Class: Hahamut::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/hahamut/uploader.rb

Overview

Image Uploader

Constant Summary collapse

ENDPOINT =
'https://us-central1-hahamut-8888.cloudfunctions.net/' \
'imagePush?bot_id=%<botid>s' \
'&access_token=%<token>s'

Instance Method Summary collapse

Constructor Details

#initialize(botid, token) ⇒ Uploader

Returns a new instance of Uploader.



12
13
14
15
# File 'lib/hahamut/uploader.rb', line 12

def initialize(botid, token)
  @botid = botid
  @token = token
end

Instance Method Details

#upload(path) ⇒ Object



17
18
19
20
21
# File 'lib/hahamut/uploader.rb', line 17

def upload(path)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  create_image http.request(build_request(path))
end

#uriObject



23
24
25
# File 'lib/hahamut/uploader.rb', line 23

def uri
  @uri ||= URI(format(ENDPOINT, botid: @botid, token: @token))
end