Module: Twitter::REST::Media

Included in:
API
Defined in:
lib/twitter/rest/media.rb

Instance Method Summary collapse

Instance Method Details

#upload(media, options = {}) ⇒ Integer

Uploads media to attach to a tweet

Raises:

See Also:

Rate Limited?:

  • No

Authentication:

  • Requires user context



18
19
20
21
22
23
24
25
26
27
# File 'lib/twitter/rest/media.rb', line 18

def upload(media, options = {})
  fail(Twitter::Error::UnacceptableIO.new) unless media.respond_to?(:to_io)
  base_url = 'https://upload.twitter.com'
  path = '/1.1/media/upload.json'
  conn = connection.dup
  conn.url_prefix = base_url
  headers = Twitter::Headers.new(self, :post, base_url + path, options).request_headers
  options.merge!(:media => media)
  conn.post(path, options) { |request| request.headers.update(headers) }.env.body[:media_id]
end