Class: Twi::Medium

Inherits:
Resource show all
Defined in:
lib/twi/medium.rb

Overview

The representation of a medium (image) attached to a message.

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Twi::Resource

Instance Method Details

#content_typeString

Returns the content type.

Returns:

  • (String)

    the content type



12
# File 'lib/twi/medium.rb', line 12

def content_type = @params['ContentType']

#idString

Returns unique identifier.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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/}

#urlString

Returns a URL where the image can be accessed at least for a few minutes.

Returns:

  • (String)

    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