Skip to content

Commit

Permalink
raise an error when using deprecated 'page' param (#145)
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Vieira <bruno@chartmogul.com>
  • Loading branch information
kmossco authored Nov 2, 2023
1 parent acc3d14 commit 8403c33
Show file tree
Hide file tree
Showing 35 changed files with 68 additions and 499 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [2.6, 2.7, 3.0, 3.1, 3.2]
ruby-version: [2.7, 3.0, 3.1, 3.2]
steps:
- uses: actions/checkout@v2
- name: Set up Ruby ${{ matrix.ruby-version }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Or install it yourself as:
$ gem install chartmogul-ruby

### Supported Ruby Versions
This gem supports Ruby 2.3 and above.
This gem supports Ruby 2.7 and above.

## Configuration

Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# chartmogul-ruby Change Log

## Version 4.0.0 - November 1 2023
- Remove support for old pagination using `page` parameter.
- Drop support for Ruby versions below 2.7.

## Version 3.3.1 - October 27 2023
- Add support for cursor based pagination to `.all` endpoints.
- Add `.next` pagination method for all supported cursor based endpoints.
Expand Down
2 changes: 1 addition & 1 deletion chartmogul-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
spec.description = 'Official Ruby client for ChartMogul\'s API'
spec.homepage = 'https://github.com/chartmogul/chartmogul-ruby'
spec.license = 'MIT'
spec.required_ruby_version = '>= 2.3'
spec.required_ruby_version = '>= 2.7'

spec.post_install_message = %q{
Starting October 29 2021, we are updating our developer libraries to support the enhanced API Access Management. Please use the same API Key for both API Token and Secret Key.
Expand Down
1 change: 1 addition & 0 deletions lib/chartmogul.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require 'chartmogul/errors/schema_invalid_error'
require 'chartmogul/errors/server_error'
require 'chartmogul/errors/unauthorized_error'
require 'chartmogul/errors/deprecated_parameter_error'

require 'chartmogul/config_attributes'
require 'chartmogul/configuration'
Expand Down
6 changes: 6 additions & 0 deletions lib/chartmogul/errors/deprecated_parameter_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module ChartMogul
class DeprecatedParameterError < ChartMogulError
end
end
7 changes: 6 additions & 1 deletion lib/chartmogul/resource_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ResourcePath

class RequiredParameterMissing < StandardError; end

DEPRECATED_PARAMETER = 'page'

def initialize(path)
@path = path
@named_params = path.scan(/:\w+/).each_with_object({}) do |named_param, hash|
Expand All @@ -22,7 +24,6 @@ def apply(params = {})

# For path = '/hello/:hello_id/say' & params = { hello_id: 1, search: 'cat' }
# it will return '/hello/1/say?search=cat'

def apply_with_get_params(params = {})
base_path = apply_named_params(params)
get_params = params.reject { |param_name| named_params.values.include?(param_name) }
Expand All @@ -33,6 +34,10 @@ def apply_with_get_params(params = {})
private

def apply_named_params(params)
if params.keys.map(&:to_s).include?(DEPRECATED_PARAMETER)
raise(ChartMogul::DeprecatedParameterError, "#{DEPRECATED_PARAMETER} is deprecated.")
end

path.dup.tap do |path|
named_params.each do |named_param, param_key|
unless params.key?(param_key)
Expand Down
2 changes: 1 addition & 1 deletion lib/chartmogul/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ChartMogul
VERSION = '3.3.1'
VERSION = '4.0.0'
end
17 changes: 4 additions & 13 deletions spec/chartmogul/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
expect(subject).to have_attributes({ uuid: nil })
end

# We can't use `.except` here because we still support Ruby 2.6 and 2.7
it 'sets the writeable properties correctly' do
expect(subject).to have_attributes(attrs.reject { |k, _| k == :uuid })
end
Expand Down Expand Up @@ -118,20 +117,12 @@
end

context 'with old pagination' do
it 'paginates correctly' do
contacts = ChartMogul::Contacts.all(per_page: 1, page: 3)
expect(contacts.size).to eq(1)
expect(contacts).to have_attributes(
cursor: cursor,
has_more: true
)
expect(contacts.first).to have_attributes(
uuid: 'con_36399f04-7686-11ee-86f6-8727560009c2'
)
end
let(:get_resources) { described_class.all(per_page: 1, page: 3) }

it_behaves_like 'raises deprecated param error'
end

context 'with new pagination' do
context 'with pagination' do
let(:first_cursor) do
'MjAyMy0xMC0yOVQxODowODo1MC4yNDQ4NzUwMDBaJmNvbl8z'\
'NjM5OWYwNC03Njg2LTExZWUtODZmNi04NzI3NTYwMDA5YzI='
Expand Down
15 changes: 5 additions & 10 deletions spec/chartmogul/customer_invoices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,17 @@
end

context 'with old pagination' do
it 'paginates correctly' do
invoices = ChartMogul::CustomerInvoices.all(
let(:get_resources) do
described_class.all(
'cus_23551596-2c7e-11ee-9ea1-2bfe193640c0',
per_page: 1, page: 1
)
expect(invoices.size).to eq(1)
expect(invoices).to have_attributes(
cursor: nil, current_page: 1, total_pages: 1, has_more: nil
)
expect(invoices.first).to have_attributes(
uuid: 'inv_d54e1b96-15a6-4491-979a-595530b1a55d'
)
end

it_behaves_like 'raises deprecated param error'
end

context 'with new pagination' do
context 'with pagination' do
let(:cursor) do
'MjAyMy0xMC0zMFQwMjo1ODo0MS4yNzkyNzIwMDBaJmludl8'\
'4YWI3NDYxNC00ZTYyLTQ5ZjYtYjRiMy1mNzc5MTA5ZTUwZDA='
Expand Down
27 changes: 9 additions & 18 deletions spec/chartmogul/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,20 @@
end

context 'with old pagination' do
it 'paginates correctly' do
customers = ChartMogul::Customers.all(per_page: 1, page: 3)
expect(customers.size).to eq(1)
expect(customers).to have_attributes(
cursor: nil, has_more: true,
page: 3, per_page: 1
)
expect(customers.first).to have_attributes(
uuid: 'cus_23551596-2c7e-11ee-9ea1-2bfe193640c0'
)
context 'when listing customers using #all' do
let(:get_resources) { ChartMogul::Customers.all(per_page: 1, page: 3) }

it_behaves_like 'raises deprecated param error'
end

it 'paginates the /search endpoint correctly' do
customers = described_class.search('gavin@example.com', page: 1, per_page: 1)
expect(customers.first.email).to eq('gavin@example.com')
expect(customers).to have_attributes(
cursor: nil, has_more: false,
page: 1, per_page: 1
)
context 'when listing customers using #search' do
let(:get_resources) { described_class.search('gavin@example.com', page: 1, per_page: 1) }

it_behaves_like 'raises deprecated param error'
end
end

context 'with new pagination' do
context 'with pagination' do
let(:first_cursor) do
'MjAxNi0wMS0wMVQxMjowMDowMC4wMDAwMDAwMDBaJjExNDE2NzQ1MA=='
end
Expand Down
15 changes: 4 additions & 11 deletions spec/chartmogul/invoice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,12 @@
end

context 'with old pagination' do
it 'paginates correctly' do
invoices = described_class.all(per_page: 1, page: 2)
expect(invoices.size).to eq(1)
expect(invoices).to have_attributes(
cursor: nil, current_page: 2, total_pages: 27
)
expect(invoices.first).to have_attributes(
uuid: 'inv_8ab74614-4e62-49f6-b4b3-f779109e50d0'
)
end
let(:get_resources) { described_class.all(per_page: 1, page: 2) }

it_behaves_like 'raises deprecated param error'
end

context 'with new pagination' do
context 'with pagination' do
let(:first_cursor) do
'MjAyMy0xMC0zMFQwMzoxNjo1Ni4wMzUwMTcwMDBaJmludl82'\
'ODk3ZDcwMC05OTNlLTQxYjUtYmVlNi1mMTU2OWM5MmNmMWU='
Expand Down
15 changes: 4 additions & 11 deletions spec/chartmogul/plan_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,12 @@
end

context 'with old pagination' do
it 'paginates correctly' do
plan_groups = described_class.all(per_page: 1, page: 3)
expect(plan_groups.size).to eq(1)
expect(plan_groups).to have_attributes(
cursor: nil, current_page: 3, total_pages: 8
)
expect(plan_groups.first).to have_attributes(
uuid: 'plg_cb92ce3a-2196-4b1b-92e1-7bb7c01c359e'
)
end
let(:get_resources) { described_class.all(per_page: 1, page: 3) }

it_behaves_like 'raises deprecated param error'
end

context 'with new pagination' do
context 'with pagination' do
let(:first_cursor) do
'MjAyMy0xMC0zMFQwNDowMTo0NS4yNDYwNzQwMDBaJjIxMTg5'
end
Expand Down
17 changes: 5 additions & 12 deletions spec/chartmogul/plan_groups/plans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@
let(:plan_group_uuid) { 'plg_5f1af63a-ec94-4688-9127-5eb816d05a8f' }

context 'with old pagination' do
it 'paginates correctly' do
plans = described_class.all(
plan_group_uuid,
per_page: 1, page: 1
)
expect(plans.size).to eq(1)
expect(plans).to have_attributes(
cursor: nil, has_more: nil,
current_page: 1, total_pages: 2
)
expect(plans.plans.first.uuid).to eq('pl_e205d990-56e3-013c-13ac-46813c1ddd3d')
let(:get_resources) do
described_class.all(plan_group_uuid, per_page: 1, page: 1)
end

it_behaves_like 'raises deprecated param error'
end

context 'with new pagination' do
context 'with pagination' do
let(:first_cursor) do
'MjAyMy0xMC0yN1QxMDo0NTozNS4yMjM5MDUwMDBaJjEwOTk1ODQ='
end
Expand Down
15 changes: 4 additions & 11 deletions spec/chartmogul/plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,12 @@
end

context 'with old pagination' do
it 'paginates correctly' do
plans = described_class.all(per_page: 1, page: 3)
expect(plans.size).to eq(1)
expect(plans).to have_attributes(
cursor: nil, current_page: 3, total_pages: 14
)
expect(plans.first).to have_attributes(
uuid: 'pl_e1c26000-56e3-013c-fc49-2215549c3f98'
)
end
let(:get_resources) { described_class.all(per_page: 1, page: 3) }

it_behaves_like 'raises deprecated param error'
end

context 'with new pagination' do
context 'with pagination' do
let(:first_cursor) do
'MjAyMy0xMC0zMFQwMjoyNzoyOC4wMzU1OTIwMDBaJjExMDAyMjQ='
end
Expand Down
4 changes: 2 additions & 2 deletions spec/chartmogul/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@
end

it 'has multiple aliases', uses_api: true do
subscriptions = described_class.all('cus_510b1395-4fe8-4d35-ae23-0e61f9a51e33', page: 1, per_page: 2)
subscriptions = described_class.all('cus_510b1395-4fe8-4d35-ae23-0e61f9a51e33', per_page: 2)
expect(subscriptions.current_page).to eq(1)
expect(subscriptions.total_pages).to eq(1)
expect(subscriptions.size).to eq(1)
expect(subscriptions.first.uuid).to eq('sub_9b3ccf25-4613-4af6-84b3-12026cfa4b7c')

subscriptions = ChartMogul::Subscriptions.all('cus_510b1395-4fe8-4d35-ae23-0e61f9a51e33', page: 2, per_page: 1)
subscriptions = ChartMogul::Subscriptions.all('cus_510b1395-4fe8-4d35-ae23-0e61f9a51e33', per_page: 1)
expect(subscriptions.current_page).to eq(2)
expect(subscriptions.total_pages).to eq(2)
expect(subscriptions.size).to eq(1)
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8403c33

Please sign in to comment.