Giter Site home page Giter Site logo

clj-trakt's Introduction

clj-trakt

clj-trakt is a Clojure library to interface with the Trakt API.

Documentation

Trakt API documention.

clj-trakt has nearly complete coverage of the Trakt API with the exception of all of the Oauth authentication methods (only the Devices authentication methods are implemented so far).

There is very generous usage of Clojure type hinting throughout the source code that will hopefully aid anyone that might be having difficulties in what functions expect for arguments and data structures.

Usage

Add the following dependency to your project.clj file:

[clj-trakt "1.0.0]

Example

To begin using clj-trakt in your project you will first need to generate a valid access token. Create a Trakt App if you haven't already.

(ns example.core
  (:require [clj-trakt.auth :as trakt]))

;; client_id and client_secret can be found in your application page within Trakt.
(def credentials
  {:api-url "https://api-v2launch.trakt.tv/"
   :client_id "39a6af3627ac61c416fd3ebd8da45e7b000df534f55faa0d7336dc6e99c2e915"
   :client_secret "2797825b6b820708d5d401bc1fd7ae6b18bd6de401d292025ea40a049d03f640"})

(defn create-token
  [trakt-app]
  (trakt/authenticate trakt-app))

(println (create-token credentials))
#_{:access_token "cabb7da92563814b43082388c4a6cc8a6c54b6b3fd8550ed9d43f63ba85b8322"
   :token_type "bearer"
   :expires_in 7776000
   :refresh_token "d6bc38e266bdd85634611cad0e1d4b29ce3ceb1464137c9d26bd69d2d6b1eee0"
   :scope "public"}

Once you have generated yourself a valid access-token map, you are free to manage it however you wish, although it probably makes the most sense for the access-token to reside within an atom that can be updated as needed to handle refreshing of the tokens.

(defonce token
  (atom {:access_token "cabb7da92563814b43082388c4a6cc8a6c54b6b3fd8550ed9d43f63ba85b8322"
         :token_type "bearer"
         :expires_in 7776000
         :refresh_token "d6bc38e266bdd85634611cad0e1d4b29ce3ceb1464137c9d26bd69d2d6b1eee0"
         :scope "public"}))

;; Now you can refresh the access-token by doing something like this...
(reset! token (trakt/refresh-token @token))

The rest is rather simple from here. Just require the namespaces you need for your API interactions and provide the function with the merged credentials and token for valid authentication.

(ns example.core
  (:require [clj-trakt.users :as trakt-users])

(def credentials {...})
(defonce token (atom {...}))

(println (trakt-users/profile (merge credentials @token) "niamu"))

License

Copyright © 2016 Brendon Walsh

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

clj-trakt's People

Contributors

niamu avatar

Stargazers

Lee avatar Programming is fun avatar Justin avatar

Watchers

 avatar James Cloos avatar Lee avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.