Skip to content

Commit

Permalink
Update to use test-unit framework for unit tests, update search objec…
Browse files Browse the repository at this point in the history
…t model and add unit tests
  • Loading branch information
ssterli2 committed Mar 20, 2018
1 parent d6c3d9d commit a86fdfe
Show file tree
Hide file tree
Showing 14 changed files with 1,212 additions and 58 deletions.
65 changes: 65 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${file}",
"showDebuggerOutput": true
},
{
"name": "Listen for rdebug-ide",
"type": "Ruby",
"request": "attach",
"cwd": "${workspaceRoot}",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "${workspaceRoot}"
},
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"args": [
"server"
]
},
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": [
"-I",
"${workspaceRoot}"
]
},
{
"name": "RSpec - active spec file only",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rspec",
"args": [
"-I",
"${workspaceRoot}",
"${file}"
]
},
{
"name": "Cucumber",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/cucumber"
}
]
}
4 changes: 2 additions & 2 deletions ConnectSDK/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in ConnectSDK.gemspec
gemspec

gem 'json', '~> 1.8.1'
gem 'rake', '~> 0.9.2.2'
gem 'json'
gem 'rake'
21 changes: 16 additions & 5 deletions ConnectSDK/lib/ConnectSDK.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# for developers.

require_relative "Credentials"
require_relative "SearchRequest"
require_relative "SearchImages"
require_relative "SearchImagesCreative"
require_relative "SearchImagesEditorial"
require_relative "ImagesRequest"
require_relative "DownloadRequest"

Expand All @@ -31,12 +33,21 @@ def get_access_token
return @credentials.get_access_token
end

# Create a search configuration that support image searching
# SearchRequest configured for a image search
def search()
return SearchRequest.new(@credentials.client_key, @credentials.get_access_token)
# Search for both creative and editorial images
def search_images()
return SearchImages.new(@credentials.client_key, @credentials.get_access_token)
end

# Search for creative images
def search_images_creative()
return SearchImagesCreative.new(@credentials.client_key, @credentials.get_access_token)
end

# Search for editorial images
def search_images_editorial()
return SearchImagesEditorial.new(@credentials.client_key, @credentials.get_access_token)
end

# Create a image details configuration that support image details
# == Returns:
# ImagesRequest configured for a image details
Expand Down
2 changes: 1 addition & 1 deletion ConnectSDK/lib/HttpHelper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require_relative 'ConnectSDK/version'

class Connect_Api_Host
API_HOST = "connect.gettyimages.com"
API_HOST = "api.gettyimages.com"
API_BASE_URL = "https://#{API_HOST}"
end

Expand Down
30 changes: 13 additions & 17 deletions ConnectSDK/lib/SearchImages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,28 @@ class SearchImages < RequestBase

CONNECT_ROUTE = "/v3/search/images" # mashery endpoint
@@search_route = CONNECT_ROUTE
QUERY_PARAMS_NAMES = ["phrase","editorial_segments","graphical_styles","license_models","orientations","exclude_nudity","embed_content_only","page","page_size"]
QUERY_PARAMS_NAMES = ["age_of_people","artists","collection_codes","collections_filter_type","color","compositions","embed_content_only","ethnicity","event_ids","exclude_nudity","fields",
"file_types","graphical_styles","keyword_ids","license_models","minimum_size","number_of_people","orientations","page","page_size","phrase","prestige_content_only","product_types",
"sort_order","specific_people"]

QUERY_PARAMS_NAMES.each do |key|
define_method :"with_#{key}" do |value = true|
if value.is_a?(Array)
build_query_params(key, value.join(","))
else
if value.is_a?(Array)
value = value.join(",")
if !key.include? "id"
value.downcase!
end
build_query_params(key, value)
else
if (!key.include? "id") && (value.is_a?(String))
value.downcase!
end
build_query_params(key, value)
end
return self
end
end

# {https://connect.gettyimages.com/swagger/ui/index.html#!/Search/Search_GetCreativeImagesByPhrase Creative Swagger}
# with_graphical_styles
# with_license_models
def creative()
@@search_route = "#{CONNECT_ROUTE}/creative"
return self
end

def editorial()
@@search_route = "#{CONNECT_ROUTE}/editorial"
return self
end

def execute
return @http_helper.get(@@search_route, @query_params)
end
Expand Down
33 changes: 33 additions & 0 deletions ConnectSDK/lib/SearchImagesCreative.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require_relative "RequestBase"

class SearchImagesCreative < RequestBase

CONNECT_ROUTE = "/v3/search/images/creative" # mashery endpoint
@@search_route = CONNECT_ROUTE
QUERY_PARAMS_NAMES = ["age_of_people","artists","collection_codes","collections_filter_type","color","compositions","embed_content_only","ethnicity","exclude_nudity","fields","file_types",
"graphical_styles","keyword_ids","license_models","minimum_size","number_of_people","orientations","page","page_size","phrase","prestige_content_only","product_types",
"sort_order"]

