Class: RubyPaypalNvp::Fetcher::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_paypal_nvp/fetcher/base.rb

Direct Known Subclasses

Balance, Statement

Class Method Summary collapse

Instance Method Summary collapse

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(options)
  new(options).call
end

Instance Method Details

#callObject

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(options)
  uri = URI(RubyPaypalNvp.configuration.api_url)
  req = Net::HTTP::Post.new(uri)
  req.set_form_data(options)
  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