Class: Paymium::Client
- Inherits:
-
Object
- Object
- Paymium::Client
- Defined in:
- lib/paymium/client.rb
Overview
Authenticated connection to the Paymium API
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#delete(path, params = {}, &block) ⇒ Object
Issue a DELETE request against the API.
-
#get(path, params = {}, &block) ⇒ Object
Issue a GET request against the API.
-
#initialize(config = {}) ⇒ Client
constructor
Initialize a client.
-
#post(path, params = {}, &block) ⇒ Object
Issue a POST request against the API.
Constructor Details
#initialize(config = {}) ⇒ Client
Initialize a client
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
#config ⇒ Object
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
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
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
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 |