From d0ce98b4af1d135fa2a7f2b417ff1903c40bb349 Mon Sep 17 00:00:00 2001 From: Mark Pitman Date: Fri, 19 May 2023 16:05:48 -0700 Subject: [PATCH] Make auth requests with new hostname New hostname for OAuth requests is authentication.gettyimages.com Add rexml to Gemfile to make build work on Ruby 3.x --- Gemfile | 1 + Gemfile.lock | 4 +++- Makefile | 2 +- README.md | 2 +- lib/Credentials.rb | 2 +- lib/HttpHelper.rb | 2 ++ unit_tests/CustomParamHeaderTests.rb | 2 +- unit_tests/CustomRequestsTests.rb | 2 +- unit_tests/DownloadImagesTests.rb | 2 +- unit_tests/DownloadVideosTests.rb | 2 +- unit_tests/ImagesTests.rb | 2 +- unit_tests/SearchImagesCreativeTests.rb | 2 +- unit_tests/SearchImagesEditorialTests.rb | 2 +- unit_tests/SearchImagesTests.rb | 2 +- unit_tests/SearchVideosCreativeTests.rb | 2 +- unit_tests/SearchVideosEditorialTests.rb | 2 +- unit_tests/SearchVideosTests.rb | 2 +- unit_tests/VideosTests.rb | 2 +- 18 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 2ba04f5..3e17f32 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,4 @@ gem 'rake' gem 'json' gem 'test-unit' gem 'webmock' +gem 'rexml' diff --git a/Gemfile.lock b/Gemfile.lock index 62d834b..74202be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,6 +10,7 @@ GEM power_assert (1.1.6) public_suffix (4.0.6) rake (13.0.1) + rexml (3.2.5) safe_yaml (1.0.5) test-unit (3.3.5) power_assert @@ -27,8 +28,9 @@ PLATFORMS DEPENDENCIES json rake + rexml test-unit webmock BUNDLED WITH - 2.1.4 + 2.2.22 diff --git a/Makefile b/Makefile index 0e7dc00..2c8797e 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ GID := $(shell id -g) build: bundle config set --local path 'vendor/bundle' - bundle install --path vendor/bundle + bundle install bundle exec rake gem build gettyimages-api.gemspec diff --git a/README.md b/README.md index aeaef60..b3c6966 100755 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ _Source code is only needed if you would like to contribute to the project. Othe ### Requirements -- Ruby version >= 2.5 +- Ruby version >= 3.0 - [Bundler](http://bundler.io) Install bundler and all dependencies diff --git a/lib/Credentials.rb b/lib/Credentials.rb index b800eb1..bce31ae 100644 --- a/lib/Credentials.rb +++ b/lib/Credentials.rb @@ -21,7 +21,7 @@ def initialize(args) end def get_uri(path) - return URI.parse "#{Api_Host::API_BASE_URL}#{path}" + return URI.parse "#{Api_Host::AUTH_BASE_URL}#{path}" end def token_has_expired() diff --git a/lib/HttpHelper.rb b/lib/HttpHelper.rb index 187fe95..81b199c 100644 --- a/lib/HttpHelper.rb +++ b/lib/HttpHelper.rb @@ -7,6 +7,8 @@ class Api_Host API_HOST = "api.gettyimages.com" API_BASE_URL = "https://#{API_HOST}" + AUTH_HOST = "authentication.gettyimages.com" + AUTH_BASE_URL = "https://#{AUTH_HOST}" end class HttpHelper diff --git a/unit_tests/CustomParamHeaderTests.rb b/unit_tests/CustomParamHeaderTests.rb index b05b3f9..e4bfc2b 100644 --- a/unit_tests/CustomParamHeaderTests.rb +++ b/unit_tests/CustomParamHeaderTests.rb @@ -5,7 +5,7 @@ class CustomParamHeaderTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/CustomRequestsTests.rb b/unit_tests/CustomRequestsTests.rb index 1db6a32..670951e 100644 --- a/unit_tests/CustomRequestsTests.rb +++ b/unit_tests/CustomRequestsTests.rb @@ -5,7 +5,7 @@ class CustomRequestsTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/DownloadImagesTests.rb b/unit_tests/DownloadImagesTests.rb index d39b5a3..94760b8 100644 --- a/unit_tests/DownloadImagesTests.rb +++ b/unit_tests/DownloadImagesTests.rb @@ -5,7 +5,7 @@ class DownloadImagesTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/DownloadVideosTests.rb b/unit_tests/DownloadVideosTests.rb index db7983b..6731a27 100644 --- a/unit_tests/DownloadVideosTests.rb +++ b/unit_tests/DownloadVideosTests.rb @@ -5,7 +5,7 @@ class DownloadVideosTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/ImagesTests.rb b/unit_tests/ImagesTests.rb index 2e03dc6..49b1695 100644 --- a/unit_tests/ImagesTests.rb +++ b/unit_tests/ImagesTests.rb @@ -5,7 +5,7 @@ class ImagesTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/SearchImagesCreativeTests.rb b/unit_tests/SearchImagesCreativeTests.rb index 7a03496..3101345 100644 --- a/unit_tests/SearchImagesCreativeTests.rb +++ b/unit_tests/SearchImagesCreativeTests.rb @@ -5,7 +5,7 @@ class SearchImagesCreativeTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/SearchImagesEditorialTests.rb b/unit_tests/SearchImagesEditorialTests.rb index 044951d..f6a0188 100644 --- a/unit_tests/SearchImagesEditorialTests.rb +++ b/unit_tests/SearchImagesEditorialTests.rb @@ -5,7 +5,7 @@ class SearchImagesEditorialTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/SearchImagesTests.rb b/unit_tests/SearchImagesTests.rb index 75ffa34..2dcb540 100644 --- a/unit_tests/SearchImagesTests.rb +++ b/unit_tests/SearchImagesTests.rb @@ -6,7 +6,7 @@ class SearchImagesTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/SearchVideosCreativeTests.rb b/unit_tests/SearchVideosCreativeTests.rb index ee8d553..e12e0bd 100644 --- a/unit_tests/SearchVideosCreativeTests.rb +++ b/unit_tests/SearchVideosCreativeTests.rb @@ -5,7 +5,7 @@ class SearchVideosCreativeTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/SearchVideosEditorialTests.rb b/unit_tests/SearchVideosEditorialTests.rb index cf148dd..75b455c 100644 --- a/unit_tests/SearchVideosEditorialTests.rb +++ b/unit_tests/SearchVideosEditorialTests.rb @@ -5,7 +5,7 @@ class SearchVideosEditorialTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/SearchVideosTests.rb b/unit_tests/SearchVideosTests.rb index 2f08a00..63cdf74 100644 --- a/unit_tests/SearchVideosTests.rb +++ b/unit_tests/SearchVideosTests.rb @@ -5,7 +5,7 @@ class SearchVideosTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end diff --git a/unit_tests/VideosTests.rb b/unit_tests/VideosTests.rb index 6ef1e6f..b76cb83 100644 --- a/unit_tests/VideosTests.rb +++ b/unit_tests/VideosTests.rb @@ -5,7 +5,7 @@ class VideosTests < Test::Unit::TestCase def setup - stub_request(:post, "https://api.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) + stub_request(:post, "https://authentication.gettyimages.com/oauth2/token").with(body: {"client_id"=>"api key", "client_secret"=>"api secret", "grant_type"=>"client_credentials"}) .to_return(status: 200, body: '{"access_token": "client_credentials_access_token", "token_types": "Bearer", "expires_in": "1800"}') end