Class: Paymium::Client

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

Overview

Authenticated connection to the Paymium API

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Client

Initialize a client

Parameters:

  • config (Hash) (defaults to: {})

    Symbol-keyed hash of the configuration



19
20
21
22
# File 'lib/paymium/client.rb', line 19

def initialize(config = {})
  @config = config
  @host   = URI.parse @config.delete(:host) || Paymium::DEFAULT_HOST
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



12
13
14
# File 'lib/paymium/client.rb', line 12

def config
  @config
end

Instance Method Details

#delete(path, params = {}, &block) ⇒ Object

Issue a DELETE request against the API

Parameters:

  • path (String)

    The request path

  • params (Hash) (defaults to: {})

    The request parameters



54
55
56
57
58
# File 'lib/paymium/client.rb', line 54

def delete(path, params = {}, &block)
  uri       = uri_from_path(path)
  uri.query = URI.encode_www_form params unless params.empty?
  request(Net::HTTP::Delete.new(uri), &block)
end

#get(path, params = {}, &block) ⇒ Object

Issue a GET request against the API

Parameters:

  • path (String)

    The request path

  • params (Hash) (defaults to: {})

    The request parameters



30
31
32
33
34
# File 'lib/paymium/client.rb', line 30

def get(path, params = {}, &block)
  uri       = uri_from_path(path)
  uri.query = URI.encode_www_form params unless params.empty?
  request(Net::HTTP::Get.new(uri), &block)
end

#post(path, params = {}, &block) ⇒ Object

Issue a POST request against the API

Parameters:

  • path (String)

    The request path

  • params (Hash) (defaults to: {})

    The request parameters



42
43
44
45
46
# File 'lib/paymium/client.rb', line 42

def post(path, params = {}, &block)
  req       = Net::HTTP::Post.new(uri_from_path(path), {})
  req.body  = Oj.dump(params)
  request(req, &block)
end