class QiwiObserver::Payments

Constants

API_PATH

Public Class Methods

new() click to toggle source
# File lib/qiwi_observer/payments/payments.rb, line 5
def initialize
  @wallet = QiwiObserver.config.wallet
  @token = QiwiObserver.config.token

  raise ArgumentError, "Wallet and token must be configure" if @wallet.nil? && @token.nil?
end

Public Instance Methods

call(args = {}) click to toggle source
# File lib/qiwi_observer/payments/payments.rb, line 12
def call(args = {})
  uri = linkage(args)
  request = prepare_a_request(uri)
  http = connect_to(uri)

  response = http.request(request)


  return PaymentsResponse.new(success: true, body: response.body) if response.is_a?(Net::HTTPOK)
  return PaymentsResponse.new(success: false, body: [response.code, response.message])
end

Private Instance Methods

connect_to(uri) click to toggle source
# File lib/qiwi_observer/payments/payments.rb, line 44
def connect_to(uri)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  http
end
linkage(args) click to toggle source
# File lib/qiwi_observer/payments/payments.rb, line 26
def linkage(args)
  link = URI(API_PATH + "#{@wallet}/payments")
  link.query = URI.encode_www_form(args)
  link
end
prepare_a_request(uri) click to toggle source
# File lib/qiwi_observer/payments/payments.rb, line 32
def prepare_a_request(uri)
  request = Net::HTTP::Get.new(uri)
  request.initialize_http_header(
    {
      'Accept' => 'application/json',
      'Content-Type' => 'application/json',
      'Authorization' => "Bearer #{@token}"
    }
  )
  request
end