Module: GettyUp::API::SearchForImages

Includes:
Util
Included in:
Client
Defined in:
lib/getty_up/api/search_for_images.rb

Constant Summary collapse

ENDPOINT =
"http://connect.gettyimages.com/v1/search/SearchForImages"

Instance Method Summary collapse

Methods included from Util

#post_json

Instance Method Details

#search_for_images(phrase, start = 1, count = 25, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/getty_up/api/search_for_images.rb', line 14

def search_for_images(phrase, start = 1, count = 25, options = {})
  request = {
    :RequestHeader => { :Token => @token},
    :SearchForImages2RequestBody => {
      :Query => { :SearchPhrase => phrase},
      :ResultOptions => {
        ItemStartNumber: start,
        ItemCount: count
      },
      :Filter => { :ImageFamilies => ["creative"] }
    }.merge(options)
  }
  response = post_json(request, ENDPOINT)

  result = OpenStruct.new
  result.response_header = response["ResponseHeader"]#.inject({}){|memo, hsh| memo.merge({hsh.first.underscore.to_sym => hsh.last})}
  result.images = response["SearchForImagesResult"]["Images"]
  result

end