gettyimages-api 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b5c91bd5871d4cb8761930aeb093fe47a0c5d85
4
+ data.tar.gz: 644524093d4158f6f95c1dca4da520c5955e8dd6
5
+ SHA512:
6
+ metadata.gz: c9f560e82439206b16671f81b5f76cfb158dea1217a1ab28282902053cb7288ce32adfd33f8dbefd54153301db0a715a183d55e3a26d1d529cf1f151f6535623
7
+ data.tar.gz: 9afd14e656e430f98c747d2418fdc6f72e564f8475b987ae8c09d04e137b6b173ffc65eba024d6fc63e31c1e4560f256300b0c2a4b6c814430f856056db7062e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,65 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Debug Local File",
9
+ "type": "Ruby",
10
+ "request": "launch",
11
+ "cwd": "${workspaceRoot}",
12
+ "program": "${file}",
13
+ "showDebuggerOutput": true
14
+ },
15
+ {
16
+ "name": "Listen for rdebug-ide",
17
+ "type": "Ruby",
18
+ "request": "attach",
19
+ "cwd": "${workspaceRoot}",
20
+ "remoteHost": "127.0.0.1",
21
+ "remotePort": "1234",
22
+ "remoteWorkspaceRoot": "${workspaceRoot}"
23
+ },
24
+ {
25
+ "name": "Rails server",
26
+ "type": "Ruby",
27
+ "request": "launch",
28
+ "cwd": "${workspaceRoot}",
29
+ "program": "${workspaceRoot}/bin/rails",
30
+ "args": [
31
+ "server"
32
+ ]
33
+ },
34
+ {
35
+ "name": "RSpec - all",
36
+ "type": "Ruby",
37
+ "request": "launch",
38
+ "cwd": "${workspaceRoot}",
39
+ "program": "${workspaceRoot}/bin/rspec",
40
+ "args": [
41
+ "-I",
42
+ "${workspaceRoot}"
43
+ ]
44
+ },
45
+ {
46
+ "name": "RSpec - active spec file only",
47
+ "type": "Ruby",
48
+ "request": "launch",
49
+ "cwd": "${workspaceRoot}",
50
+ "program": "${workspaceRoot}/bin/rspec",
51
+ "args": [
52
+ "-I",
53
+ "${workspaceRoot}",
54
+ "${file}"
55
+ ]
56
+ },
57
+ {
58
+ "name": "Cucumber",
59
+ "type": "Ruby",
60
+ "request": "launch",
61
+ "cwd": "${workspaceRoot}",
62
+ "program": "${workspaceRoot}/bin/cucumber"
63
+ }
64
+ ]
65
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
3
+ // for the documentation about the tasks.json format
4
+ "version": "2.0.0",
5
+ "tasks": [
6
+ {
7
+ "label": "test",
8
+ "type": "shell",
9
+ "command": "ruby",
10
+ "args": [
11
+ "./unit_tests/Run.rb"
12
+ ],
13
+ }
14
+ ]
15
+ }
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'json'
5
+ gem 'test-unit'
6
+ gem 'webmock'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2014-2018 Getty Images
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # Getty Images API Ruby SDK
2
+ [![Build Status](https://travis-ci.org/gettyimages/gettyimages-api_ruby.svg?branch=master)](https://travis-ci.org/gettyimages/gettyimages-api_ruby)
3
+ Seamlessly integrate Getty Images' expansive digital content, powerful search technology, and rich metadata into your publishing tools, products and services!
4
+
5
+ - Search for images and videos from our extensive creative and editorial catalogs.
6
+ - Get image and video metadata.
7
+ - Download files using your Getty Images products (e.g., Editorial subscriptions, Easy Access, Thinkstock Subscriptions, and Image Packs).
8
+ - Custom Request functionality that allows user to call any endpoint.
9
+
10
+ ## Requirements
11
+
12
+ - Ruby version >= 2.4
13
+ - [Bundler](http://bundler.io)
14
+
15
+ ## Examples
16
+
17
+ ### Search for one or more images
18
+
19
+ ```ruby
20
+ require 'gettyimages-api'
21
+
22
+ api_key = "API Key"
23
+ api_secret = "API Secret"
24
+
25
+ # create instance of the SDK
26
+ apiClient = ApiClient.new(api_key, api_secret)
27
+ result = apiClient
28
+ .search_images()
29
+ .with_phrase("gorilla")
30
+ .with_fields(["artist", "id", "title"])
31
+ .with_exclude_nudity("true")
32
+ .with_page(2)
33
+ .with_page_size(5)
34
+ .execute()
35
+
36
+ result["images"].each do | image |
37
+ puts "Id: #{image["id"]} Title: #{image["title"]}"
38
+ end
39
+ ```
40
+
41
+ ### Get detailed information for one image
42
+
43
+ ```ruby
44
+ require 'gettyimages-api'
45
+
46
+ api_key = "API Key"
47
+ api_secret = "API Secret"
48
+
49
+ # create instance of the SDK
50
+ apiClient = ApiClient.new(api_key, api_secret)
51
+ result = apiClient
52
+ .images()
53
+ .with_id("ASSET_ID")
54
+ .execute()
55
+
56
+ puts result
57
+ ```
58
+
59
+ ### Get detailed information for multiple images
60
+
61
+ ```ruby
62
+ require 'gettyimages-api'
63
+
64
+ api_key = "API Key"
65
+ api_secret = "API Secret"
66
+
67
+ # create instance of the SDK
68
+ apiClient = ApiClient.new(api_key, api_secret)
69
+ result = apiClient
70
+ .images()
71
+ .with_ids(["ASSET_ID_1", "ASSET_ID_2"])
72
+ .execute()
73
+
74
+ result["images"].each do | image |
75
+ puts image
76
+ end
77
+ ```
78
+
79
+ ### Download an image
80
+
81
+ ```ruby
82
+ require 'gettyimages-api'
83
+
84
+ api_key = "API Key"
85
+ api_secret = "API Secret"
86
+
87
+ # create instance of the SDK
88
+ apiClient = ApiClient.new(api_key, api_secret)
89
+ result = apiClient
90
+ .download_images()
91
+ .with_id("ASSET_ID")
92
+ .execute()
93
+
94
+ puts result["uri"]
95
+ ```
96
+
97
+ ### Use the custom request functionality for GET request with query parameters
98
+
99
+ ```ruby
100
+ require 'gettyimages-api'
101
+
102
+ api_key = "API Key"
103
+ api_secret = "API Secret"
104
+
105
+ # create instance of the SDK
106
+ apiClient = ApiClient.new(api_key, api_secret)
107
+ result = apiClient
108
+ .custom_request()
109
+ .with_method("GET")
110
+ .with_route("search/images")
111
+ .with_query_parameters({"phrase"=> "cat", "fields"=> ["artist", "id", "title"], "page" => 2})
112
+ .execute()
113
+
114
+ result["images"].each do | image |
115
+ puts "Id: #{image["id"]} Title: #{image["title"]}"
116
+ end
117
+ ```
118
+
119
+ ### Use the custom request functionality for POST request with body
120
+
121
+ ```ruby
122
+ require 'gettyimages-api'
123
+
124
+ api_key = "API Key"
125
+ api_secret = "API Secret"
126
+
127
+ # create instance of the SDK
128
+ apiClient = ApiClient.new(api_key, api_secret)
129
+ result = apiClient
130
+ .custom_request()
131
+ .with_method("POST")
132
+ .with_route("boards")
133
+ .with_body({"name"=> "Board Name", "description" => "Board Description"})
134
+ .execute()
135
+
136
+ puts result["id"]
137
+ ```
138
+
139
+ ## Unit Tests
140
+
141
+ Install bundler and all dependencies
142
+
143
+ ```sh
144
+ gem install bundler
145
+ bundle install
146
+ ```
147
+
148
+ To execute all unit tests:
149
+
150
+ ```sh
151
+ rake
152
+ ```
153
+
154
+ To run one unit test file:
155
+
156
+ ```sh
157
+ ruby unit_tests/FILENAME.rb
158
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler"
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ task :test do
6
+ ruby("unit_tests/Run.rb")
7
+ end
8
+
9
+ task default: :test
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require_relative 'lib/GettyImagesApi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gettyimages-api"
8
+ spec.version = GettyImagesApi::VERSION
9
+ spec.version = "#{spec.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
10
+ spec.authors = ["Getty Images"]
11
+ spec.email = ["developersupport@gettyimages.com"]
12
+ spec.summary = "Getty Images API SDK"
13
+ spec.description = "Getty Images API SDK"
14
+ spec.homepage = "https://github.com/gettyimages/gettyimages-api_ruby"
15
+ spec.license = "MIT"
16
+ gem_files = `git ls-files -z`.split("\x0")
17
+ gem_ignored_files = `git ls-files -z unit_tests/`.split("\x0")
18
+ spec.files = gem_files - gem_ignored_files - ['.travis.yml']
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake"
24
+
25
+ end
data/lib/ApiClient.rb ADDED
@@ -0,0 +1,88 @@
1
+ require_relative "Credentials"
2
+ require_relative "Search/SearchImages.rb"
3
+ require_relative "Search/SearchImagesCreative.rb"
4
+ require_relative "Search/SearchImagesEditorial.rb"
5
+ require_relative "Search/SearchVideos.rb"
6
+ require_relative "Search/SearchVideosCreative.rb"
7
+ require_relative "Search/SearchVideosEditorial.rb"
8
+ require_relative "Downloads/DownloadImages.rb"
9
+ require_relative "Downloads/DownloadVideos.rb"
10
+ require_relative "Images/Images.rb"
11
+ require_relative "Videos/Videos.rb"
12
+ require_relative "CustomRequest/CustomRequest.rb"
13
+
14
+ class ApiClient
15
+
16
+ # Initialize the Credentials to be used by the SDK
17
+ def initialize(api_key, api_secret, user_name = nil, password = nil)
18
+
19
+ @credentials = Credentials.new(
20
+ :credential_type => (user_name.nil?) || (password.nil?) ? OAuthGrantType::CLIENT_CREDENTIALS : OAuthGrantType::PASSWORD,
21
+ :client_key => api_key,
22
+ :client_secret => api_secret,
23
+ :user_name => user_name,
24
+ :password => password)
25
+ end
26
+
27
+ # Get access token to be used by the SDK
28
+ def get_access_token
29
+ return @credentials.get_access_token
30
+ end
31
+
32
+ # Search for both creative and editorial images
33
+ def search_images()
34
+ return SearchImages.new(@credentials.client_key, @credentials.get_access_token)
35
+ end
36
+
37
+ # Search for creative images
38
+ def search_images_creative()
39
+ return SearchImagesCreative.new(@credentials.client_key, @credentials.get_access_token)
40
+ end
41
+
42
+ # Search for editorial images
43
+ def search_images_editorial()
44
+ return SearchImagesEditorial.new(@credentials.client_key, @credentials.get_access_token)
45
+ end
46
+
47
+ #Search for both creative and editorial videos
48
+ def search_videos()
49
+ return SearchVideos.new(@credentials.client_key, @credentials.get_access_token)
50
+ end
51
+
52
+ #Search for creative videos
53
+ def search_videos_creative()
54
+ return SearchVideosCreative.new(@credentials.client_key, @credentials.get_access_token)
55
+ end
56
+
57
+ #Search for editorial videos
58
+ def search_videos_editorial()
59
+ return SearchVideosEditorial.new(@credentials.client_key, @credentials.get_access_token)
60
+ end
61
+
62
+ #Get metadata for images
63
+ def images()
64
+ return Images.new(@credentials.client_key, @credentials.get_access_token)
65
+ end
66
+
67
+ #Get metadata for videos
68
+ def videos()
69
+ return Videos.new(@credentials.client_key, @credentials.get_access_token)
70
+ end
71
+
72
+ #Download an image
73
+ def download_images()
74
+ return DownloadImages.new(@credentials.client_key, @credentials.get_access_token)
75
+ end
76
+
77
+ #Download a video
78
+ def download_videos()
79
+ return DownloadVideos.new(@credentials.client_key, @credentials.get_access_token)
80
+ end
81
+
82
+ #Build a custom API request
83
+ def custom_request()
84
+ return CustomRequest.new(@credentials.client_key, @credentials.get_access_token)
85
+ end
86
+
87
+ end
88
+
@@ -0,0 +1,68 @@
1
+ require 'open-uri'
2
+ require 'net/https'
3
+
4
+ class OAuthGrantType
5
+ PASSWORD = 'password'
6
+ CLIENT_CREDENTIALS = 'client_credentials'
7
+ end
8
+
9
+ class Credentials
10
+
11
+ attr_accessor :credential_type
12
+ attr_accessor :client_key
13
+ attr_accessor :client_secret
14
+ attr_accessor :user_name
15
+ attr_accessor :password
16
+
17
+ def initialize(args)
18
+ args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
19
+ end
20
+
21
+ def get_uri(path)
22
+ return URI.parse "#{Api_Host::API_BASE_URL}#{path}"
23
+ end
24
+
25
+ # Get Access Token Using OAuth
26
+ def get_access_token
27
+
28
+ # Determine OAuth Flow
29
+ case @credential_type
30
+ when OAuthGrantType::PASSWORD
31
+ oauth_data = {
32
+ :grant_type => @credential_type,
33
+ :client_id => @client_key,
34
+ :client_secret => @client_secret,
35
+ :username => @user_name,
36
+ :password => @password }
37
+ when OAuthGrantType::CLIENT_CREDENTIALS
38
+ oauth_data = {
39
+ :grant_type => @credential_type,
40
+ :client_id => @client_key,
41
+ :client_secret => @client_secret }
42
+ else
43
+ puts 'Current OAuth flow only supports Resource Owner and Client Credentials'
44
+ end
45
+
46
+ # define endpoint
47
+ uri = get_uri '/oauth2/token'
48
+
49
+ # define HTTPS connection
50
+ https = Net::HTTP.new(uri.host, uri.port)
51
+ https.use_ssl = true
52
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
53
+
54
+ # define Request
55
+ req = Net::HTTP::Post.new uri.request_uri
56
+ req['Api-Key'] = @client_key
57
+ req.set_form_data oauth_data
58
+
59
+ res = https.request req
60
+ data = res.body
61
+ result = JSON.parse(data)
62
+ if !res.is_a?(Net::HTTPSuccess)
63
+ raise res.code + ": " + result['error_description']
64
+ end
65
+ return result['access_token']
66
+ end
67
+
68
+ end
@@ -0,0 +1,63 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class CustomRequest < RequestBase
4
+
5
+ attr_accessor :method, :body, :route
6
+ # @route = "/v3/"
7
+
8
+ def initialize(api_key, access_token)
9
+ @route = "/v3/"
10
+ super(api_key, access_token)
11
+ end
12
+
13
+ def execute
14
+ case @method
15
+ when "GET"
16
+ return @http_helper.get(@route, @query_params)
17
+ when "POST"
18
+ return @http_helper.post(@route, @query_params, self.body)
19
+ when "PUT"
20
+ return @http_helper.put(@route, @query_params, self.body)
21
+ when "DELETE"
22
+ return @http_helper.delete(@route, @query_params)
23
+ else
24
+ raise "No appropriate HTTP method found for this request."
25
+ end
26
+
27
+ end
28
+
29
+ def with_route(route)
30
+ @route += route
31
+ return self
32
+ end
33
+
34
+ def with_method(method)
35
+ @method = method
36
+ return self
37
+ end
38
+
39
+ def with_query_parameters(params)
40
+ params.each do |key,value|
41
+ if value.is_a?(Array)
42
+ value = value.join(",")
43
+ if !key.include? "id"
44
+ value.downcase!
45
+ end
46
+ params[key] = value
47
+ else
48
+ if (!key.include? "id") && (value.is_a?(String))
49
+ value.downcase!
50
+ end
51
+ params[key] = value
52
+ end
53
+ end
54
+ @query_params = params
55
+ return self
56
+ end
57
+
58
+ def with_body(body)
59
+ self.body = body
60
+ return self
61
+ end
62
+
63
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class DownloadImages < RequestBase
4
+
5
+ attr_accessor :asset_id
6
+
7
+ API_ROUTE = "/v3/downloads/images" # mashery endpoint
8
+ QUERY_PARAMS_NAMES = ["file_type","height","product_id","product_type"]
9
+
10
+ QUERY_PARAMS_NAMES.each do |key|
11
+ define_method :"with_#{key}" do |value = true|
12
+ if (!key.include? "id") && (value.is_a?(String))
13
+ value.downcase!
14
+ end
15
+ build_query_params(key, value)
16
+ return self
17
+ end
18
+ end
19
+
20
+ public
21
+ def with_id(asset_id)
22
+ self.asset_id = asset_id
23
+ return self
24
+ end
25
+
26
+ def execute
27
+ build_query_params("auto_download", "false")
28
+ uri = API_ROUTE + "/" + self.asset_id
29
+ return @http_helper.post(uri, @query_params, nil)
30
+ end
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class DownloadVideos < RequestBase
4
+
5
+ attr_accessor :asset_id
6
+
7
+ API_ROUTE = "/v3/downloads/videos" # mashery endpoint
8
+ QUERY_PARAMS_NAMES = ["product_id","size"]
9
+
10
+ QUERY_PARAMS_NAMES.each do |key|
11
+ define_method :"with_#{key}" do |value = true|
12
+ if (!key.include? "id") && (value.is_a?(String))
13
+ value.downcase!
14
+ end
15
+ build_query_params(key, value)
16
+ return self
17
+ end
18
+ end
19
+
20
+ public
21
+ def with_id(asset_id)
22
+ self.asset_id = asset_id
23
+ return self
24
+ end
25
+
26
+ def execute
27
+ build_query_params("auto_download", "false")
28
+ uri = API_ROUTE + "/" + self.asset_id
29
+ return @http_helper.post(uri, @query_params, nil)
30
+ end
31
+
32
+ end
data/lib/Example.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "pp"
2
+ require_relative "GettyImagesApi"
3
+
4
+ api_key = "api key"
5
+ api_secret = "api secret"
6
+
7
+ apiClient = GettyImagesApi.new(api_key, api_secret)
8
+ search_results = apiClient.search().images().creative()
9
+ .with_phrase("gorilla")
10
+ .with_response_fields(["id","title"])
11
+ .with_graphical_styles("illustration")
12
+ .with_graphical_styles(["fine_art","photography"])
13
+ .with_page(2)
14
+ .with_page_size(5)
15
+ .execute()
16
+
17
+ search_results["images"].each do | image |
18
+ puts "Id: #{image["id"]} Title: #{image["title"]}"
19
+ end
20
+
21
+
@@ -0,0 +1,3 @@
1
+ module GettyImagesApi
2
+ VERSION = "2.0.0"
3
+ end
data/lib/HttpHelper.rb ADDED
@@ -0,0 +1,124 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'rbconfig'
5
+ require_relative 'GettyImagesApi/version'
6
+
7
+ class Api_Host
8
+ API_HOST = "api.gettyimages.com"
9
+ API_BASE_URL = "https://#{API_HOST}"
10
+ end
11
+
12
+ class HttpHelper
13
+
14
+ def initialize(api_key, access_token)
15
+ @api_key = api_key
16
+ @access_token = access_token
17
+ end
18
+
19
+ def get_uri(path)
20
+ return URI.parse "#{Api_Host::API_BASE_URL}#{path}"
21
+ end
22
+
23
+ def get(endpoint_path, query_params)
24
+
25
+ uri = get_uri(endpoint_path)
26
+ #puts uri
27
+ if !query_params.nil?
28
+ uri.query = URI.encode_www_form query_params
29
+ end
30
+ #puts "REQUEST URI: #{uri.request_uri}"
31
+ req = Net::HTTP::Get.new uri.request_uri
32
+ return send uri, req, @api_key, @access_token
33
+
34
+ end
35
+
36
+ def post(endpoint_path, query_params, body)
37
+
38
+ uri = get_uri(endpoint_path)
39
+ if !query_params.nil?
40
+ uri.query = URI.encode_www_form query_params
41
+ end
42
+ req = Net::HTTP::Post.new uri.request_uri
43
+ if !body.nil?
44
+ req["Content-Type"] = "application/json"
45
+ req.body = body.to_json
46
+ end
47
+ return send uri, req, @api_key, @access_token
48
+
49
+ end
50
+
51
+ def put(endpoint_path, query_params, body)
52
+
53
+ uri = get_uri(endpoint_path)
54
+ if !query_params.nil?
55
+ uri.query = URI.encode_www_form query_params
56
+ end
57
+ req = Net::HTTP::Put.new uri.request_uri
58
+ if !body.nil?
59
+ req["Content-Type"] = "application/json"
60
+ req.body = body.to_json
61
+ end
62
+ return send uri, req, @api_key, @access_token
63
+
64
+ end
65
+
66
+ def delete(endpoint_path, query_params)
67
+
68
+ uri = get_uri(endpoint_path)
69
+ if !query_params.nil?
70
+ uri.query = URI.encode_www_form query_params
71
+ end
72
+ req = Net::HTTP::Delete.new uri.request_uri
73
+ return send uri, req, @api_key, @access_token
74
+
75
+ end
76
+
77
+ private
78
+ def os
79
+ @os ||= (
80
+ host_os = RbConfig::CONFIG['host_os']
81
+ case host_os
82
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
83
+ :windows
84
+ when /darwin|mac os/
85
+ :macosx
86
+ when /linux/
87
+ :linux
88
+ when /solaris|bsd/
89
+ :unix
90
+ else
91
+ raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
92
+ end)
93
+ end
94
+
95
+ private
96
+ def send(uri, request, api_key, bearer_token = "")
97
+
98
+ # define HTTPS connection
99
+ https = Net::HTTP.new(uri.host, uri.port)
100
+ https.use_ssl = true
101
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
102
+
103
+ # define headers
104
+ request["User-Agent"] = "GettImagesApiSdk/#{GettyImagesApi::VERSION} (#{os} ; Ruby #{RUBY_VERSION})"
105
+ request["Api-Key"] = api_key
106
+ request["Authorization"] = "Bearer #{bearer_token}" unless bearer_token.empty?
107
+
108
+ # send request
109
+ resp = https.request request
110
+
111
+ if !resp.is_a?(Net::HTTPSuccess)
112
+ data = JSON.parse(resp.body)
113
+ raise "HTTP RESPONSE: #{data}"
114
+ end
115
+
116
+ if resp.code == '204'
117
+ return Hash.new
118
+ end
119
+
120
+ return JSON.parse(resp.body)
121
+
122
+ end
123
+
124
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class Images < RequestBase
4
+
5
+ attr_accessor :asset_id
6
+
7
+ API_ROUTE = "/v3/images" # mashery endpoint
8
+ QUERY_PARAMS_NAMES = ["ids","fields"]
9
+
10
+ QUERY_PARAMS_NAMES.each do |key|
11
+ define_method :"with_#{key}" do |value = true|
12
+ value = value.join(",")
13
+ if !key.include? "id"
14
+ value.downcase!
15
+ end
16
+ build_query_params(key, value)
17
+ return self
18
+ end
19
+ end
20
+
21
+ public
22
+ def with_id(id)
23
+ self.asset_id = id
24
+ return self
25
+ end
26
+
27
+ public
28
+ def execute
29
+ self.asset_id.nil? ? uri = API_ROUTE : uri = API_ROUTE + "/" + self.asset_id
30
+ return @http_helper.get(uri, @query_params)
31
+ end
32
+
33
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "HttpHelper"
2
+
3
+ class RequestBase
4
+
5
+ attr_accessor :http_helper, :query_params
6
+
7
+ def initialize(api_key, access_token)
8
+
9
+ #puts "here is my token #{access_token}"
10
+ @http_helper = HttpHelper.new(api_key, access_token)
11
+ @query_params = Hash.new
12
+
13
+ end
14
+
15
+ protected
16
+ def build_query_params(key, value)
17
+ @query_params[key].nil? ? @query_params[key] = value : @query_params[key] << "," + value
18
+ end
19
+
20
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class SearchImages < RequestBase
4
+
5
+ API_ROUTE = "/v3/search/images" # mashery endpoint
6
+ QUERY_PARAMS_NAMES = ["age_of_people","artists","collection_codes","collections_filter_type","color","compositions","embed_content_only","ethnicity","event_ids","exclude_nudity","fields",
7
+ "file_types","graphical_styles","keyword_ids","license_models","minimum_size","number_of_people","orientations","page","page_size","phrase","prestige_content_only","product_types",
8
+ "sort_order","specific_people"]
9
+
10
+ QUERY_PARAMS_NAMES.each do |key|
11
+ define_method :"with_#{key}" do |value = true|
12
+ if value.is_a?(Array)
13
+ value = value.join(",")
14
+ if (!key.include? "id") && (!key.include? "orientations")
15
+ value.downcase!
16
+ end
17
+ build_query_params(key, value)
18
+ else
19
+ if (!key.include? "id") && (!key.include? "orientations") && (value.is_a?(String))
20
+ value.downcase!
21
+ end
22
+ build_query_params(key, value)
23
+ end
24
+ return self
25
+ end
26
+ end
27
+
28
+ def execute
29
+ return @http_helper.get(API_ROUTE, @query_params)
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,32 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class SearchImagesCreative < RequestBase
4
+
5
+ API_ROUTE = "/v3/search/images/creative" # mashery endpoint
6
+ QUERY_PARAMS_NAMES = ["age_of_people","artists","collection_codes","collections_filter_type","color","compositions","embed_content_only","ethnicity","exclude_nudity","fields","file_types",
7
+ "graphical_styles","keyword_ids","license_models","minimum_size","number_of_people","orientations","page","page_size","phrase","prestige_content_only","product_types",
8
+ "sort_order"]
9
+
10
+ QUERY_PARAMS_NAMES.each do |key|
11
+ define_method :"with_#{key}" do |value = true|
12
+ if value.is_a?(Array)
13
+ value = value.join(",")
14
+ if (!key.include? "id") && (!key.include? "orientations")
15
+ value.downcase!
16
+ end
17
+ build_query_params(key, value)
18
+ else
19
+ if (!key.include? "id") && (!key.include? "orientations") && (value.is_a?(String))
20
+ value.downcase!
21
+ end
22
+ build_query_params(key, value)
23
+ end
24
+ return self
25
+ end
26
+ end
27
+
28
+ def execute
29
+ return @http_helper.get(API_ROUTE, @query_params)
30
+ end
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class SearchImagesEditorial < RequestBase
4
+
5
+ API_ROUTE = "/v3/search/images/editorial" # mashery endpoint
6
+ QUERY_PARAMS_NAMES = ["age_of_people","artists","collection_codes","collections_filter_type","compositions","editorial_segments","embed_content_only","end_date","entity_uris","ethnicity",
7
+ "event_ids","exclude_nudity","fields","file_types","graphical_styles","keyword_ids","minimum_quality_rank","minimum_size","number_of_people","orientations","page","page_size","phrase",
8
+ "product_types","sort_order","specific_people","start_date"]
9
+
10
+ QUERY_PARAMS_NAMES.each do |key|
11
+ define_method :"with_#{key}" do |value = true|
12
+ if value.is_a?(Array)
13
+ value = value.join(",")
14
+ if (!key.include? "id") && (!key.include? "orientations")
15
+ value.downcase!
16
+ end
17
+ build_query_params(key, value)
18
+ else
19
+ if (!key.include? "id") && (!key.include? "orientations") && (value.is_a?(String))
20
+ value.downcase!
21
+ end
22
+ build_query_params(key, value)
23
+ end
24
+ return self
25
+ end
26
+ end
27
+
28
+ def execute
29
+ return @http_helper.get(API_ROUTE, @query_params)
30
+ end
31
+
32
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class SearchVideos < RequestBase
4
+
5
+ API_ROUTE = "/v3/search/videos" # mashery endpoint
6
+ QUERY_PARAMS_NAMES = ["age_of_people","collection_codes","collections_filter_type","editorial_video_types","exclude_nudity","fields","format_available","frame_rates",
7
+ "keyword_ids","license_models","page","page_size","phrase","product_types","sort_order","specific_people"]
8
+
9
+ QUERY_PARAMS_NAMES.each do |key|
10
+ define_method :"with_#{key}" do |value = true|
11
+ if value.is_a?(Array)
12
+ value = value.join(",")
13
+ if !key.include? "id"
14
+ value.downcase!
15
+ end
16
+ build_query_params(key, value)
17
+ else
18
+ if (!key.include? "id") && (value.is_a?(String))
19
+ value.downcase!
20
+ end
21
+ build_query_params(key, value)
22
+ end
23
+ return self
24
+ end
25
+ end
26
+
27
+ def execute
28
+ return @http_helper.get(API_ROUTE, @query_params)
29
+ end
30
+
31
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class SearchVideosCreative < RequestBase
4
+
5
+ API_ROUTE = "/v3/search/videos/creative" # mashery endpoint
6
+ QUERY_PARAMS_NAMES = ["age_of_people","collection_codes","collections_filter_type","exclude_nudity","fields","format_available","frame_rates",
7
+ "keyword_ids","license_models","page","page_size","phrase","product_types","sort_order"]
8
+
9
+ QUERY_PARAMS_NAMES.each do |key|
10
+ define_method :"with_#{key}" do |value = true|
11
+ if value.is_a?(Array)
12
+ value = value.join(",")
13
+ if !key.include? "id"
14
+ value.downcase!
15
+ end
16
+ build_query_params(key, value)
17
+ else
18
+ if (!key.include? "id") && (value.is_a?(String))
19
+ value.downcase!
20
+ end
21
+ build_query_params(key, value)
22
+ end
23
+ return self
24
+ end
25
+ end
26
+
27
+ def execute
28
+ return @http_helper.get(API_ROUTE, @query_params)
29
+ end
30
+
31
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class SearchVideosEditorial < RequestBase
4
+
5
+ API_ROUTE = "/v3/search/videos/editorial" # mashery endpoint
6
+ QUERY_PARAMS_NAMES = ["age_of_people","collection_codes","collections_filter_type","editorial_video_types","entity_uris","exclude_nudity","fields","format_available","frame_rates",
7
+ "keyword_ids","page","page_size","phrase","product_types","sort_order","specific_people"]
8
+
9
+ QUERY_PARAMS_NAMES.each do |key|
10
+ define_method :"with_#{key}" do |value = true|
11
+ if value.is_a?(Array)
12
+ value = value.join(",")
13
+ if !key.include? "id"
14
+ value.downcase!
15
+ end
16
+ build_query_params(key, value)
17
+ else
18
+ if (!key.include? "id") && (value.is_a?(String))
19
+ value.downcase!
20
+ end
21
+ build_query_params(key, value)
22
+ end
23
+ return self
24
+ end
25
+ end
26
+
27
+ def execute
28
+ return @http_helper.get(API_ROUTE, @query_params)
29
+ end
30
+
31
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "../RequestBase.rb"
2
+
3
+ class Videos < RequestBase
4
+
5
+ attr_accessor :asset_id
6
+
7
+ API_ROUTE = "/v3/videos" # mashery endpoint
8
+ QUERY_PARAMS_NAMES = ["ids","fields"]
9
+
10
+ QUERY_PARAMS_NAMES.each do |key|
11
+ define_method :"with_#{key}" do |value = true|
12
+ value = value.join(",")
13
+ if !key.include? "id"
14
+ value.downcase!
15
+ end
16
+ build_query_params(key, value)
17
+ return self
18
+ end
19
+ end
20
+
21
+ public
22
+ def with_id(id)
23
+ self.asset_id = id
24
+ return self
25
+ end
26
+
27
+ public
28
+ def execute
29
+ self.asset_id.nil? ? uri = API_ROUTE : uri = API_ROUTE + "/" + self.asset_id
30
+ return @http_helper.get(uri, @query_params)
31
+ end
32
+
33
+ end
@@ -0,0 +1 @@
1
+ require_relative 'ApiClient'
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gettyimages-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Getty Images
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Getty Images API SDK
42
+ email:
43
+ - developersupport@gettyimages.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".vscode/launch.json"
50
+ - ".vscode/tasks.json"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - gettyimages-api.gemspec
57
+ - lib/ApiClient.rb
58
+ - lib/Credentials.rb
59
+ - lib/CustomRequest/CustomRequest.rb
60
+ - lib/Downloads/DownloadImages.rb
61
+ - lib/Downloads/DownloadVideos.rb
62
+ - lib/Example.rb
63
+ - lib/GettyImagesApi/version.rb
64
+ - lib/HttpHelper.rb
65
+ - lib/Images/Images.rb
66
+ - lib/RequestBase.rb
67
+ - lib/Search/SearchImages.rb
68
+ - lib/Search/SearchImagesCreative.rb
69
+ - lib/Search/SearchImagesEditorial.rb
70
+ - lib/Search/SearchVideos.rb
71
+ - lib/Search/SearchVideosCreative.rb
72
+ - lib/Search/SearchVideosEditorial.rb
73
+ - lib/Videos/Videos.rb
74
+ - lib/gettyimages-api.rb
75
+ homepage: https://github.com/gettyimages/gettyimages-api_ruby
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Getty Images API SDK
99
+ test_files: []