Class: Twtmore::API
- Inherits:
-
Object
- Object
- Twtmore::API
- Defined in:
- lib/twtmore/api.rb
Instance Method Summary collapse
- #callback(callback, status_id) ⇒ Object
-
#initialize(key) ⇒ API
constructor
A new instance of API.
- #shorten(text, user, reply_to = nil) ⇒ Object
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) = {: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', ) 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? = {:apikey => @key, :user => user, :tweet => text} else = {: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', ) JSON.parse(resp.body) end |