class Ditto::Client

Attributes

client_id[R]

Public Class Methods

new(client_id) click to toggle source
# File lib/ditto/client.rb, line 5
def initialize(client_id)
  @client_id = client_id
end

Public Instance Methods

find(url, id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

encoded(params) click to toggle source
# File lib/ditto/client.rb, line 36
def encoded(params)
  URI.encode_www_form(params).gsub("+", "%20")
end
image_match_params(url, id) click to toggle source
# File lib/ditto/client.rb, line 40
def image_match_params(url, id)
  { client_id: client_id, url: url, uid: id }
end