Skip to content

Instantly share code, notes, and snippets.

@jem-computer
Created March 16, 2013 15:36
Show Gist options
  • Save jem-computer/5176922 to your computer and use it in GitHub Desktop.
Save jem-computer/5176922 to your computer and use it in GitHub Desktop.
class Twitter
constructor: (options) ->
@_url = "https://api.twitter.com"
@_version = "1.1"
_.extend this, options if options
_getUrl: (url) ->
[@_url, @_version, url].join "/"
get: (url, params) ->
@call "GET", url, params
post: (url, params) ->
@call "POST", url, params
call: (method, url, params) ->
#this.unblock();
oauthBinding = @getOauthBindingForCurrentUser()
result = oauthBinding.call(method, @_getUrl(url), params)
result
getOauthBinding: ->
config = Accounts.loginServiceConfiguration.findOne(service: "twitter")
urls = Accounts.twitter._urls
new OAuth1Binding(config.consumerKey, config.secret, urls)
getOauthBindingForCurrentUser: ->
oauthBinding = @getOauthBinding()
user = Meteor.user()
oauthBinding.accessToken = user.services.twitter.accessToken
oauthBinding.accessTokenSecret = user.services.twitter.accessTokenSecret
oauthBinding
userTimeline: ->
@get "statuses/user_timeline.json"
postTweet: (text) ->
@post "statuses/update.json",
status: text
follow: (screenName) ->
@post "friendships/create.json",
screen_name: screenName
follow: true
getLists: (user) ->
if user
@get "lists/list.json",
screen_name: user
else
@get "lists/list.json"
getListMembers: (listId, cursor = "-1") ->
@get "lists/members.json",
list_id: listId
cursor: cursor
usersSearch: (query, page = 0, count = 6, includeEntities = true) ->
@get "users/search.json",
q: query
page: page
count: count
include_entities: includeEntities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment