Class: DocomoImageRecognition::Client
- Inherits:
-
Object
- Object
- DocomoImageRecognition::Client
- Defined in:
- lib/docomo_image_recognition/client.rb
Instance Method Summary collapse
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #recognize(data, options = default_options) ⇒ Object
- #recognize_from_file(path, options = default_options) ⇒ Object
- #recognize_from_url(url, options = default_options) ⇒ Object
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, = ) url = "#{@base_url}&#{to_query()}" 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, = ) data = File.read(path) recognize(data, ) 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, = ) data = download_file(url) recognize(data, ) end |