ConnectSDK 1.0.1.Beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjdlMjg4NDU1Nzg3Zjk5YjRjZWJlMzQ0ODI1ZjAwMTE0Zjc1ODIyYg==
5
+ data.tar.gz: !binary |-
6
+ YWQ3ZTdkZWU5MTJlOWVlZDU1N2M4OWYyYzc5YTA0MWJjYmNkNTU4NQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZTRmNjA5ZThjYmIwOTQ0MWM4NDQzNjczZTI2NDkzNDM4OGU0Yzc0MDQ0ZmRi
10
+ YTdjNjkxMTA0N2IzMDQ2ODYxYzU3MzFkOWY5NTEyYTUzM2NmYzNiMzdiNjFk
11
+ NzA3NzY3MzRjZDllMjlmMjFhZTNmNDUyNzE3NTkwMWQzOGE3OGI=
12
+ data.tar.gz: !binary |-
13
+ MjY3Mjk0NmYzYjNhMDVkYTMxODZkN2UyN2JjOWZkZGZmYzg3Y2U0M2Q4ZTAy
14
+ N2IxZGJhNGQ4YzJlNDY2ZGMxMWZmOTc1ZmQ4MTA4Mjg3YTlmMzAyNDU0ZDBh
15
+ MzkyOTFlYjExNDkxYWUzZTYzNjYxOTA5YjFjZTM4ZTc4MzI2NDI=
@@ -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,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ConnectSDK/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ConnectSDK"
8
+ spec.version = ConnectSDK::VERSION
9
+ spec.authors = ["Rod Santos, Lisa Guo"]
10
+ spec.email = ["rod.santos@gettyimages.com"]
11
+ spec.summary = "Connect SDK"
12
+ spec.description = "Connect SDK"
13
+ spec.homepage = "http://api.gettyimages.com/"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.7"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+
22
+ end
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ConnectSDK.gemspec
4
+ gemspec
5
+
6
+ gem 'json', '~> 1.8.1'
7
+ gem 'rake', '~> 0.9.2.2'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Getty Images
2
+
3
+ MIT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ ## Requirements
2
+ - Ruby version > 1.9.3
3
+ - [Bundler](http://bundler.io) version > 1.7.3
4
+
5
+ ## Building Gem Package
6
+ The following describes how to create the local gem package for Connect SDK. The package will be created in the pkg folder in the source code location.
7
+
8
+ $ cd connect_sdk_ruby/ConnectSDK
9
+ $ bundle exec rake build
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,52 @@
1
+ # Connect SDK by Getty Images.
2
+ # Provides an interface to Getty Images connect api.
3
+ #
4
+ # The goal of the SDK is to simplify credential management and provide a reusable library
5
+ # for developers.
6
+
7
+ require_relative "Credentials"
8
+ require_relative "SearchRequest"
9
+ require_relative "ImagesRequest"
10
+ require_relative "DownloadRequest"
11
+
12
+ # ConnectSDK
13
+ # Provides a code api for interacting with getty rest services.
14
+ # {https://connect.gettyimages.com/swagger/ui/index.html Connect Getty Images API}
15
+
16
+ class ConnectSdk
17
+
18
+ # Initialize the Credentials to be used by the SDK
19
+ def initialize(api_key, api_secret, user_name = nil, password = nil)
20
+
21
+ @credentials = Credentials.new(
22
+ :credential_type => (user_name.nil?) || (password.nil?) ? OAuthGrantType::CLIENT_CREDENTIALS : OAuthGrantType::PASSWORD,
23
+ :client_key => api_key,
24
+ :client_secret => api_secret,
25
+ :user_name => user_name,
26
+ :password => password)
27
+ end
28
+
29
+ # Get access token to be used by the SDK
30
+ def get_access_token
31
+ return @credentials.get_access_token
32
+ end
33
+
34
+ # Create a search configuration that support image searching
35
+ # SearchRequest configured for a image search
36
+ def search()
37
+ return SearchRequest.new(@credentials.client_key, @credentials.get_access_token)
38
+ end
39
+
40
+ # Create a image details configuration that support image details
41
+ # == Returns:
42
+ # ImagesRequest configured for a image details
43
+ def images()
44
+ return ImagesRequest.new(@credentials.client_key, @credentials.get_access_token)
45
+ end
46
+
47
+ def download
48
+ return DownloadRequest.new(@credentials.client_key, @credentials.get_access_token)
49
+ end
50
+
51
+ end
52
+
@@ -0,0 +1,3 @@
1
+ module ConnectSDK
2
+ VERSION = '1.0.1.Beta'
3
+ end
@@ -0,0 +1,67 @@
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 "#{Connect_Api_Host::API_BASE_URL}#{path}"
23
+ end
24
+
25
+ # Get Access Token Using Connect API OAuth 2.0
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 if res.is_a?(Net::HTTPSuccess)
61
+ result = JSON.parse(data)
62
+
63
+ return result['access_token']
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'HttpHelper'
2
+
3
+ class DownloadRequest
4
+
5
+ attr_accessor :asset_id
6
+
7
+ def initialize(api_key, access_token)
8
+
9
+ self
10
+ @api_key = api_key
11
+ @access_token = access_token
12
+
13
+ @http_helper = HttpHelper.new(api_key, access_token)
14
+
15
+ end
16
+
17
+ public
18
+ def with_id(asset_id)
19
+ self.asset_id = asset_id
20
+ return self
21
+ end
22
+
23
+ public
24
+ def execute
25
+
26
+ uri = '/v3/downloads/' + self.asset_id + '?auto_download=false'
27
+ data = @http_helper.post(uri)
28
+ return data['uri']
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,22 @@
1
+ require "pp"
2
+ require_relative "ConnectSDK"
3
+
4
+ api_key = "3z7q8fyw8ach5kr3mg35dkqz"
5
+ api_secret = "kYksrEH4Vyn6txeT5tFDJjxsdVYqS6usNDupa3aYWpwkr"
6
+
7
+ # Example of Connect SDK
8
+ connectSdk = ConnectSdk.new(api_key, api_secret)
9
+ search_results = connectSdk.search().images().creative()
10
+ .with_phrase("gorilla")
11
+ .with_response_fields(["id","title"])
12
+ .with_graphical_styles("illustration")
13
+ .with_graphical_styles(["fine_art","photography"])
14
+ .with_page(2)
15
+ .with_page_size(5)
16
+ .execute()
17
+
18
+ search_results["images"].each do | image |
19
+ puts "Id: #{image["id"]} Title: #{image["title"]}"
20
+ end
21
+
22
+
@@ -0,0 +1,69 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "json"
4
+
5
+ class Connect_Api_Host
6
+ API_HOST = "connect.gettyimages.com"
7
+ # API_HOST = "gibson.candidate-gettyimages.com/Public"
8
+ API_BASE_URL = "https://#{API_HOST}"
9
+ end
10
+
11
+ class HttpHelper
12
+
13
+ def initialize(api_key, access_token)
14
+ @api_key = api_key
15
+ @access_token = access_token
16
+ end
17
+
18
+ public
19
+ def get_uri(path)
20
+ return URI.parse "#{Connect_Api_Host::API_BASE_URL}#{path}"
21
+ end
22
+
23
+ public
24
+ def get(endpoint_path, query_params)
25
+
26
+ uri = get_uri(endpoint_path)
27
+ #puts uri
28
+ if !query_params.nil?
29
+ uri.query = URI.encode_www_form query_params
30
+ end
31
+ #puts "REQUEST URI: #{uri.request_uri}"
32
+ req = Net::HTTP::Get.new uri.request_uri
33
+ return send uri, req, @api_key, @access_token
34
+
35
+ end
36
+
37
+ public
38
+ def post(endpoint_path)
39
+
40
+ uri = get_uri endpoint_path
41
+ req = Net::HTTP::Post.new uri.request_uri
42
+ return send uri, req, @api_key, @access_token
43
+
44
+ end
45
+
46
+ def send(connect_uri, connect_request, api_key, bearer_token = "")
47
+
48
+ # define HTTPS connection
49
+ https = Net::HTTP.new(connect_uri.host, connect_uri.port)
50
+ https.use_ssl = true
51
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
52
+
53
+ # define headers
54
+ connect_request["Api-Key"] = api_key
55
+ connect_request["Authorization"] = "Bearer #{bearer_token}" unless bearer_token.empty?
56
+
57
+ # send request
58
+ resp = https.request connect_request
59
+ # puts "HTTP RESPONSE: #{resp}"
60
+
61
+ if !resp.is_a?(Net::HTTPSuccess)
62
+ raise "HTTP RESPONSE: #{resp}"
63
+ end
64
+
65
+ return JSON.parse(resp.body)
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "RequestBase"
2
+
3
+ class ImagesRequest < RequestBase
4
+
5
+ CONNECT_ROUTE = "/v3/images" # mashery endpoint
6
+
7
+ QUERY_PARAMS_NAMES = ["page","page_size"]
8
+
9
+ QUERY_PARAMS_NAMES.each do |key|
10
+ define_method :"with_#{key}" do |value = true|
11
+ if value.is_a?(Array)
12
+ build_query_params(key, value.join(","))
13
+ else
14
+ build_query_params(key, value)
15
+ end
16
+ return self
17
+ end
18
+ end
19
+
20
+ public
21
+ def with_ids(ids)
22
+ @ids = ids.join("%2C")
23
+ return self
24
+ end
25
+
26
+ public
27
+ def execute
28
+ return @http_helper.get("#{CONNECT_ROUTE}/#{@ids}", @query_params)
29
+ return "here"
30
+ end
31
+
32
+ end
@@ -0,0 +1,33 @@
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
+ public
16
+ def with_response_fields(fields)
17
+ build_query_params("fields", fields.join(","))
18
+ return self
19
+ end
20
+
21
+ public
22
+ def with_response_field(field)
23
+ build_query_params("fields", field)
24
+ return self
25
+ end
26
+
27
+ protected
28
+ def build_query_params(key, value)
29
+ @query_params[key].nil? ? @query_params[key] = value : @query_params[key] << "," + value
30
+ end
31
+
32
+
33
+ end
@@ -0,0 +1,38 @@
1
+ require_relative "RequestBase"
2
+
3
+ class SearchImages < RequestBase
4
+
5
+ CONNECT_ROUTE = "/v3/search/images" # mashery endpoint
6
+ @@search_route = CONNECT_ROUTE
7
+ QUERY_PARAMS_NAMES = ["phrase","editorial_segments","graphical_styles","license_models","orientations","exclude_nudity","embed_content_only","page","page_size"]
8
+
9
+ QUERY_PARAMS_NAMES.each do |key|
10
+ define_method :"with_#{key}" do |value = true|
11
+ if value.is_a?(Array)
12
+ build_query_params(key, value.join(","))
13
+ else
14
+ build_query_params(key, value)
15
+ end
16
+ return self
17
+ end
18
+ end
19
+
20
+ # {https://connect.gettyimages.com/swagger/ui/index.html#!/Search/Search_GetCreativeImagesByPhrase Creative Swagger}
21
+ # with_graphical_styles
22
+ # with_license_models
23
+ def creative()
24
+ @@search_route = "#{CONNECT_ROUTE}/creative"
25
+ return self
26
+ end
27
+
28
+ def editorial()
29
+ @@search_route = "#{CONNECT_ROUTE}/editorial"
30
+ return self
31
+ end
32
+
33
+ def execute
34
+ return @http_helper.get(@@search_route, @query_params)
35
+ end
36
+
37
+ end
38
+
@@ -0,0 +1,15 @@
1
+ require_relative "SearchImages"
2
+
3
+ class SearchRequest
4
+
5
+ def initialize(api_key, token)
6
+ @api_key = api_key
7
+ @token = token
8
+ end
9
+
10
+ public
11
+ def images()
12
+ return SearchImages.new(@api_key, @token)
13
+ end
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ConnectSDK
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1.Beta
5
+ platform: ruby
6
+ authors:
7
+ - Rod Santos, Lisa Guo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-02 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: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Connect SDK
42
+ email:
43
+ - rod.santos@gettyimages.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - ConnectSDK.gemspec
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/ConnectSDK.rb
55
+ - lib/ConnectSDK/version.rb
56
+ - lib/Credentials.rb
57
+ - lib/DownloadRequest.rb
58
+ - lib/Example.rb
59
+ - lib/HttpHelper.rb
60
+ - lib/ImagesRequest.rb
61
+ - lib/RequestBase.rb
62
+ - lib/SearchImages.rb
63
+ - lib/SearchRequest.rb
64
+ homepage: http://api.gettyimages.com/
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ! '>'
80
+ - !ruby/object:Gem::Version
81
+ version: 1.3.1
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.4.2
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Connect SDK
88
+ test_files: []