Giter Site home page Giter Site logo

twttr's Introduction

twttr

Clojars Project cljdoc version badge Travis CI build status Coverage status on Coveralls

Twitter API client for Clojure, using aleph and clj-oauth, supporting REST and Streaming endpoints.

twttr is a much simplified fork of twitter-api, mostly due to using aleph instead of http.async.client. In particular, streaming is now much easier. Also removed: all ^:dynamic vars, and all but one macro.

Install

twttr is on Clojars:

[twttr "3.2.3"]

Getting started

Assuming you've got your OAuth credentials in hand (procuring them is outside the scope of this library), the easiest way to use them in your Clojure project is via environment variables:

export CONSUMER_KEY=l4VAFAKEFAKEFAKEpy7R7
export CONSUMER_SECRET=dVnTimJtFAKEFAKEFAKEFAKEFAKEFAKEBVYnO91BR1G
export ACCESS_TOKEN=195648015-OIHb87zuFAKEFAKEFAKEFAKEFAKEFAKEb5aLUMYo
export ACCESS_TOKEN_SECRET=jsVg1HFAKEFAKEFAKEFAKEFAKEFAKE4yfOLC5cXA9fcXr

And then (in the same shell session!) run lein repl or whatever you're using to kick off your Clojure code:

; save this to `dev/user.clj` in your project
(ns user
  (:require [twttr.api :as api]
            [twttr.auth :refer [env->UserCredentials]]))

; read credentials from environment variables, namely:
; CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, and ACCESS_TOKEN_SECRET
(def creds (env->UserCredentials))

; the "https://api.twitter.com/1.1/users/show.json" Resource URL
; becomes the "users-show" function
(api/users-show creds :params {:screen_name "jack"})
;=> {:id 12, :verified true, :created_at "Tue Mar 21 20:50:14 +0000 2006", ...}

; the value returned is the body of the response,
; with the rest of the response attached as metadata:
(meta *1)
;=> {:request-time 263,
;    :headers {"x-rate-limit-reset" "1495550008", "last-modified" "Tue, 23 May 2017 14:29:28 GMT",
;              "x-rate-limit-limit" "900", "x-rate-limit-remaining" "898", ...},
;    :status 200,
;    :connection-time 269}

; update your status
(api/statuses-update creds :params {:status "Well that was quick."})

; get a taste of the sample stream
(def stream (api/statuses-sample creds))
(def first10 (doall (take 10 stream)))
(-> stream meta :body (.close))
(map :text first10)

Testing

The tests require that credentials be provided via environment variables as described above.

Then run lein test, which can take a minute since many of the tests involve calling the Twitter API and waiting for an appropriate response. If all tests completed successfully, the test output will end with a message like:

Ran 27 tests containing 68 assertions.
0 failures, 0 errors.

License

Distributed under the Eclipse Public License, same as Clojure.

  • Copyright (C) 2017โ€“2019 Christopher Brown
  • Copyright (C) 2011 StreamScience

twttr's People

Contributors

chbrown avatar adamwynne avatar dotemacs avatar peat avatar bitsai avatar minleychris avatar jcrossley3 avatar ortuna avatar eightysteele avatar bzg avatar juxtin avatar matthiasn avatar morganastra avatar paulbowler avatar thatsnotright avatar yogsototh avatar jtoy avatar ryane 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.