Class: Twi::Medium
Overview
The representation of a medium (image) attached to a message.
Instance Method Summary collapse
-
#content_type ⇒ String
The content type.
-
#id ⇒ String
Unique identifier.
-
#image? ⇒ Boolean
Whether the medium has the content type of an image.
-
#url ⇒ String
A URL where the image can be accessed at least for a few minutes.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Twi::Resource
Instance Method Details
#content_type ⇒ String
Returns the content type.
12 |
# File 'lib/twi/medium.rb', line 12 def content_type = @params['ContentType'] |
#id ⇒ String
Returns unique identifier.
6 |
# File 'lib/twi/medium.rb', line 6 def id = @params['Sid'] |
#image? ⇒ Boolean
Returns whether the medium has the content type of an image.
9 |
# File 'lib/twi/medium.rb', line 9 def image? = content_type.match? %r{^image/} |
#url ⇒ String
Returns a URL where the image can be accessed at least for a few minutes.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/twi/medium.rb', line 15 def url uri = URI service_url http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) request.basic_auth Twi.lio.sid, Twi.lio.secret response = http.request(request) JSON(response.body).dig 'links', 'content_direct_temporary' end |