Add a configure method to the class

This commit is contained in:
Dan Milne
2019-09-09 13:26:11 +10:00
parent 8ba56663ae
commit c77d41d3f1
3 changed files with 41 additions and 1 deletions

View File

@@ -8,4 +8,19 @@ require 'paapi/response'
module Paapi
class Error < StandardError; end
class NotImplemented < StandardError; end
class << self
attr_accessor :access_key,
:secret_key,
:partner_tag,
:partner_type,
:marketplace,
:test_mode
def configure
yield self
true
end
alias_method :config, :configure
end
end

View File

@@ -6,7 +6,13 @@ module Paapi
attr_accessor :marketplace, :partner_tag
attr_reader :partner_type, :access_key, :secret_key
def initialize(access_key:, secret_key:, marketplace:, partner_tag: nil, resources: nil, partner_type: 'Associates')
def initialize(access_key: Paapi.access_key,
secret_key: Paapi.secret_key,
marketplace: Paapi.marketplace || :us,
partner_tag: Paapi.partner_tag,
resources: nil,
partner_type: 'Associates'
)
raise ArgumentError unless MARKETPLACES.keys.include?(marketplace.to_sym)
@access_key = access_key
@secret_key = secret_key