Module: GettyConnect::Client::Image

Included in:
GettyConnect::Client
Defined in:
lib/getty_connect/client/image.rb

Instance Method Summary collapse

Instance Method Details

#download(download_token, options = {}) ⇒ Object

Returns download urls and related data for images

Parameters:

  • download_token (String)

    Specify the token authorizing the image download. Use the DownloadToken value provided by ‘get_download_authorisation()` or `get_largest_download_authorisation()`

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :coordination_id (String)

    Value will be echoed in the response. Can be used to track requests.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/getty_connect/client/image.rb', line 157

def download(download_token, options={})
  request = {
    :RequestHeader => {
      :Token => self.secure_token,
      :CoordinationId => options[:coordination_id] || ""
    },
    :CreateDownloadRequestBody => {
      :DownloadItems => [{
        :DownloadToken => download_token
      }]
    }
  }
  post(@download_request_endpoint, request, use_ssl=true)
end

#get_details(assetIds, options = {}) ⇒ Object

Returns detailed image metadata for all specified images.

Parameters:

  • assetIds (Array)

    An array of AssetIds

  • options (Hash) (defaults to: {})

    A customisable set of options

Options Hash (options):

  • :coordination_id (String)

    Indicates the CoordinationId value provided in the triggering request.

  • :country_code (String)

    Enables hide/block rules based on locale-based limitations on content; filters out any image whose use is prohibited in the specific country. Accepts three-letter country codes as defined in ISO 3166-1 en.wikipedia.org/wiki/ISO_3166-1_alpha-3#Current_codes. Defaults to USA.

  • :language (String)

    String. Specify an IETF RFC 5646 compliant language tag to determine the language used for localizable strings returned in the response. Defaults to ‘en-US`.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/getty_connect/client/image.rb', line 85

def get_details(assetIds, options={})
  request = {
    :RequestHeader => {
      :Token => self.token,
      :CoordinationId => options[:coordination_id] || ""
    },
    :GetImageDetailsRequestBody => {
      :CountryCode => options[:country_code] || "USA",
      :ImageIds => assetIds,
      :Language => options[:language] || "en-us"
    }
  }
  post(@image_details_endpoint, request)
end

#get_download_token(image_id, size_key) ⇒ Object

Requests download authorisation for image

Parameters:

  • image_id (Integer)

    Id of image

  • size_key (String)

    Identifies size of the image being authorized for download. Returned from ‘get_details()`.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/getty_connect/client/image.rb', line 134

def get_download_token(image_id, size_key)
  request = {
    :RequestHeader => {
      :Token => self.token
    },
    :GetImageDownloadAuthorizationsRequestBody => {
      :ImageSizes => [{
        :ImageId => image_id,
        :SizeKey => size_key
      }]
    }
  }
  response = post(@download_auth_endpoint, request)
  response.GetImageDownloadAuthorizationsResult.Images.first.Authorizations.first.DownloadToken
end

#get_largest_download_auth(asset_ids, options = {}) ⇒ Object

Returns list of authorized downloads



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/getty_connect/client/image.rb', line 52

def get_largest_download_auth(asset_ids, options={})
  asset_id_list = Array.new()
  asset_ids.each do |aid|
    asset_id_list << {:ImageId=>aid}
  end

  request = {
    :RequestHeader => {
      :Token => self.token,
      :CoordinationId => options[:coordination_id] || ""
    },
    :GetLargestImageDownloadAuthorizationsRequestBody => {
      :Images => asset_id_list
    },
  }
  post(@download_largest_endpoint, request)
end

#get_preview(assetIds, preview_format) ⇒ Object

Convenience method. Returns a collection of urls and imageids

Parameters:

  • assetIds (Array)

    Array of assetIds

  • preview_format (String)

    Format of preview image. Options in order of size are: ‘thumb`, `preview`, `comp`, `watermark_preview`, `watermark_comp`



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/getty_connect/client/image.rb', line 106

def get_preview(assetIds, preview_format)
  response = get_details(assetIds)
  preview = []
  response.GetImageDetailsResult.Images.each do |image, index|
    url = ""
    case preview_format
    when "comp"
      url = image.UrlComp
    when "preview"
      url = image.UrlPreview
    when "thumb"
      url = image.UrlThumb
    when "watermark_comp"
      url = image.UrlWatermarkComp
    when "watermark_preview"
      url = image.UrlWatermarkPreview
    end
    preview << { "imageId" => image.ImageId,
                 "url" => url }
  end
  preview 
end

#search(phrase, options = {}) ⇒ Object

Search for images by keyword.

param options [Hash] A customisable set of options

Examples:

Search for images of bears, returning a max. of 5 results

client.search("bears", {:item_count => 5})

Parameters:

  • phrase (String)

    The search phrase.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :filetypes (Array)

    String array of filetypes. Possible values are ‘eps` and `jpg`.

  • :item_count (Integer)

    Number of items to return

  • :item_start_number (Integer)

    Returns the index of the first image. Use with ‘:item_count` to support pagination.

  • :language (String)

    String. Specify an IETF RFC 5646 compliant language tag to determine the language used for localizable strings returned in the response. Defaults to ‘en-US`.

  • :licenses (Array)

    Array of strings specifying a type of license by which to filter results. Possible values are: ‘royaltyfree`, `rightsmanaged`.

  • :orientations (String)

    Possible values are: ‘horizontal`, `vertical`, `panoramichorizontal`, `panoramicvertical`, `square`

  • :specific_persons (Array)

    Specify the personalities to query the images that match all of the specified personalities.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/getty_connect/client/image.rb', line 26

def search(phrase, options={})
  
  request = {
    :RequestHeader => { :Token => self.token},
    :SearchForImages2RequestBody => {
      :Query => { 
        :SearchPhrase => phrase,
        :SpecificPersons => options[:specific_persons],
      },
      :Language => options[:language] || "en-us",
      :ResultOptions => {
        :ItemCount => options[:item_count] || 15,
        :ItemStartNumber => options[:item_start_number] || 1
      },
      :Filter => {
          :LicensingModels => options[:licenses] || ["royaltyfree"],
          :Orientations => options[:orientations],
          :FileTypes => options[:filetypes] || ["jpg"],
          :ProductOfferings => options[:product_offerings] || ["EasyAccess"]
      },
    }
  }
  post(@search_endpoint, request)
end