Module: TwitPic::API
- Defined in:
- lib/twitpic/api.rb
Constant Summary collapse
- API_BASE =
'http://api.twitpic.com/2/'
Class Method Summary collapse
- .query(client, call, args) ⇒ Object
- .tweet(client, media) ⇒ Object
-
.upload(client, file, args) ⇒ Object
Uploads an image to the TwitPic API.
Class Method Details
.query(client, call, args) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/twitpic/api.rb', line 11 def query(client, call, args) self.validate(call, args) if call[:method] == :get then self.get(call[:endpoint], args) else self.post(client, call[:endpoint], args) end end |
.tweet(client, media) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/twitpic/api.rb', line 33 def tweet(client, media) raise ArgumentError, "Invalid argument, must be an object returned from a photo upload" unless media.has_key? 'text' tweet = "#{media['text'][0..114]} #{media['url']}" url = 'http://api.twitter.com/1/statuses/update.json'; headers = TwitPic::API.build_header(client, tweet) opts = { :headers => headers, :params => { 'status' => tweet } } data = Nestful.post(url, opts) return media, JSON.parse(data) end |
.upload(client, file, args) ⇒ Object
Uploads an image to the TwitPic API
File can be either the path to the image or a File object
25 26 27 28 29 30 31 |
# File 'lib/twitpic/api.rb', line 25 def upload(client, file, args) file = File.open(file) if file.instance_of? String args[:media] = file self.post(client, 'upload', args) end |