Class: Twtmore::API

Inherits:
Object
  • Object
show all
Defined in:
lib/twtmore/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ API

Returns a new instance of API.



3
4
5
# File 'lib/twtmore/api.rb', line 3

def initialize(key)
  @key = key
end

Instance Method Details

#callback(callback, status_id) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/twtmore/api.rb', line 24

def callback(callback, status_id)
  options = {:apikey => @key, :key => callback, :status_id => status_id}
  
  sess = Patron::Session.new
  sess.timeout = 10
  sess.base_url = Twtmore::API_ROOT
  sess.headers['User-Agent'] = "TwtmoreGem/v#{Twtmore::VERSION}"
      
  resp = sess.post('/callback', options)
  
  JSON.parse(resp.body)
end

#shorten(text, user, reply_to = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/twtmore/api.rb', line 7

def shorten(text, user, reply_to = nil)
  if reply_to.nil?
    options = {:apikey => @key, :user => user, :tweet => text}
  else
    options = {:apikey => @key, :user => user, :tweet => text, :reply_to_user => reply_to[:user], :reply_to_tweet => reply_to[:reply_to_tweet]}
  end
  
  sess = Patron::Session.new
  sess.timeout = 10
  sess.base_url = Twtmore::API_ROOT
  sess.headers['User-Agent'] = "TwtmoreGem/v#{Twtmore::VERSION}"
      
  resp = sess.post('/shorten', options)
  
  JSON.parse(resp.body)
end