From 1d7f62d02e0793dcb99d1387be7233b0b4e2889c Mon Sep 17 00:00:00 2001 From: Nick Adams Date: Wed, 16 Nov 2022 15:07:57 -0500 Subject: [PATCH 1/6] Updating Faraday Gem for Compatibility with Ruby 3 This commit updates the Faraday gem for compatibility for Ruby 3. For now I've pinned it to the latest version. This commit also updates the author and email to match the current owner of the Gem (with all due respect to Rune who created it). I also delete the .travis.yaml file because we no longer use that service. --- .travis.yml | 11 ----------- Gemfile.lock | 40 +++++++++++++++++++++------------------- atlas-api.gemspec | 6 +++--- 3 files changed, 24 insertions(+), 33 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fc8dd63..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: ruby -rvm: - - 1.9.3 - - 2.0.0 -notifications: - campfire: - rooms: - - secure: "nay0jqTm7naZ7JKI6q9uG9Au4DfnRP94q1uaiJ+YW9jdV2ygzaB7GmI7fILo7uwCuoy0QIN8KQ/3PhdVeDoSweULs5PaoC7qlO+IX8scBcDMzsykY9JuTiO9cuSQeV0OFwKrStgTsX5a8lt7ryCd+zQXaHdo+FO6mnjy44YXoyI=" - template: - - ":construction_worker: %{repository} (%{commit}) : %{message} %{foo} " - - "Build details: %{build_url}" diff --git a/Gemfile.lock b/Gemfile.lock index ff54f50..b43a994 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,39 +2,41 @@ PATH remote: . specs: atlas-api (0.1.2) - faraday (~> 0.15.4) + faraday (~> 2.7.0) hashie (~> 3.6.0) GEM remote: https://rubygems.org/ specs: - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) crack (0.4.5) rexml diff-lcs (1.5.0) - faraday (0.15.4) - multipart-post (>= 1.2, < 3) + faraday (2.7.0) + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-net_http (3.0.2) hashdiff (1.0.1) hashie (3.6.0) - multipart-post (2.1.1) - public_suffix (4.0.7) + public_suffix (5.0.0) rake (13.0.6) rexml (3.2.5) - rspec (3.11.0) - rspec-core (~> 3.11.0) - rspec-expectations (~> 3.11.0) - rspec-mocks (~> 3.11.0) - rspec-core (3.11.0) - rspec-support (~> 3.11.0) - rspec-expectations (3.11.0) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-mocks (3.11.1) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-support (3.11.0) - webmock (3.14.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + ruby2_keywords (0.0.5) + webmock (3.18.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) diff --git a/atlas-api.gemspec b/atlas-api.gemspec index d32f6fa..9279a14 100644 --- a/atlas-api.gemspec +++ b/atlas-api.gemspec @@ -6,8 +6,8 @@ require 'atlas-api/version' Gem::Specification.new do |gem| gem.name = "atlas-api" gem.version = Atlas::Api::VERSION - gem.authors = ["Rune Skjoldborg Madsen"] - gem.email = ["rune@runemadsen.com"] + gem.authors = ["O'Reilly Media Tools Team"] + gem.email = ["toolsreq@oreilly.com"] gem.description = "Gem to interact with the O'Reilly Media Atlas API" gem.summary = "Gem to interact with the O'Reilly Media Atlas API" gem.homepage = "" @@ -17,7 +17,7 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] - gem.add_dependency "faraday", "~> 0.15.4" + gem.add_dependency "faraday", "~> 2.7.0" gem.add_dependency "hashie", "~> 3.6.0" gem.add_development_dependency "rspec" gem.add_development_dependency "webmock" From ff2f3d940d8431f1e4a5a2f6243975544f4daec8 Mon Sep 17 00:00:00 2001 From: Nick Adams Date: Wed, 16 Nov 2022 15:18:44 -0500 Subject: [PATCH 2/6] Removing Deprecated URI Encoding Method URI.encode was removed in Ruby 3, so I removed it. The percent encoding is now handled by Faraday. I also changed the stub URLs from Rune's website to Atlas to better match reality. --- lib/atlas-api/client.rb | 2 +- spec/atlas-api/client_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/atlas-api/client.rb b/lib/atlas-api/client.rb index 4bf2ee3..ea07366 100644 --- a/lib/atlas-api/client.rb +++ b/lib/atlas-api/client.rb @@ -74,7 +74,7 @@ def agent private def request(method, path, options) - @last_response = response = agent.send(method, URI.encode(path), options) + @last_response = response = agent.send(method, path, options) Hashie::Mash.new(JSON.parse(response.body)) end diff --git a/spec/atlas-api/client_spec.rb b/spec/atlas-api/client_spec.rb index adca5b9..b108404 100644 --- a/spec/atlas-api/client_spec.rb +++ b/spec/atlas-api/client_spec.rb @@ -8,7 +8,7 @@ def stub_request_with_token(method, path, body, query = {}) before(:each) do @token = "abcdefg" - @endpoint = "http://www.runemadsen.com" + @endpoint = "http://atlas.oreilly.com" @body = { message: "Success!" } @client = Atlas::Api::Client.new( auth_token: @token, @@ -32,7 +32,7 @@ def stub_request_with_token(method, path, body, query = {}) end it "should combine paths from endpoint and path" do - @endpoint = "http://www.runemadsen.com/api" + @endpoint = "http://atlas.oreilly.com/api" client = Atlas::Api::Client.new( auth_token: @token, api_endpoint: @endpoint From 55147213e0a98ccbb45e9bab064346501450724f Mon Sep 17 00:00:00 2001 From: Nick Adams Date: Wed, 16 Nov 2022 15:50:25 -0500 Subject: [PATCH 3/6] Updating to version 0.2.0 --- Gemfile.lock | 2 +- lib/atlas-api/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b43a994..ad510ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - atlas-api (0.1.2) + atlas-api (0.2.0) faraday (~> 2.7.0) hashie (~> 3.6.0) diff --git a/lib/atlas-api/version.rb b/lib/atlas-api/version.rb index 420659a..c6e73cc 100644 --- a/lib/atlas-api/version.rb +++ b/lib/atlas-api/version.rb @@ -1,5 +1,5 @@ module Atlas module Api - VERSION = "0.1.2" + VERSION = "0.2.0" end end From 7e1e8ab3b8fa62f56252aa9fdd21f033d2e5afb0 Mon Sep 17 00:00:00 2001 From: Nick Adams Date: Wed, 16 Nov 2022 15:50:45 -0500 Subject: [PATCH 4/6] Adding GitHub Actions CI This commit adds a YAML configuration file for automatically running the tests on PRs and pushes. It's set up to run the tests on both Ruby 2.7, 3.0, 3.1, and 3.2 and more can be added as needed. --- .github/workflows/ci.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..59fcf7c --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,30 @@ + +name: CI +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + tests: + name: Run test suite + runs-on: ubuntu-latest + + strategy: + matrix: + ruby-version: ['3.2', '3.1', '3.0', '2.7'] + + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + - name: Install dependencies + run: bundle install + - name: Run tests + run: bundle exec rspec spec/atlas-api/client_spec.rb \ No newline at end of file From ca4ab9c9521df3015a516546d1bae356672bb350 Mon Sep 17 00:00:00 2001 From: Nick Adams Date: Thu, 17 Nov 2022 16:14:09 -0500 Subject: [PATCH 5/6] Adding Test Coverage and Removing Unused HTTP Method This commit adds the simplecov gem to measure test coverage. In running the test coverage, I realized that the delete method was not covered by the tests. We don't support sending delete requests through this API so I removed the method. --- .gitignore | 1 + Gemfile | 1 + Gemfile.lock | 8 ++++++++ lib/atlas-api/client.rb | 4 ---- spec/spec_helper.rb | 2 ++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 735b4d5..14b512d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ spec/reports test/tmp test/version_tmp tmp +coverage diff --git a/Gemfile b/Gemfile index 64df509..8e04d61 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,6 @@ source 'https://rubygems.org' gem "rake", "~> 13.0.1" +gem "simplecov" gemspec \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index ad510ba..ec23ad5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,6 +13,7 @@ GEM crack (0.4.5) rexml diff-lcs (1.5.0) + docile (1.4.0) faraday (2.7.0) faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) @@ -36,6 +37,12 @@ GEM rspec-support (~> 3.12.0) rspec-support (3.12.0) ruby2_keywords (0.0.5) + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) webmock (3.18.1) addressable (>= 2.8.0) crack (>= 0.3.2) @@ -48,6 +55,7 @@ DEPENDENCIES atlas-api! rake (~> 13.0.1) rspec + simplecov webmock BUNDLED WITH diff --git a/lib/atlas-api/client.rb b/lib/atlas-api/client.rb index ea07366..0ae0e4e 100644 --- a/lib/atlas-api/client.rb +++ b/lib/atlas-api/client.rb @@ -62,10 +62,6 @@ def put(path, options = {}) request :put, path, options end - def delete(path, options = {}) - request :delete, path, options - end - def agent @agent ||= Faraday.new(url: @api_endpoint, params: { auth_token: @auth_token }) @agent diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 679b3a0..54fef43 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,2 +1,4 @@ +require 'simplecov' +SimpleCov.start require 'atlas-api' require 'webmock/rspec' \ No newline at end of file From af3ea289c45a7a20c633771ff47367d07a73407b Mon Sep 17 00:00:00 2001 From: Nick Adams Date: Thu, 17 Nov 2022 16:22:29 -0500 Subject: [PATCH 6/6] Changing master to main in README and tests --- README.md | 2 +- spec/atlas-api/client_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fbacd12..26d4ac0 100644 --- a/README.md +++ b/README.md @@ -21,5 +21,5 @@ $ atlas build ATLAS_TOKEN PROJECT FORMATS BRANCH A real world example of this would look something like this: ```bash -$ atlas build abcdefg oreillymedia/atlas_book_skeleton pdf,epub,html master +$ atlas build abcdefg oreillymedia/atlas_book_skeleton pdf,epub,html main ``` \ No newline at end of file diff --git a/spec/atlas-api/client_spec.rb b/spec/atlas-api/client_spec.rb index b108404..96059da 100644 --- a/spec/atlas-api/client_spec.rb +++ b/spec/atlas-api/client_spec.rb @@ -54,7 +54,7 @@ def stub_request_with_token(method, path, body, query = {}) query = { :project => "atlasservers/basic-sample", :formats => "pdf,html", - :branch => "master", + :branch => "main", :pingback_url => "http://www.someurl.com" } @@ -115,7 +115,7 @@ def stub_request_with_token(method, path, body, query = {}) query = { :project => "atlasservers/basic-sample", :formats => "pdf,html", - :branch => "master", + :branch => "main", :pingback_url => "http://www.someurl.com" } stub = stub_request_with_token(:post, "builds", @body.to_json, query)