Module: GettyConnect::Client::Image
- Included in:
- GettyConnect::Client
- Defined in:
- lib/getty_connect/client/image.rb
Instance Method Summary collapse
-
#download(download_token, options = {}) ⇒ Object
Returns download urls and related data for images.
-
#get_details(assetIds, options = {}) ⇒ Object
Returns detailed image metadata for all specified images.
-
#get_download_token(image_id, size_key) ⇒ Object
Requests download authorisation for image.
-
#get_largest_download_auth(asset_ids, options = {}) ⇒ Object
Returns list of authorized downloads.
-
#get_preview(assetIds, preview_format) ⇒ Object
Convenience method.
-
#search(phrase, options = {}) ⇒ Object
Search for images by keyword.
Instance Method Details
#download(download_token, options = {}) ⇒ Object
Returns download urls and related data for images
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, ={}) request = { :RequestHeader => { :Token => self.secure_token, :CoordinationId => [: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.
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, ={}) request = { :RequestHeader => { :Token => self.token, :CoordinationId => [:coordination_id] || "" }, :GetImageDetailsRequestBody => { :CountryCode => [:country_code] || "USA", :ImageIds => assetIds, :Language => [:language] || "en-us" } } post(@image_details_endpoint, request) end |
#get_download_token(image_id, size_key) ⇒ Object
Requests download authorisation for image
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, ={}) asset_id_list = Array.new() asset_ids.each do |aid| asset_id_list << {:ImageId=>aid} end request = { :RequestHeader => { :Token => self.token, :CoordinationId => [: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
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
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, ={}) request = { :RequestHeader => { :Token => self.token}, :SearchForImages2RequestBody => { :Query => { :SearchPhrase => phrase, :SpecificPersons => [:specific_persons], }, :Language => [:language] || "en-us", :ResultOptions => { :ItemCount => [:item_count] || 15, :ItemStartNumber => [:item_start_number] || 1 }, :Filter => { :LicensingModels => [:licenses] || ["royaltyfree"], :Orientations => [:orientations], :FileTypes => [:filetypes] || ["jpg"], :ProductOfferings => [:product_offerings] || ["EasyAccess"] }, } } post(@search_endpoint, request) end |