Class: Eyevision::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/eyevision/client.rb

Constant Summary collapse

BASE_URI =
"https://vision-api.eyeem.com/v1"
SUPPORTED_FEATURES =
%w(TAGS CAPTIONS AESTHETIC_SCORE)

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/eyevision/client.rb', line 10

def initialize(client_id, client_secret)
  @client_id     = client_id
  @client_secret = client_secret
end

Instance Method Details

#analyze(opts) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/eyevision/client.rb', line 15

def analyze(opts)
  case
  when opts[:file]
    image = from_file(opts[:file])
  when opts[:url]
    image = from_url(opts[:url])
  when opts[:image]
    image = opts[:image]
  else
    raise "You need to supply an image, file or URL"
  end

  features = SUPPORTED_FEATURES & (opts[:features] || SUPPORTED_FEATURES)

  resp = request('/analyze', body: body(image, features), headers: auth_headers, format: :json)

  JSON.parse(resp.body)["responses"].first
end