garbanzo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +278 -0
- data/README.md +122 -0
- data/Rakefile +9 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/garbanzo.gemspec +31 -0
- data/lib/garbanzo.rb +43 -0
- data/lib/garbanzo/address.rb +35 -0
- data/lib/garbanzo/ast.rb +9 -0
- data/lib/garbanzo/ast/base.rb +33 -0
- data/lib/garbanzo/ast/cancel.rb +19 -0
- data/lib/garbanzo/ast/create.rb +30 -0
- data/lib/garbanzo/ast/status.rb +19 -0
- data/lib/garbanzo/ast/update.rb +30 -0
- data/lib/garbanzo/connection.rb +11 -0
- data/lib/garbanzo/credentials.rb +23 -0
- data/lib/garbanzo/credit_card.rb +36 -0
- data/lib/garbanzo/duration.rb +21 -0
- data/lib/garbanzo/interval.rb +45 -0
- data/lib/garbanzo/parameters.rb +10 -0
- data/lib/garbanzo/parser.rb +21 -0
- data/lib/garbanzo/request.rb +33 -0
- data/lib/garbanzo/response.rb +25 -0
- data/lib/garbanzo/subscription.rb +54 -0
- data/lib/garbanzo/subscription/base.rb +46 -0
- data/lib/garbanzo/subscription/cancel.rb +11 -0
- data/lib/garbanzo/subscription/create.rb +16 -0
- data/lib/garbanzo/subscription/status.rb +21 -0
- data/lib/garbanzo/subscription/update.rb +16 -0
- data/lib/garbanzo/version.rb +3 -0
- metadata +231 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Garbanzo
|
4
|
+
class Request
|
5
|
+
def self.post(xml, test_mode = true)
|
6
|
+
new(test_mode).post(xml).body
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(test_mode)
|
10
|
+
@test_mode = test_mode
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(xml)
|
14
|
+
connection.post do |p|
|
15
|
+
p.url Garbanzo::API_URI
|
16
|
+
p.headers['Content-Type'] = 'text/xml'
|
17
|
+
p.body = xml
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :test_mode
|
24
|
+
|
25
|
+
def connection
|
26
|
+
@connection ||= Faraday.new(url: host)
|
27
|
+
end
|
28
|
+
|
29
|
+
def host
|
30
|
+
test_mode ? Garbanzo::TEST_HOST : Garbanzo::LIVE_HOST
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Garbanzo
|
2
|
+
class Response < Parser
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def_delegators :response, :id, :to_h
|
6
|
+
|
7
|
+
def self.wrap(response)
|
8
|
+
new(response).to_h
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def response
|
14
|
+
node(:resultCode) == 'Ok' ? success : error
|
15
|
+
end
|
16
|
+
|
17
|
+
def success
|
18
|
+
{ id: node(:subscriptionId).to_i }
|
19
|
+
end
|
20
|
+
|
21
|
+
def error
|
22
|
+
{ id: nil, error_code: node(:code), errors: [node(:text)] }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'garbanzo/subscription/base'
|
2
|
+
require 'garbanzo/subscription/create'
|
3
|
+
require 'garbanzo/subscription/cancel'
|
4
|
+
require 'garbanzo/subscription/status'
|
5
|
+
require 'garbanzo/subscription/update'
|
6
|
+
|
7
|
+
module Garbanzo
|
8
|
+
class Subscription
|
9
|
+
include ActiveAttr::Model
|
10
|
+
|
11
|
+
attribute :id, type: Integer
|
12
|
+
attribute :amount, type: Integer
|
13
|
+
attribute :card
|
14
|
+
attribute :address
|
15
|
+
attribute :duration, default: -> { Duration.new }
|
16
|
+
attribute :interval, default: -> { Interval.new }
|
17
|
+
attribute :internal_status, default: nil
|
18
|
+
|
19
|
+
attribute :error_code
|
20
|
+
|
21
|
+
def save
|
22
|
+
id ? update : create
|
23
|
+
!errors.any?
|
24
|
+
end
|
25
|
+
|
26
|
+
def cancel
|
27
|
+
handle_response Cancel.call(id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def status
|
31
|
+
handle_response Status.call(id)
|
32
|
+
internal_status
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def create
|
38
|
+
handle_response Create.call(amount, card, address, duration, interval)
|
39
|
+
end
|
40
|
+
|
41
|
+
def update
|
42
|
+
handle_response Update.call(id, amount, card, address, duration, interval)
|
43
|
+
end
|
44
|
+
|
45
|
+
def handle_response(response)
|
46
|
+
if response[:errors]
|
47
|
+
errors.add(:base, response[:errors])
|
48
|
+
else
|
49
|
+
self.attributes = response
|
50
|
+
end
|
51
|
+
self
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'gyoku'
|
2
|
+
|
3
|
+
module Garbanzo
|
4
|
+
class Subscription
|
5
|
+
class Base
|
6
|
+
module XMLFormatter
|
7
|
+
def to_xml
|
8
|
+
Gyoku.xml(self.nodes)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.call(*args)
|
13
|
+
new.call *args
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(connection = Garbanzo.connection)
|
17
|
+
@connection = connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(*args)
|
21
|
+
ast = ast_builder.build *args
|
22
|
+
request ast.to_xml
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :connection
|
28
|
+
|
29
|
+
def request(xml)
|
30
|
+
response_klass.wrap Request.post(xml, connection.test_mode)
|
31
|
+
end
|
32
|
+
|
33
|
+
def response_klass
|
34
|
+
Response
|
35
|
+
end
|
36
|
+
|
37
|
+
def ast_builder
|
38
|
+
ast_builder_klass.new(connection).extend(formatter)
|
39
|
+
end
|
40
|
+
|
41
|
+
def formatter
|
42
|
+
XMLFormatter
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Garbanzo
|
2
|
+
class Subscription
|
3
|
+
class Status < Base
|
4
|
+
private
|
5
|
+
|
6
|
+
def ast_builder_klass
|
7
|
+
Garbanzo::AST::Status
|
8
|
+
end
|
9
|
+
|
10
|
+
def response_klass
|
11
|
+
StatusResponse
|
12
|
+
end
|
13
|
+
|
14
|
+
class StatusResponse < Response
|
15
|
+
def success
|
16
|
+
{ status: node(:Status) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,231 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: garbanzo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Corin Schedler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: active_attr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gyoku
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: minitest-color
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: credit_card_validator
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: A small library for interacting with Authorize ARB
|
168
|
+
email:
|
169
|
+
- corin@dubdromic.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".gitignore"
|
175
|
+
- ".travis.yml"
|
176
|
+
- Gemfile
|
177
|
+
- LICENSE
|
178
|
+
- README.md
|
179
|
+
- Rakefile
|
180
|
+
- bin/console
|
181
|
+
- bin/setup
|
182
|
+
- garbanzo.gemspec
|
183
|
+
- lib/garbanzo.rb
|
184
|
+
- lib/garbanzo/address.rb
|
185
|
+
- lib/garbanzo/ast.rb
|
186
|
+
- lib/garbanzo/ast/base.rb
|
187
|
+
- lib/garbanzo/ast/cancel.rb
|
188
|
+
- lib/garbanzo/ast/create.rb
|
189
|
+
- lib/garbanzo/ast/status.rb
|
190
|
+
- lib/garbanzo/ast/update.rb
|
191
|
+
- lib/garbanzo/connection.rb
|
192
|
+
- lib/garbanzo/credentials.rb
|
193
|
+
- lib/garbanzo/credit_card.rb
|
194
|
+
- lib/garbanzo/duration.rb
|
195
|
+
- lib/garbanzo/interval.rb
|
196
|
+
- lib/garbanzo/parameters.rb
|
197
|
+
- lib/garbanzo/parser.rb
|
198
|
+
- lib/garbanzo/request.rb
|
199
|
+
- lib/garbanzo/response.rb
|
200
|
+
- lib/garbanzo/subscription.rb
|
201
|
+
- lib/garbanzo/subscription/base.rb
|
202
|
+
- lib/garbanzo/subscription/cancel.rb
|
203
|
+
- lib/garbanzo/subscription/create.rb
|
204
|
+
- lib/garbanzo/subscription/status.rb
|
205
|
+
- lib/garbanzo/subscription/update.rb
|
206
|
+
- lib/garbanzo/version.rb
|
207
|
+
homepage: https://github.com/dubdromic/garbanzo
|
208
|
+
licenses:
|
209
|
+
- GPLv2
|
210
|
+
metadata: {}
|
211
|
+
post_install_message:
|
212
|
+
rdoc_options: []
|
213
|
+
require_paths:
|
214
|
+
- lib
|
215
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
216
|
+
requirements:
|
217
|
+
- - ">="
|
218
|
+
- !ruby/object:Gem::Version
|
219
|
+
version: '0'
|
220
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
221
|
+
requirements:
|
222
|
+
- - ">="
|
223
|
+
- !ruby/object:Gem::Version
|
224
|
+
version: '0'
|
225
|
+
requirements: []
|
226
|
+
rubyforge_project:
|
227
|
+
rubygems_version: 2.4.5.1
|
228
|
+
signing_key:
|
229
|
+
specification_version: 4
|
230
|
+
summary: A small library for interacting with Authorize ARB
|
231
|
+
test_files: []
|