getty_connect 0.0.2

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.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ *.swp
5
+ *.swo
6
+ .config
7
+ .yardoc
8
+ .DS_STORE
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order random
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in getty-connect.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+ # Capybara request specs
17
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
18
+ end
19
+
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Avos Systems Inc.
2
+
3
+ MIT License
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.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # GettyConnect
2
+
3
+ An *un-official* ruby wrapper for the Getty Images [Connect API](https://api.gettyimages.com/apis).
4
+
5
+ ![Getty Connect](https://api.gettyimages.com/sites/all/themes/getty_images/images/theme-developer_connect/Connect_logo.png "Getty Connect")
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'getty_connect'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install getty_connect
20
+
21
+ ## Usage Examples
22
+
23
+ ### Creating and configuring a client
24
+ ```ruby
25
+ GettyConnect.configure do |c|
26
+ c.system_id = YOUR_SYSTEM_ID
27
+ c.system_password = YOUR_SYSTEM_PASSWORD
28
+ c.api_username = YOUR_API_USERNAME
29
+ c.api_password = YOUR_API_PASSWORD
30
+ end
31
+
32
+ client = GettyConnect.new
33
+ ```
34
+
35
+ ### Requesting an authentication token
36
+ ```ruby
37
+ client.request_token
38
+ ```
39
+ With the duration of client.token_duration, tokens can be renewed with
40
+
41
+ ```ruby
42
+ client.renew_token
43
+ ```
44
+
45
+ ### Search & Image Details
46
+ ```ruby
47
+ client.search("phrase", options={})
48
+ ```
49
+ e.g. to return 5 images of bears
50
+
51
+ ```ruby
52
+ client.search("bears", options={:item_count => 5}
53
+ ```
54
+
55
+ search() will return a subset of image metadata. To retrieve all metadata for a particular asset use:
56
+
57
+ ```ruby
58
+ client.get_image_details(assetIds)
59
+ ```
60
+
61
+ ### Retrieving Image URLs
62
+
63
+ #### Preview images
64
+ Options are _comp_, _preview_, _thumb_, _watermark_comp_, _watermark_preview_
65
+
66
+ ```ruby
67
+ client.get_preview(["143895284", "143895289"], "thumb")
68
+ ```
69
+
70
+ ## API Documentation
71
+
72
+ Run the following command to generate documentation:
73
+
74
+ rake doc:yard
75
+
76
+ ## Not Yet Implemented
77
+
78
+ * GetEvents
79
+ * GetLargestImageDownloadAuthorizations
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create new Pull Request
88
+
89
+ ## Inspiration
90
+
91
+ Inspired by the [Twitter](https://github.com/jnunemaker/twitter) API gem.
92
+
93
+ ## Copyright
94
+ Copyright (c) 2012 Avos Systems Inc.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
10
+ namespace :doc do
11
+ require 'yard'
12
+ YARD::Rake::YardocTask.new do |task|
13
+ task.files = ['lib/**/*.rb']
14
+ task.options = [
15
+ '--output-dir', 'doc/yard',
16
+ '--markup', 'markdown',
17
+ '--readme', 'README.md']
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/getty_connect/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'faraday', '~> 0.8'
6
+ gem.add_dependency 'faraday_middleware', '~> 0.8'
7
+ gem.add_dependency 'hashie', '~> 1.2'
8
+ gem.add_dependency 'multi_json', '~> 1.3'
9
+ gem.add_development_dependency 'rake'
10
+ gem.add_development_dependency 'rspec', '~> 2.6'
11
+ gem.add_development_dependency 'guard-rspec'
12
+ gem.add_development_dependency 'json'
13
+ gem.add_development_dependency 'yard', '~> 0.8'
14
+ gem.add_development_dependency 'webmock'
15
+
16
+ gem.authors = ["Bayard Randel"]
17
+ gem.email = ["kit@avos.com"]
18
+ gem.description = %q{A ruby wrapper for the Getty Images Connect API}
19
+ gem.summary = %q{Getty Images Connect API wrapper}
20
+ gem.homepage = "https://github.com/avos/getty_connect/"
21
+
22
+ gem.files = `git ls-files`.split($\)
23
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
25
+ gem.name = "getty_connect"
26
+ gem.require_paths = ["lib"]
27
+ gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
28
+ gem.version = GettyConnect::VERSION
29
+ end
@@ -0,0 +1,44 @@
1
+ require 'faraday'
2
+ require 'multi_json'
3
+
4
+ # @api private
5
+ module Faraday
6
+ class Response::RaiseGettyConnectError < Response::Middleware
7
+ def on_complete(response)
8
+ case response[:status].to_i
9
+ when 400
10
+ raise GettyConnect::BadRequest, error_message(response)
11
+ when 401
12
+ raise GettyConnect::Unauthorized, error_message(response)
13
+ when 403
14
+ raise GettyConnect::Forbidden, error_message(response)
15
+ when 404
16
+ raise GettyConnect::NotFound, error_message(response)
17
+ when 406
18
+ raise GettyConnect::NotAcceptable, error_message(response)
19
+ when 422
20
+ raise GettyConnect::UnprocessableEntity, error_message(response)
21
+ when 500
22
+ raise GettyConnect::InternalServerError, error_message(response)
23
+ when 501
24
+ raise GettyConnect::NotImplemented, error_message(response)
25
+ when 502
26
+ raise GettyConnect::BadGateway, error_message(response)
27
+ when 503
28
+ raise GettyConnect::ServiceUnavailable, error_message(response)
29
+ end
30
+ end
31
+
32
+ def error_message(response)
33
+ message = if (body = response[:body]) && !body.empty?
34
+ if body.is_a?(String)
35
+ body = MultiJson.load(body, :symbolize_keys => true)
36
+ end
37
+ ": #{body[:error] || body[:message] || ''}"
38
+ else
39
+ ''
40
+ end
41
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{message}"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,169 @@
1
+ module GettyConnect
2
+ class Client
3
+ module Image
4
+
5
+ # Search for images by keyword.
6
+ #
7
+ # @param phrase [String] The search phrase.
8
+ # param options [Hash] A customisable set of options
9
+ # @option options [Array] :filetypes String array of filetypes. Possible
10
+ # values are `eps` and `jpg`.
11
+ # @option options [Integer] :item_count Number of items to return
12
+ # @option options [Integer] :item_start_number Returns the index of
13
+ # the first image. Use with `:item_count` to support pagination.
14
+ # @option options [String] :language String. Specify an IETF RFC 5646
15
+ # compliant language tag to determine the language used for localizable
16
+ # strings returned in the response. Defaults to `en-US`.
17
+ # @option options [Array] :licenses Array of strings specifying a type
18
+ # of license by which to filter results.
19
+ # Possible values are: `royaltyfree`, `rightsmanaged`.
20
+ # @option options [String] :orientations Possible values are: `horizontal`,
21
+ # `vertical`, `panoramichorizontal`, `panoramicvertical`, `square`
22
+ # @option options [Array] :specific_persons Specify the personalities
23
+ # to query the images that match all of the specified personalities.
24
+ # @example Search for images of bears, returning a max. of 5 results
25
+ # client.search("bears", {:item_count => 5})
26
+ def search(phrase, options={})
27
+
28
+ request = {
29
+ :RequestHeader => { :Token => self.token},
30
+ :SearchForImages2RequestBody => {
31
+ :Query => {
32
+ :SearchPhrase => phrase,
33
+ :SpecificPersons => options[:specific_persons],
34
+ },
35
+ :Language => options[:language] || "en-us",
36
+ :ResultOptions => {
37
+ :ItemCount => options[:item_count] || 15,
38
+ :ItemStartNumber => options[:item_start_number] || 1
39
+ },
40
+ :Filter => {
41
+ :LicensingModels => options[:licenses] || ["royaltyfree"],
42
+ :Orientations => options[:orientations],
43
+ :FileTypes => options[:filetypes] || ["jpg"],
44
+ :ProductOfferings => options[:product_offerings] || ["EasyAccess"]
45
+ },
46
+ }
47
+ }
48
+ post(@search_endpoint, request)
49
+ end
50
+
51
+ # Returns list of authorized downloads
52
+ get_largest_download_auth(asset_ids)
53
+ request = {
54
+ :RequestHeader => {
55
+ :Token => self.token,
56
+ :CoordinationId => options[:coordination_id] || ""
57
+ },
58
+ :GetLargestImageDownloadAuthorizationsRequestBody => {
59
+ :ImageIds => asset_ids
60
+ }
61
+ }
62
+ post(@download_largest_endpoint, request)
63
+ end
64
+
65
+ # Returns detailed image metadata for all specified images.
66
+ #
67
+ # @param assetIds [Array] An array of AssetIds
68
+ # @param options [Hash] A customisable set of options
69
+ # @option options [String] :coordination_id Indicates the CoordinationId
70
+ # value provided in the triggering request.
71
+ # @option options [String] :country_code Enables hide/block rules based on
72
+ # locale-based limitations on content; filters out any image whose use is
73
+ # prohibited in the specific country. Accepts three-letter country codes
74
+ # as defined in ISO 3166-1
75
+ # http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3#Current_codes.
76
+ # Defaults to USA.
77
+ # @option options [String] :language String. Specify an IETF RFC 5646
78
+ # compliant language tag to determine the language used for localizable
79
+ # strings returned in the response. Defaults to `en-US`.
80
+ def get_details(assetIds, options={})
81
+ request = {
82
+ :RequestHeader => {
83
+ :Token => self.token,
84
+ :CoordinationId => options[:coordination_id] || ""
85
+ },
86
+ :GetImageDetailsRequestBody => {
87
+ :CountryCode => options[:country_code] || "USA",
88
+ :ImageIds => assetIds,
89
+ :Language => options[:language] || "en-us"
90
+ }
91
+ }
92
+ post(@image_details_endpoint, request)
93
+ end
94
+
95
+ # Convenience method. Returns a collection of urls and imageids
96
+ #
97
+ # @param assetIds [Array] Array of assetIds
98
+ # @param preview_format [String] Format of preview image. Options in order
99
+ # of size are: `thumb`, `preview`, `comp`, `watermark_preview`,
100
+ # `watermark_comp`
101
+ def get_preview(assetIds, preview_format)
102
+ response = get_details(assetIds)
103
+ preview = []
104
+ response.GetImageDetailsResult.Images.each do |image, index|
105
+ url = ""
106
+ case preview_format
107
+ when "comp"
108
+ url = image.UrlComp
109
+ when "preview"
110
+ url = image.UrlPreview
111
+ when "thumb"
112
+ url = image.UrlThumb
113
+ when "watermark_comp"
114
+ url = image.UrlWatermarkComp
115
+ when "watermark_preview"
116
+ url = image.UrlWatermarkPreview
117
+ end
118
+ preview << { "imageId" => image.ImageId,
119
+ "url" => url }
120
+ end
121
+ preview
122
+ end
123
+
124
+ # Requests download authorisation for image
125
+ #
126
+ # @param image_id [Integer] Id of image
127
+ # @param size_key [String] Identifies size of the image being authorized
128
+ # for download. Returned from `get_details()`.
129
+ def get_download_token(image_id, size_key)
130
+ request = {
131
+ :RequestHeader => {
132
+ :Token => self.token
133
+ },
134
+ :GetImageDownloadAuthorizationsRequestBody => {
135
+ :ImageSizes => [{
136
+ :ImageId => image_id,
137
+ :SizeKey => size_key
138
+ }]
139
+ }
140
+ }
141
+ response = post(@download_auth_endpoint, request)
142
+ response.GetImageDownloadAuthorizationsResult.Images.first.Authorizations.first.DownloadToken
143
+ end
144
+
145
+ # Returns download urls and related data for images
146
+ #
147
+ # @param download_token [String] Specify the token authorizing the image
148
+ # download. Use the DownloadToken value provided by
149
+ # `get_download_authorisation()` or `get_largest_download_authorisation()`
150
+ # @option options [String] :coordination_id Value will be echoed in the
151
+ # response. Can be used to track requests.
152
+ def download(download_token, options={})
153
+ request = {
154
+ :RequestHeader => {
155
+ :Token => self.secure_token,
156
+ :CoordinationId => options[:coordination_id] || ""
157
+ },
158
+ :CreateDownloadRequestBody => {
159
+ :DownloadItems => [{
160
+ :DownloadToken => download_token
161
+ }]
162
+ }
163
+ }
164
+ post(@download_request_endpoint, request)
165
+ end
166
+
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,52 @@
1
+ module GettyConnect
2
+ class Client
3
+ module Session
4
+
5
+ def request_token(options={})
6
+ options = {
7
+ :RequestHeader => {
8
+ :Token => ''
9
+ },
10
+ :CreateSessionRequestBody => {
11
+ :SystemId => GettyConnect.system_id,
12
+ :SystemPassword => GettyConnect.system_password,
13
+ :UserName => GettyConnect.api_username,
14
+ :UserPassword => GettyConnect.api_password
15
+ }
16
+ }.merge options
17
+
18
+ response = post(@create_session_endpoint, options)
19
+ if response.ResponseHeader.Status == "success"
20
+ self.token = response.CreateSessionResult.Token
21
+ self.secure_token = response.CreateSessionResult.SecureToken
22
+ self.token_issued_at = Time.now()
23
+ self.token_duration = response.CreateSessionResult.TokenDurationMinutes
24
+ end
25
+ response
26
+ end
27
+
28
+ def renew_token(options={})
29
+ if self.secure_token
30
+ options = {
31
+ :RequestHeader => {
32
+ :Token => self.secure_token
33
+ },
34
+ :RenewSessionRequestBody => {
35
+ :SystemId => GettyConnect.system_id,
36
+ :SystemPassword => GettyConnect.system_password
37
+ }
38
+ }.merge options
39
+ else
40
+ "Token must be first requested."
41
+ end
42
+
43
+ response = post(@renew_session_endpoint, options)
44
+ if response.ResponseHeader.Status == "success"
45
+ self.token_renewed_at = Time.now()
46
+ end
47
+ response
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ require 'getty_connect/connection'
2
+ require 'getty_connect/request'
3
+
4
+ require 'getty_connect/client/session'
5
+ require 'getty_connect/client/image'
6
+
7
+ module GettyConnect
8
+ class Client
9
+ attr_accessor(*Config::VALID_OPTIONS_KEYS)
10
+ attr_accessor :secure_token, :token, :token_issued_at, :token_renewed_at, :token_duration
11
+
12
+ def initialize(options={})
13
+ options = GettyConnect.options.merge(options)
14
+ Config::VALID_OPTIONS_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ include GettyConnect::Connection
20
+ include GettyConnect::Request
21
+
22
+ include GettyConnect::Client::Session
23
+ include GettyConnect::Client::Image
24
+ end
25
+ end
@@ -0,0 +1,90 @@
1
+ require 'faraday'
2
+ require 'getty_connect/version'
3
+
4
+ module GettyConnect
5
+ module Config
6
+
7
+ # GettyConnect endpoints
8
+ # https://api.gettyimages.com/apis
9
+
10
+ DEFAULT_API_VERSION = "v1"
11
+
12
+ DEFAULT_CREATE_SESSION_ENDPOINT =
13
+ "#{DEFAULT_API_VERSION}/session/CreateSession"
14
+ DEFAULT_RENEW_SESSION_ENDPOINT =
15
+ "#{DEFAULT_API_VERSION}/session/RenewSession"
16
+ DEFAULT_SEARCH_ENDPOINT = "#{DEFAULT_API_VERSION}/search/SearchForImages"
17
+ DEFAULT_IMAGE_DETAILS_ENDPOINT =
18
+ "#{DEFAULT_API_VERSION}/search/GetImageDetails"
19
+ DEFAULT_DOWNLOAD_AUTH_ENDPOINT =
20
+ "#{DEFAULT_API_VERSION}/download/GetImageDownloadAuthorizations"
21
+ DEFAULT_DOWNLOAD_REQUEST_ENDPOINT =
22
+ "#{DEFAULT_API_VERSION}/download/CreateDownloadRequest"
23
+ DEFAULT_DOWNLOAD_LARGEST_ENDPOINT =
24
+ "#{DEFAULT_API_VERSION}/download/GetLargestImageDownloadAuthorizations"
25
+
26
+ DEFAULT_USER_AGENT = "GettyConnect Ruby Gem #{GettyConnect::VERSION}"
27
+
28
+ # Authentication
29
+ DEFAULT_SYSTEM_ID = "3131" # nil
30
+ DEFAULT_SYSTEM_PASSWORD =
31
+ "I7zZycelG4VxeG0lPJdVZCZwDI7zn4rUIJwUd7V/V+0=" # nil
32
+ DEFAULT_API_USERNAME = "avos_api" # nil
33
+ DEFAULT_API_PASSWORD = "S3p4PmAtkuppoKT" # nil
34
+
35
+ # An array of valid keys in the options hash
36
+ # when configuring a {GettyConnect::Client}
37
+ VALID_OPTIONS_KEYS = [
38
+ :create_session_endpoint,
39
+ :renew_session_endpoint,
40
+ :search_endpoint,
41
+ :image_details_endpoint,
42
+ :download_auth_endpoint,
43
+ :download_request_endpoint,
44
+ :download_largest_endpoint,
45
+ :user_agent,
46
+ :system_id,
47
+ :system_password,
48
+ :api_username,
49
+ :api_password,
50
+ :api_version
51
+ ]
52
+
53
+ attr_accessor(*VALID_OPTIONS_KEYS)
54
+
55
+ # When this module is extended, set all configuration options
56
+ # to their default values
57
+ def self.extended(base)
58
+ base.reset
59
+ end
60
+
61
+ # Convenience method to allow configuration options to be set in a block
62
+ def configure
63
+ yield self
64
+ self
65
+ end
66
+
67
+ def options
68
+ VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
69
+ end
70
+
71
+ # Reset all configuration options to defaults
72
+ def reset
73
+ self.create_session_endpoint = DEFAULT_CREATE_SESSION_ENDPOINT
74
+ self.renew_session_endpoint = DEFAULT_RENEW_SESSION_ENDPOINT
75
+ self.search_endpoint = DEFAULT_SEARCH_ENDPOINT
76
+ self.image_details_endpoint = DEFAULT_IMAGE_DETAILS_ENDPOINT
77
+ self.download_auth_endpoint = DEFAULT_DOWNLOAD_AUTH_ENDPOINT
78
+ self.download_request_endpoint = DEFAULT_DOWNLOAD_REQUEST_ENDPOINT
79
+ self.download_largest_endpoint = DEFAULT_DOWNLOAD_LARGEST_ENDPOINT
80
+ self.user_agent = DEFAULT_USER_AGENT
81
+ self.system_id = DEFAULT_SYSTEM_ID
82
+ self.system_password = DEFAULT_SYSTEM_PASSWORD
83
+ self.api_username = DEFAULT_API_USERNAME
84
+ self.api_password = DEFAULT_API_PASSWORD
85
+ self.api_version = DEFAULT_API_VERSION
86
+ self
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,28 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/response/raise_getty_connect_error'
3
+
4
+ module GettyConnect
5
+ module Connection
6
+ private
7
+
8
+ def connection
9
+ url = "https://connect.gettyimages.com"
10
+
11
+ options = {
12
+ :ssl => { :verify => false },
13
+ :url => url
14
+ }
15
+
16
+ connection = Faraday.new(options) do |builder|
17
+ builder.request :json
18
+ builder.use Faraday::Response::RaiseGettyConnectError
19
+ builder.use FaradayMiddleware::Mashify
20
+ builder.use FaradayMiddleware::ParseJson
21
+ builder.adapter(Faraday.default_adapter)
22
+ end
23
+
24
+ connection
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ module GettyConnect
2
+ # Custom error class for rescuing from all Getty Connect errors
3
+ class Error < StandardError; end
4
+
5
+ # Raised when Getty Connect returns a 400 HTTP status code
6
+ class BadRequest < Error; end
7
+
8
+ # Raised when Getty Connect returns a 401 HTTP status code
9
+ class Unauthorized < Error; end
10
+
11
+ # Raised when Getty Connect returns a 403 HTTP status code
12
+ class Forbidden < Error; end
13
+
14
+ # Raised when Getty Connect returns a 404 HTTP status code
15
+ class NotFound < Error; end
16
+
17
+ # Raised when Getty Connect returns a 406 HTTP status code
18
+ class NotAcceptable < Error; end
19
+
20
+ # Raised when Getty Connect returns a 422 HTTP status code
21
+ class UnprocessableEntity < Error; end
22
+
23
+ # Raised when Getty Connect returns a 500 HTTP status code
24
+ class InternalServerError < Error; end
25
+
26
+ # Raised when Getty Connect returns a 501 HTTP status code
27
+ class NotImplemented < Error; end
28
+
29
+ # Raised when Getty Connect returns a 502 HTTP status code
30
+ class BadGateway < Error; end
31
+
32
+ # Raised when Getty Connect returns a 503 HTTP status code
33
+ class ServiceUnavailable < Error; end
34
+ end
@@ -0,0 +1,43 @@
1
+ require 'multi_json'
2
+
3
+ module GettyConnect
4
+ module Request
5
+ def delete(path, options={})
6
+ request(:delete, path, options)
7
+ end
8
+
9
+ def get(path, options={})
10
+ request(:get, path, options)
11
+ end
12
+
13
+ def patch(path, options={})
14
+ request(:patch, path, options)
15
+ end
16
+
17
+ def post(path, options={})
18
+ request(:post, path, options)
19
+ end
20
+
21
+ def put(path, options={})
22
+ request(:put, path, options)
23
+ end
24
+
25
+ private
26
+
27
+ def request(method, path, options)
28
+ response = connection().send(method) do |request|
29
+ case method
30
+ when :delete, :get
31
+ request.url(path, options)
32
+ when :patch, :post, :put
33
+ request.path = path
34
+ request.body = MultiJson.dump(options) unless options.empty?
35
+ else
36
+ request.body = options unless options.empty?
37
+ end
38
+ end
39
+ response.body
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module GettyConnect
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'getty_connect/config'
2
+ require 'getty_connect/client'
3
+ require 'getty_connect/error'
4
+
5
+ module GettyConnect
6
+ extend Config
7
+ class << self
8
+ # Alias for GettyConnect::Client.new
9
+ #
10
+ # @return [GettyConnect::Client]
11
+ def new(options={})
12
+ GettyConnect::Client.new(options)
13
+ end
14
+
15
+ # Delegate to GettyConnect::Client.new
16
+ def method_missing(method, *args, &block)
17
+ return super unless new.respond_to?(method)
18
+ new.send(method, *args, &block)
19
+ end
20
+
21
+ def respond_to?(method, include_private=false)
22
+ new.respond_to?(method, include_private) || super(method, include_private)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ describe GettyConnect do
5
+ after do
6
+ GettyConnect.reset
7
+ end
8
+
9
+ describe ".respond_to?" do
10
+ it "should be true if method exists" do
11
+ GettyConnect.respond_to?(:new, true).should be_true
12
+ end
13
+ end
14
+
15
+ describe ".new" do
16
+ it "should be a GettyConnect::Client" do
17
+ GettyConnect.new.should be_a GettyConnect::Client
18
+ end
19
+ end
20
+
21
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'getty_connect'
2
+ require 'rspec'
3
+ #require 'webmock/rspec'
4
+
5
+ #def stub_post(endpoint)
6
+ # stub_request(:post, endpoint)
7
+ # puts "endpoint #{endpoint}"
8
+ #end
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: getty_connect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bayard Randel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday_middleware
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.8'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.8'
46
+ - !ruby/object:Gem::Dependency
47
+ name: hashie
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.2'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ - !ruby/object:Gem::Dependency
63
+ name: multi_json
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '2.6'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '2.6'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: json
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: yard
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: '0.8'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: '0.8'
158
+ - !ruby/object:Gem::Dependency
159
+ name: webmock
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: A ruby wrapper for the Getty Images Connect API
175
+ email:
176
+ - kit@avos.com
177
+ executables: []
178
+ extensions: []
179
+ extra_rdoc_files: []
180
+ files:
181
+ - .gitignore
182
+ - .rspec
183
+ - Gemfile
184
+ - Guardfile
185
+ - LICENSE.md
186
+ - README.md
187
+ - Rakefile
188
+ - getty_connect.gemspec
189
+ - lib/faraday/response/raise_getty_connect_error.rb
190
+ - lib/getty_connect.rb
191
+ - lib/getty_connect/client.rb
192
+ - lib/getty_connect/client/image.rb
193
+ - lib/getty_connect/client/session.rb
194
+ - lib/getty_connect/config.rb
195
+ - lib/getty_connect/connection.rb
196
+ - lib/getty_connect/error.rb
197
+ - lib/getty_connect/request.rb
198
+ - lib/getty_connect/version.rb
199
+ - spec/getty_connect_spec.rb
200
+ - spec/helper.rb
201
+ homepage: https://github.com/avos/getty_connect/
202
+ licenses: []
203
+ post_install_message:
204
+ rdoc_options: []
205
+ require_paths:
206
+ - lib
207
+ required_ruby_version: !ruby/object:Gem::Requirement
208
+ none: false
209
+ requirements:
210
+ - - ! '>='
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ segments:
214
+ - 0
215
+ hash: -401614436648419646
216
+ required_rubygems_version: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: 1.3.6
222
+ requirements: []
223
+ rubyforge_project:
224
+ rubygems_version: 1.8.24
225
+ signing_key:
226
+ specification_version: 3
227
+ summary: Getty Images Connect API wrapper
228
+ test_files:
229
+ - spec/getty_connect_spec.rb
230
+ - spec/helper.rb
231
+ has_rdoc: