Class: GroupMe::ImageClient

Inherits:
Object
  • Object
show all
Defined in:
lib/groupme/image_client.rb

Constant Summary collapse

API_BASE_URL =
'https://image.groupme.com/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ImageClient

Returns a new instance of ImageClient.



9
10
11
12
# File 'lib/groupme/image_client.rb', line 9

def initialize(args = {})
  @access_token = args[:access_token] || GroupMe.configuration.access_token
  @client = HTTPClient.new(base_url: API_BASE_URL, default_header: { 'X-Access-Token': @access_token, 'Content-Type': 'image/jpeg' })
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



7
8
9
# File 'lib/groupme/image_client.rb', line 7

def access_token
  @access_token
end

Instance Method Details

#upload(image_blob) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/groupme/image_client.rb', line 14

def upload(image_blob)
  response = @client.post('pictures', image_blob)

  return response.reason unless response.ok?

  image = JSON.parse(response.body, symbolize_names: true)
  image[:payload][:url]
end