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 +4 -4
- data/README.md +1 -1
- data/lib/paymium.rb +10 -0
- data/lib/paymium/client.rb +54 -27
- data/lib/paymium/version.rb +4 -1
- metadata +29 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebd140c948e6d8fd0ca5b259e98c9a1a1ec37676
|
4
|
+
data.tar.gz: fcf3630aa311096a1832e1177da2a4ec2e384435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd67e9a92e028cdf673bca591255905ca7cd4e599e86ac8d37ac14ed29361821d44d31732ed207184de9cbcb539eb372c0fb87f2403cfde21a11b9fa5fa9c37e
|
7
|
+
data.tar.gz: f334aa0744fc62c8f9de989e6aa89455b14ae8fa9f9524631195a4fd09e3aa899c4f687c16fe216e39f3ddf7644ba470d995833ae87ee7898bda87a89a9ff4fe
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Paymium ruby client [](http://travis-ci.org/Paymium/paymium_gem) [](https://coveralls.io/r/Paymium/paymium_gem?branch=master) [](http://travis-ci.org/Paymium/paymium_gem) [](https://coveralls.io/r/Paymium/paymium_gem?branch=master) [](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
|
|
data/lib/paymium.rb
CHANGED
data/lib/paymium/client.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
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
|
33
|
+
request(Net::HTTP::Get.new(uri), &block)
|
17
34
|
end
|
18
35
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
57
|
+
request(Net::HTTP::Delete.new(uri), &block)
|
29
58
|
end
|
30
59
|
|
31
60
|
private
|
32
61
|
|
33
|
-
def set_header_fields
|
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
|
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
|
79
|
+
def request(req, &block)
|
51
80
|
req.content_type = 'application/json'
|
52
|
-
set_header_fields(req) if @config[:key]
|
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
|
55
|
-
handle_response
|
83
|
+
resp = http.request(req)
|
84
|
+
handle_response(resp, &block)
|
56
85
|
end
|
57
86
|
end
|
58
87
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
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
|
data/lib/paymium/version.rb
CHANGED
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.
|
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:
|