Skip to content

Commit

Permalink
Merge pull request #31 from inloco/feat/remove_api_instance
Browse files Browse the repository at this point in the history
Remove support for Incognia::Api initialization
  • Loading branch information
ottony authored Nov 12, 2024
2 parents ecb2f04 + 09e6e34 commit a407912
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 94 deletions.
23 changes: 3 additions & 20 deletions lib/incognia_api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,10 @@

module Incognia
class Api
# business layer: uses the Client.instance to build domain objects
# raises missing parameters errors

def initialize(client_id:, client_secret:)
Incognia.configure(client_id: client_id, client_secret: client_secret)

warn("Deprecation warning: The Incognia::Api instance will be removed. " +
"Please set up with `Incognia.configure` and use class methods instead.")
end

def register_signup(**args); self.class.register_signup(**args) end
def register_login(**args); self.class.register_login(**args) end
def register_feedback(**args); self.class.register_feedback(**args) end
def register_payment(**args); self.class.register_payment(**args) end
def connection
warn("Deprecation warning: #connection and .connection are deprecated and will be private.")

self.class.connection
end

class << self
# business layer: uses the Client.instance to build domain objects
# raises missing parameters errors

def register_signup(request_token: nil, address: nil, **opts)
params = { request_token: request_token }.compact
params.merge!(opts)
Expand Down
74 changes: 0 additions & 74 deletions spec/incognia_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -579,79 +579,5 @@ def expect_evidences_to_match(model, expected)
expect(model.evidence.location_services.location_sensors_enabled).
to eql expected[:evidence][:location_services][:location_sensors_enabled]
end

context 'deprecated instance' do
let(:api_instance) do
described_class.new(client_id: 'id', client_secret: 'secret')
end

before do
allow_any_instance_of(described_class).to receive(:warn)
end

describe 'initialization' do
it 'configures Incognia with client_id and client_secret' do
expect(Incognia).to receive(:configure).with(
client_id: 'id',
client_secret: 'secret'
)

api_instance
end
end

shared_examples_for 'instance method delegation' do |method, args|
it "calls Incognia.#{method}" do
expect(described_class).to receive(method).with(**args)

api_instance.method(method).call(**args)
end
end

describe '#register_signup' do
it_behaves_like 'instance method delegation', :register_signup, {
request_token: 'request_token',
address: 'address',
account_id: 'account_id'
}
end

describe '#register_login' do
it_behaves_like 'instance method delegation', :register_login, {
account_id: 'account_id',
request_token: 'token',
external_id: 'external_id'
}
end

describe '#register_payment' do
it_behaves_like 'instance method delegation', :register_payment, {
account_id: 'account_id',
request_token: 'token',
external_id: 'external_id'
}
end

describe '#register_feedback' do
it_behaves_like 'instance method delegation', :register_feedback, {
event: 'event',
account_id: 'account_id'
}
end

describe '#connection' do
it 'calls Incognia.connection' do
expect(described_class).to receive(:connection)

api_instance.connection
end

it 'warns about deprecation of #connection and .connection' do
expect(api_instance).to receive(:warn).with("Deprecation warning: #connection and .connection are deprecated and will be private.")

api_instance.connection
end
end
end
end
end

0 comments on commit a407912

Please sign in to comment.