buckaroo_json 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +9 -0
- data/buckaroo_json.gemspec +1 -0
- data/lib/buckaroo_json.rb +24 -2
- data/lib/buckaroo_json/request.rb +72 -0
- data/lib/buckaroo_json/services.rb +30 -0
- data/lib/buckaroo_json/transaction.rb +28 -0
- data/lib/buckaroo_json/transaction_specification.rb +24 -0
- data/lib/buckaroo_json/uri.rb +16 -0
- data/lib/buckaroo_json/version.rb +1 -1
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1d033bbda1b260f24ed469106927cdbb47fda0e
|
4
|
+
data.tar.gz: 79ec1613b3138c1512a4879d571e43b86dc1aebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ecf99806bdc066a87f65a4b9b6fb74ea72bde3e2a79d74f26c59b2408b13d7919f7d52a30f13ecad8f00e928a0ce31c0c0a8653a28a30871bc83929a42dd350
|
7
|
+
data.tar.gz: 571d006f22d968213242641c2a440bb9c9a4c8f95cd67ece8aabc09eb950d1f0fff7c7ec79c7cf8f68042535b0337eaedf2fd5138eb3e92496b9188f8e5c0b6a
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# 0.2.0 (2015-11-28)
|
2
|
+
|
3
|
+
* `BuckarooJson.transaction` added for creating new transactions
|
4
|
+
* `BuckarooJson.transaction_specification` for requesting data specs from server
|
5
|
+
|
6
|
+
# 0.1.0 (2015-11-15)
|
7
|
+
|
8
|
+
* HMAC Authentication following [Buckaroo documentation](https://testcheckout.buckaroo.nl/json/Docs/Authentication)
|
9
|
+
|
data/buckaroo_json.gemspec
CHANGED
data/lib/buckaroo_json.rb
CHANGED
@@ -1,6 +1,28 @@
|
|
1
|
-
require 'buckaroo_json/
|
1
|
+
require 'buckaroo_json/transaction'
|
2
|
+
require 'buckaroo_json/transaction_specification'
|
2
3
|
require 'buckaroo_json/version'
|
3
4
|
|
4
5
|
module BuckarooJson
|
5
|
-
|
6
|
+
def self.transaction(content = {})
|
7
|
+
Transaction.create(**configuration.merge(content: content))
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.transaction_specification(service, version: '3.0')
|
11
|
+
TransactionSpecification.create(
|
12
|
+
**configuration.merge(
|
13
|
+
service: service,
|
14
|
+
version: version
|
15
|
+
)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.configuration
|
22
|
+
{
|
23
|
+
mode: ENV['BUCKAROO_JSON_MODE'] || 'test',
|
24
|
+
website_key: ENV['BUCKAROO_JSON_WEBSITE_KEY'],
|
25
|
+
api_key: ENV['BUCKAROO_JSON_API_KEY']
|
26
|
+
}
|
27
|
+
end
|
6
28
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'buckaroo_json/authorization_header'
|
4
|
+
require 'buckaroo_json/uri'
|
5
|
+
|
6
|
+
module BuckarooJson
|
7
|
+
module Request
|
8
|
+
class << self
|
9
|
+
def create(mode:, website_key:, api_key:, method:, endpoint:, content:)
|
10
|
+
uri = checkout_uri(mode: mode, endpoint: endpoint)
|
11
|
+
req = request_for_method(
|
12
|
+
website_key: website_key,
|
13
|
+
api_key: api_key,
|
14
|
+
method: method,
|
15
|
+
uri: uri,
|
16
|
+
content: content.to_json
|
17
|
+
)
|
18
|
+
response(host: uri.host, port: uri.port, request: req)
|
19
|
+
end
|
20
|
+
|
21
|
+
def checkout_uri(mode:, endpoint:)
|
22
|
+
Uri.create(mode: mode, endpoint: endpoint)
|
23
|
+
end
|
24
|
+
|
25
|
+
def request_for_method(method:, **args)
|
26
|
+
case method
|
27
|
+
when 'GET'
|
28
|
+
get(**args)
|
29
|
+
when 'POST'
|
30
|
+
post(**args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def get(uri:, content:, website_key:, api_key:)
|
35
|
+
Net::HTTP::Get.new(uri.request_uri).tap do |req|
|
36
|
+
req['Accept'] = 'application/json'
|
37
|
+
req['Authorization'] = create_authorization_header(
|
38
|
+
website_key: website_key,
|
39
|
+
api_key: api_key,
|
40
|
+
method: 'GET',
|
41
|
+
url: uri,
|
42
|
+
content: content
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def post(uri:, content:, website_key:, api_key:)
|
48
|
+
Net::HTTP::Post.new(uri.request_uri).tap do |req|
|
49
|
+
req.body = content
|
50
|
+
req['Content-Type'] = 'application/json'
|
51
|
+
req['Authorization'] = create_authorization_header(
|
52
|
+
website_key: website_key,
|
53
|
+
api_key: api_key,
|
54
|
+
method: 'POST',
|
55
|
+
url: uri,
|
56
|
+
content: content
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def response(host:, port:, request:)
|
62
|
+
Net::HTTP.start(host, port, use_ssl: true) do |http|
|
63
|
+
http.request(request)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_authorization_header(**args)
|
68
|
+
AuthorizationHeader.create(**args)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module BuckarooJson
|
2
|
+
module Services
|
3
|
+
class << self
|
4
|
+
def convert(services)
|
5
|
+
{
|
6
|
+
'ServiceList' => services.map { |s| convert_service(s) }
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def convert_service(params)
|
13
|
+
base, others = split_hash(params, 'Name', 'Action', 'Version')
|
14
|
+
base.merge('Parameters' => expand_parameters(others))
|
15
|
+
end
|
16
|
+
|
17
|
+
def split_hash(the_hash, *keys)
|
18
|
+
selected = the_hash.select { |key, _| keys.include?(key) }
|
19
|
+
others = the_hash.reject { |key, _| keys.include?(key) }
|
20
|
+
[selected, others]
|
21
|
+
end
|
22
|
+
|
23
|
+
def expand_parameters(params)
|
24
|
+
params.to_a.map do |key, value|
|
25
|
+
{ 'Name' => key, 'Value' => value }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'buckaroo_json/request'
|
2
|
+
require 'buckaroo_json/services'
|
3
|
+
|
4
|
+
module BuckarooJson
|
5
|
+
module Transaction
|
6
|
+
class << self
|
7
|
+
def create(mode:, website_key:, api_key:, content:)
|
8
|
+
Request.create(
|
9
|
+
mode: mode,
|
10
|
+
website_key: website_key,
|
11
|
+
api_key: api_key,
|
12
|
+
method: 'POST',
|
13
|
+
endpoint: 'Transaction',
|
14
|
+
content: convert_services(content)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def convert_services(content)
|
21
|
+
return content unless content.key?('Services')
|
22
|
+
content.merge(
|
23
|
+
'Services' => Services.convert(content['Services'])
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'buckaroo_json/request'
|
2
|
+
|
3
|
+
module BuckarooJson
|
4
|
+
module TransactionSpecification
|
5
|
+
class << self
|
6
|
+
def create(mode:, website_key:, api_key:, service:, version:)
|
7
|
+
Request.create(
|
8
|
+
mode: mode,
|
9
|
+
website_key: website_key,
|
10
|
+
api_key: api_key,
|
11
|
+
method: 'GET',
|
12
|
+
endpoint: endpoint(service, version),
|
13
|
+
content: nil
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def endpoint(service, version)
|
20
|
+
"Transaction/Specification/#{service}?serviceVersion=#{version}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module BuckarooJson
|
4
|
+
module Uri
|
5
|
+
class << self
|
6
|
+
def create(mode:, endpoint:)
|
7
|
+
URI.join("https://#{subdomain(mode)}.buckaroo.nl", 'json/', endpoint)
|
8
|
+
end
|
9
|
+
|
10
|
+
def subdomain(mode)
|
11
|
+
return 'checkout' if mode == 'production'
|
12
|
+
'testcheckout'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buckaroo_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Floris Huetink
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- florishuetink@gmail.com
|
@@ -62,6 +76,7 @@ files:
|
|
62
76
|
- ".gitignore"
|
63
77
|
- ".rspec"
|
64
78
|
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
65
80
|
- CODE_OF_CONDUCT.md
|
66
81
|
- Gemfile
|
67
82
|
- LICENSE.txt
|
@@ -72,6 +87,11 @@ files:
|
|
72
87
|
- buckaroo_json.gemspec
|
73
88
|
- lib/buckaroo_json.rb
|
74
89
|
- lib/buckaroo_json/authorization_header.rb
|
90
|
+
- lib/buckaroo_json/request.rb
|
91
|
+
- lib/buckaroo_json/services.rb
|
92
|
+
- lib/buckaroo_json/transaction.rb
|
93
|
+
- lib/buckaroo_json/transaction_specification.rb
|
94
|
+
- lib/buckaroo_json/uri.rb
|
75
95
|
- lib/buckaroo_json/version.rb
|
76
96
|
homepage: https://github.com/florish/buckaroo_json
|
77
97
|
licenses:
|