Class: Ditto::Client
- Inherits:
-
Object
- Object
- Ditto::Client
- Defined in:
- lib/ditto/client.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
Instance Method Summary collapse
- #find(url, id) ⇒ Object
- #find_raw(url, id) ⇒ Object
- #find_uri(url, id) ⇒ Object
-
#initialize(client_id) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(client_id) ⇒ Client
Returns a new instance of Client.
5 6 7 |
# File 'lib/ditto/client.rb', line 5 def initialize(client_id) @client_id = client_id end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
3 4 5 |
# File 'lib/ditto/client.rb', line 3 def client_id @client_id end |
Instance Method Details
#find(url, id) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ditto/client.rb', line 9 def find(url, id) code, body = find_raw(url, id) case code when "200" Image.new(JSON.parse(body, symbolize_names: true)) when "408" raise ImageTimeoutError when "415" raise InvalidImageError end end |
#find_raw(url, id) ⇒ Object
22 23 24 25 |
# File 'lib/ditto/client.rb', line 22 def find_raw(url, id) response = Net::HTTP.get_response(find_uri(url, id)) [response.code, response.body] end |
#find_uri(url, id) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/ditto/client.rb', line 27 def find_uri(url, id) URI::HTTP.build( host: "ondemand-p02-api.ditto.us.com", path: "/v1/find", query: encoded(image_match_params(url, id))) end |