paymium 0.0.1 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5706b4c947cafd84f95f3a346b094af2422c0d59
4
- data.tar.gz: 36fc8e2eb461d4f75cd7410a4949a08a3d4c636c
3
+ metadata.gz: ebd140c948e6d8fd0ca5b259e98c9a1a1ec37676
4
+ data.tar.gz: fcf3630aa311096a1832e1177da2a4ec2e384435
5
5
  SHA512:
6
- metadata.gz: 073d60640008402cdd82691b3958274f98b9cf8132a9cef45cc82c6763d03f4193d564238451732826098e3a12ab4710c56a6aea138544a424a45a3cb09b7d4c
7
- data.tar.gz: 63e1e16c67d0f08e1597f775e8b4cb24ab94148ccb6ec79adf82583c3f0511a33dc6b64a502f9159159a6a85263a982d6ed04cdcb07efca55ef3d88c73e6e6b8
6
+ metadata.gz: fd67e9a92e028cdf673bca591255905ca7cd4e599e86ac8d37ac14ed29361821d44d31732ed207184de9cbcb539eb372c0fb87f2403cfde21a11b9fa5fa9c37e
7
+ data.tar.gz: f334aa0744fc62c8f9de989e6aa89455b14ae8fa9f9524631195a4fd09e3aa899c4f687c16fe216e39f3ddf7644ba470d995833ae87ee7898bda87a89a9ff4fe
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Paymium ruby client [![Build Status](https://secure.travis-ci.org/Paymium/paymium_gem.png?branch=master)](http://travis-ci.org/Paymium/paymium_gem) [![Coverage Status](https://img.shields.io/coveralls/Paymium/paymium_gem.svg)](https://coveralls.io/r/Paymium/paymium_gem?branch=master) [![Gem Version](https://badge.fury.io/rb/paymium_gem.svg)](http://badge.fury.io/rb/paymium_gem)
1
+ # Paymium ruby client [![Build Status](https://secure.travis-ci.org/Paymium/paymium_gem.png?branch=master)](http://travis-ci.org/Paymium/paymium_gem) [![Coverage Status](https://img.shields.io/coveralls/Paymium/paymium_gem.svg)](https://coveralls.io/r/Paymium/paymium_gem?branch=master) [![Gem Version](https://badge.fury.io/rb/paymium.svg)](http://badge.fury.io/rb/paymium)
2
2
 
3
3
  Simple ruby wrapper for the [Paymium API](https://github.com/Paymium/api-documentation).
4
4
 
@@ -9,3 +9,13 @@ Oj.default_options = {
9
9
  require 'paymium/client'
10
10
  require 'paymium/version'
11
11
 
12
+ #
13
+ # Root module
14
+ #
15
+ module Paymium
16
+
17
+ # Default API host
18
+ DEFAULT_HOST = 'https://paymium.com/api/v1'
19
+
20
+ end
21
+
@@ -3,34 +3,63 @@ require 'openssl'
3
3
  require 'base64'
4
4
 
5
5
  module Paymium
6
+
7
+ #
8
+ # Authenticated connection to the Paymium API
9
+ #
6
10
  class Client
7
11
 
8
- def initialize config = {}
9
- @config = HashWithIndifferentAccess.new config
10
- @host = URI.parse @config.delete(:host)
12
+ attr_accessor :config
13
+
14
+ #
15
+ # Initialize a client
16
+ #
17
+ # @param config [Hash] Symbol-keyed hash of the configuration
18
+ #
19
+ def initialize(config = {})
20
+ @config = config
21
+ @host = URI.parse @config.delete(:host) || Paymium::DEFAULT_HOST
11
22
  end
12
23
 
13
- def get path, params = {}, &block
24
+ #
25
+ # Issue a GET request against the API
26
+ #
27
+ # @param path [String] The request path
28
+ # @param params [Hash] The request parameters
29
+ #
30
+ def get(path, params = {}, &block)
14
31
  uri = uri_from_path(path)
15
32
  uri.query = URI.encode_www_form params unless params.empty?
16
- request Net::HTTP::Get.new(uri), &block
33
+ request(Net::HTTP::Get.new(uri), &block)
17
34
  end
18
35
 
19
- def post path, params = {}, &block
20
- req = Net::HTTP::Post.new(uri_from_path(path))
21
- req.body = Oj.dump(params)
22
- request req, &block
36
+ #
37
+ # Issue a POST request against the API
38
+ #
39
+ # @param path [String] The request path
40
+ # @param params [Hash] The request parameters
41
+ #
42
+ def post(path, params = {}, &block)
43
+ req = Net::HTTP::Post.new(uri_from_path(path), {})
44
+ req.body = Oj.dump(params)
45
+ request(req, &block)
23
46
  end
24
47
 
25
- def delete path, params = {}, &block
48
+ #
49
+ # Issue a DELETE request against the API
50
+ #
51
+ # @param path [String] The request path
52
+ # @param params [Hash] The request parameters
53
+ #
54
+ def delete(path, params = {}, &block)
26
55
  uri = uri_from_path(path)
27
56
  uri.query = URI.encode_www_form params unless params.empty?
28
- request Net::HTTP::Delete.new(uri), &block
57
+ request(Net::HTTP::Delete.new(uri), &block)
29
58
  end
30
59
 
31
60
  private
32
61
 
33
- def set_header_fields req
62
+ def set_header_fields(req)
34
63
  key = @config[:key]
35
64
  nonce = (Time.now.to_f * 10**6).to_i
36
65
  data = [nonce, req.uri.to_s, req.body].compact.join
@@ -41,35 +70,33 @@ module Paymium
41
70
  req
42
71
  end
43
72
 
44
- def uri_from_path path
73
+ def uri_from_path(path)
45
74
  uri = @host.dup
46
75
  uri.path = "#{@host.path}/#{path}".gsub('//','/')
47
76
  uri
48
77
  end
49
78
 
50
- def request req, &block
79
+ def request(req, &block)
51
80
  req.content_type = 'application/json'
52
- set_header_fields(req) if @config[:key].present? and @config[:secret].present?
81
+ set_header_fields(req) if @config[:key] and @config[:secret]
53
82
  Net::HTTP.start(@host.host, @host.port, :use_ssl => @host.scheme == 'https') do |http|
54
- resp = http.request req
55
- handle_response resp, &block
83
+ resp = http.request(req)
84
+ handle_response(resp, &block)
56
85
  end
57
86
  end
58
87
 
59
- #todo use Oj to parse response to handle big decimal
60
- def handle_response resp, &block
61
- if resp.class < Net::HTTPSuccess
62
- resp = Oj.load(resp.body)
63
- block.nil? ? resp : block.call(resp)
88
+ def handle_response(resp, &block)
89
+ if resp.class == Net::HTTPNoContent
90
+ block.nil? ? nil : block.call(resp)
91
+ elsif resp.class < Net::HTTPSuccess
92
+ parsed_resp = Oj.load(resp.body)
93
+ block.nil? ? parsed_resp : block.call(resp)
64
94
  else
65
- if resp.content_type == 'application/json'
66
- raise Error, [resp.message, Oj.load(resp.body)['errors']]
67
- else
68
- raise Error, resp.message
69
- end
95
+ raise Error, resp.body
70
96
  end
71
97
  end
72
98
 
99
+ # Generic Error class
73
100
  class Error < RuntimeError; end
74
101
 
75
102
  end
@@ -1,3 +1,6 @@
1
1
  module Paymium
2
- VERSION = "0.0.1"
2
+
3
+ # The gem version
4
+ VERSION = '0.0.11'
5
+
3
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas PAPON
@@ -95,6 +95,34 @@ dependencies:
95
95
  - - ~>
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0.7'
98
+ - !ruby/object:Gem::Dependency
99
+ name: vcr
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '2.9'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '2.9'
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: '1.0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.0'
98
126
  description: The client handles authentication and enables users to directly issue
99
127
  requests to the Paymium API
100
128
  email: