Class: PaysonAPI::V2::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/payson_api/v2/client.rb

Class Method Summary collapse

Class Method Details

.account_infoObject



9
10
11
12
# File 'lib/payson_api/v2/client.rb', line 9

def self.
  response = payson_request(Net::HTTP::Get, PAYSON_API_RESOURCES[:accounts][:get])
  PaysonAPI::V2::Models::.from_hash(JSON.parse(response.body))
end

.create_checkout(request) ⇒ Object



19
20
21
22
23
# File 'lib/payson_api/v2/client.rb', line 19

def self.create_checkout(request)
  response = payson_request(Net::HTTP::Post, PAYSON_API_RESOURCES[:checkouts][:create], request)
  intercept_validation_errors(response)
  PaysonAPI::V2::Models::Checkout.from_hash(JSON.parse(response.body))
end

.get_checkout(id) ⇒ Object



14
15
16
17
# File 'lib/payson_api/v2/client.rb', line 14

def self.get_checkout(id)
  response = payson_request(Net::HTTP::Get, PAYSON_API_RESOURCES[:checkouts][:get] % id)
  PaysonAPI::V2::Models::Checkout.from_hash(JSON.parse(response.body))
end

.list_checkouts(request) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/payson_api/v2/client.rb', line 31

def self.list_checkouts(request)
  path = [PAYSON_API_RESOURCES[:checkouts][:list], hash_to_params(request.to_hash)].join('?')
  response = payson_request(Net::HTTP::Get, path)
  [].tap do |checkouts|
    JSON.parse(response.body)['data'].each do |json|
      checkouts << PaysonAPI::V2::Models::Checkout.from_hash(json)
    end
  end
end

.update_checkout(request) ⇒ Object



25
26
27
28
29
# File 'lib/payson_api/v2/client.rb', line 25

def self.update_checkout(request)
  response = payson_request(Net::HTTP::Put, PAYSON_API_RESOURCES[:checkouts][:update] % request.id, request)
  intercept_validation_errors(response)
  PaysonAPI::V2::Models::Checkout.from_hash(JSON.parse(response.body))
end