Class: RubyPaypalNvp::Fetcher::Base
- Inherits:
-
Object
- Object
- RubyPaypalNvp::Fetcher::Base
- Defined in:
- lib/ruby_paypal_nvp/fetcher/base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:enable Metrics/AbcSize.
-
#initialize(opts) ⇒ Base
constructor
Input options: date_from date_to currency subject transaction_class.
- #load_api_response(options) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Base
Input options:
date_from
date_to
currency
subject
transaction_class
rubocop:disable Metrics/AbcSize
17 18 19 20 21 22 23 24 |
# File 'lib/ruby_paypal_nvp/fetcher/base.rb', line 17 def initialize(opts) @start_date = opts.fetch(:date_from, Time.zone.now).beginning_of_day.utc.iso8601 @end_date = opts.fetch(:date_to, Time.zone.now).end_of_day.utc.iso8601 @currency = opts.fetch(:currency, 'CZK') @subject = opts[:subject] || RubyPaypalNvp.configuration.subject @transaction_class = opts.fetch(:transaction_class, 'BalanceAffecting') @resulting_hash = default_hash end |
Class Method Details
.call(options) ⇒ Object
34 35 36 |
# File 'lib/ruby_paypal_nvp/fetcher/base.rb', line 34 def self.call() new().call end |
Instance Method Details
#call ⇒ Object
rubocop:enable Metrics/AbcSize
27 28 29 30 31 32 |
# File 'lib/ruby_paypal_nvp/fetcher/base.rb', line 27 def call result = load_response process_loaded_data(result) rescue NoMethodError raise "Error processing #{self.class} for #{@subject}" end |
#load_api_response(options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_paypal_nvp/fetcher/base.rb', line 38 def load_api_response() uri = URI(RubyPaypalNvp.configuration.api_url) req = Net::HTTP::Post.new(uri) req.set_form_data() res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.open_timeout = 6000 http.read_timeout = 6000 http.request(req) end pretty_json(res.body) end |