Class: DocomoImageRecognition::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/docomo_image_recognition/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.



3
4
5
6
# File 'lib/docomo_image_recognition/client.rb', line 3

def initialize(api_key)
  base_url = DocomoImageRecognition.configuration.base_url
  @base_url = base_url + "?APIKEY=#{api_key}"
end

Instance Method Details

#recognize(data, options = default_options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/docomo_image_recognition/client.rb', line 8

def recognize(data, options = default_options)
  url = "#{@base_url}&#{to_query(options)}"
  curl = Curl::Easy.new(url)
  curl.headers['Content-Type'] = 'application/octet-stream'
  curl.post_body = data
  curl.http_post
  body = JSON.parse(curl.body_str)
  raise_on_error!(body, curl.status)
  body
end

#recognize_from_file(path, options = default_options) ⇒ Object



19
20
21
22
# File 'lib/docomo_image_recognition/client.rb', line 19

def recognize_from_file(path, options = default_options)
  data = File.read(path)
  recognize(data, options)
end

#recognize_from_url(url, options = default_options) ⇒ Object



24
25
26
27
# File 'lib/docomo_image_recognition/client.rb', line 24

def recognize_from_url(url, options = default_options)
  data = download_file(url)
  recognize(data, options)
end