QUERY_PARAMS_NAMES.each do |key|
define_method :"with_#{key}" do |value = true|
if value.is_a?(Array)
value = value.join(",")
if !key.include? "id"
value.downcase!
end
build_query_params(key, value)
else
if (!key.include? "id") && (value.is_a?(String))
value.downcase!
end
build_query_params(key, value)
end
return self
end
end

def execute
return @http_helper.get(@@search_route, @query_params)
end

end
33 changes: 33 additions & 0 deletions ConnectSDK/lib/SearchImagesEditorial.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require_relative "RequestBase"

class SearchImagesEditorial < RequestBase

CONNECT_ROUTE = "/v3/search/images/editorial" # mashery endpoint
@@search_route = CONNECT_ROUTE
QUERY_PARAMS_NAMES = ["age_of_people","artists","collection_codes","collections_filter_type","compositions","editorial_segments","embed_content_only","end_date","entity_uris","ethnicity",
"event_ids","exclude_nudity","fields","file_types","graphical_styles","keyword_ids","minimum_quality_rank","minimum_size","number_of_people","orientations","page","page_size","phrase",
"product_types","sort_order","specific_people","start_date"]

QUERY_PARAMS_NAMES.each do |key|
define_method :"with_#{key}" do |value = true|
if value.is_a?(Array)
value = value.join(",")
if !key.include? "id"
value.downcase!
end
build_query_params(key, value)
else
if (!key.include? "id") && (value.is_a?(String))
value.downcase!
end
build_query_params(key, value)
end
return self
end
end

def execute
return @http_helper.get(@@search_route, @query_params)
end

end
15 changes: 0 additions & 15 deletions ConnectSDK/lib/SearchRequest.rb

This file was deleted.

12 changes: 8 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
source 'https://rubygems.org'

gem 'ConnectSDK', '~> 1.0.1.Beta'
gem 'json', '~> 1.8.1'
gem 'cucumber', '~> 1.3.17'
gem 'rake', '~> 10.4.2'
gem 'ConnectSDK'
gem 'rake'
gem 'json'
gem 'cucumber'
gem 'gherkin'
gem 'test-unit'
gem 'mockserver-client'
gem 'webmock'
115 changes: 101 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,111 @@ GEM
remote: https://rubygems.org/
specs:
ConnectSDK (1.0.2.Beta)
builder (3.2.2)
cucumber (1.3.17)
activesupport (4.2.10)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
backports (3.11.1)
builder (3.2.3)
colorize (0.8.1)
concurrent-ruby (1.0.5)
crack (0.4.3)
safe_yaml (~> 1.0.0)
cucumber (3.1.0)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12)
cucumber-core (~> 3.1.0)
cucumber-expressions (~> 5.0.4)
cucumber-wire (~> 0.0.1)
diff-lcs (~> 1.3)
gherkin (~> 5.0)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.1)
diff-lcs (1.2.5)
gherkin (2.12.2-x86-mingw32)
multi_json (~> 1.3)
json (1.8.1)
multi_json (1.10.1)
multi_test (0.1.1)
multi_test (>= 0.1.2)
cucumber-core (3.1.0)
backports (>= 3.8.0)
cucumber-tag_expressions (~> 1.1.0)
gherkin (>= 5.0.0)
cucumber-expressions (5.0.13)
cucumber-tag_expressions (1.1.1)
cucumber-wire (0.0.1)
diff-lcs (1.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
ffi (1.9.23-x64-mingw32)
ffi (1.9.23-x86-mingw32)
gherkin (5.0.0)
hashdiff (0.3.7)
hashie (3.5.7)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json (1.8.6)
little-plugger (1.1.4)
logging (1.8.2)
little-plugger (>= 1.1.3)
multi_json (>= 1.8.4)
logging_factory (0.0.3)
logging (~> 1.8.1)
preconditions (~> 0.3.0)
mime-types (2.99.3)
minitest (5.11.3)
mockserver-client (1.0.7)
activesupport (~> 4.1)
colorize (~> 0.7)
hashie (~> 3.0)
json (~> 1.8)
logging_factory (~> 0.0.2)
rest-client (~> 1.7)
thor (~> 0.19)
multi_json (1.13.1)
multi_test (0.1.2)
netrc (0.11.0)
power_assert (1.1.1)
preconditions (0.3.0)
public_suffix (3.0.2)
rake (12.3.0)
rest-client (1.8.0-x64-mingw32)
ffi (~> 1.9)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rest-client (1.8.0-x86-mingw32)
ffi (~> 1.9)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
safe_yaml (1.0.4)
test-unit (3.2.7)
power_assert
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5-x64-mingw32)
unf_ext (0.0.7.5-x86-mingw32)
webmock (3.3.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff

PLATFORMS
x64-mingw32
x86-mingw32

DEPENDENCIES
ConnectSDK (~> 1.0.1.Beta)
cucumber (~> 1.3.17)
json (~> 1.8.1)
ConnectSDK
cucumber
gherkin
json
mockserver-client
rake
test-unit
webmock

BUNDLED WITH
1.16.1
Empty file added features/support/env.rb
Empty file.
Loading

0 comments on commit a86fdfe

Please sign in to comment.