actionkit_connector 0.1.4 → 0.2.0
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/lib/actionkit_connector/version.rb +1 -1
- data/lib/actionkit_connector.rb +62 -0
- data/spec/connector_spec.rb +100 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4eeb4b6e7d0bde25857028d38896ff19d78b604a
|
4
|
+
data.tar.gz: b1fc898fca46658d916db5019725a7a12da08255
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 580bd61fe4bfbcb047d65b3188d762d6192168774d2241625c84496204dc2138498eb4b7481dcfca8329913c0491529909b0e5ee3a4c50dbc0705d7ec6b62eb1
|
7
|
+
data.tar.gz: cc98ec77802888dcc844dc7d8306350bd957fc9e1440f83ffdaf3f64fde51acbbbddf0369637f2172f0863367ebd576daf68ce92decf6af56b503e7a65c61de8
|
data/lib/actionkit_connector.rb
CHANGED
@@ -137,6 +137,22 @@ module ActionKitConnector
|
|
137
137
|
self.class.post(target, options)
|
138
138
|
end
|
139
139
|
|
140
|
+
# Creates an action which registers a donation with a user account.
|
141
|
+
#
|
142
|
+
# @param [Hash] options The hash of values sent to ActionKit which contain information about this transaction.
|
143
|
+
def create_donation_action(options={})
|
144
|
+
target = "#{self.base_url}/donationpush/"
|
145
|
+
options = self.validate_donation_options(options)
|
146
|
+
page_opts = {
|
147
|
+
basic_auth: self.auth,
|
148
|
+
body: options.to_json,
|
149
|
+
headers: {
|
150
|
+
'Content-Type' => 'application/json'
|
151
|
+
}
|
152
|
+
}
|
153
|
+
self.class.post(target, page_opts)
|
154
|
+
end
|
155
|
+
|
140
156
|
def parse_action_options(options)
|
141
157
|
included_options = {}
|
142
158
|
acceptable_options = [
|
@@ -154,5 +170,51 @@ module ActionKitConnector
|
|
154
170
|
end
|
155
171
|
included_options
|
156
172
|
end
|
173
|
+
|
174
|
+
def validate_donation_options(options)
|
175
|
+
required_base_keys = [:donationpage, :order, :user]
|
176
|
+
if required_base_keys.all? {|s| options.key? s}
|
177
|
+
options[:donationpage] = validate_donationpage_options(options[:donationpage])
|
178
|
+
options[:order] = validate_donation_order_options(options[:order])
|
179
|
+
options[:user] = validate_donation_user_options(options[:user])
|
180
|
+
else
|
181
|
+
raise 'Donation options require donationpage, order and user keys in the base hash.'
|
182
|
+
end
|
183
|
+
options
|
184
|
+
end
|
185
|
+
|
186
|
+
def validate_donationpage_options(options)
|
187
|
+
required_base_keys = [:name, :payment_account]
|
188
|
+
if required_base_keys.all? {|s| options.key? s}
|
189
|
+
options
|
190
|
+
else
|
191
|
+
raise 'Donation Page options require name and payment_account keys in the hash.'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def validate_donation_order_options(options)
|
196
|
+
required_base_keys = [:amount, :exp_date_month, :exp_date_year]
|
197
|
+
if required_base_keys.all? {|s| options.key? s}
|
198
|
+
if options[:card_num].nil?
|
199
|
+
options[:card_num] = '4111111111111111' # Default placeholder card number.
|
200
|
+
end
|
201
|
+
|
202
|
+
if options[:card_code].nil?
|
203
|
+
options[:card_code] = '007' # Default AK Card Code.
|
204
|
+
end
|
205
|
+
else
|
206
|
+
raise 'Donation Order options require amount, exp_date_month and exp_date_year keys.'
|
207
|
+
end
|
208
|
+
options
|
209
|
+
end
|
210
|
+
|
211
|
+
def validate_donation_user_options(options)
|
212
|
+
required_base_keys = [:email, :country]
|
213
|
+
if required_base_keys.all? {|s| options.key? s}
|
214
|
+
options
|
215
|
+
else
|
216
|
+
raise 'Donation User options require email and country keys in the hash.'
|
217
|
+
end
|
218
|
+
end
|
157
219
|
end
|
158
220
|
end
|
data/spec/connector_spec.rb
CHANGED
@@ -63,5 +63,105 @@ describe 'Connector' do
|
|
63
63
|
with(body: request_body)
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
# Used for the donation validations below.
|
68
|
+
let(:full_donation_options) {
|
69
|
+
{
|
70
|
+
donationpage: {
|
71
|
+
name: 'donation',
|
72
|
+
payment_account: 'Default Import Stub'
|
73
|
+
},
|
74
|
+
order: {
|
75
|
+
amount: '1',
|
76
|
+
card_num: '4111111111111111',
|
77
|
+
card_code: '007',
|
78
|
+
exp_date_month: '01',
|
79
|
+
exp_date_year: '2016'
|
80
|
+
},
|
81
|
+
user: {
|
82
|
+
email: 'eric@sumofus.org',
|
83
|
+
country: 'United States',
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
describe '#create_donation_action' do
|
89
|
+
let(:request_body) {
|
90
|
+
full_donation_options.to_json
|
91
|
+
}
|
92
|
+
|
93
|
+
before do
|
94
|
+
stub_request(:post, "http://username:password@api.example.com/donationpush/").
|
95
|
+
with(body: request_body)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'creates a donationpush action' do
|
99
|
+
client.create_donation_action(full_donation_options)
|
100
|
+
expect(WebMock).to have_requested(:post, 'http://username:password@api.example.com/donationpush/').
|
101
|
+
with(body: request_body, headers: {'Content-Type' => 'application/json'})
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'donation validation methods' do
|
106
|
+
let(:expected_donationpage) {
|
107
|
+
full_donation_options[:donationpage]
|
108
|
+
}
|
109
|
+
let(:expected_order) {
|
110
|
+
full_donation_options[:order]
|
111
|
+
}
|
112
|
+
let(:expected_user) {
|
113
|
+
full_donation_options[:user]
|
114
|
+
}
|
115
|
+
describe '#validate_donation_options' do
|
116
|
+
it 'sends back the correct options when provided a valid hash' do
|
117
|
+
expect(client.validate_donation_options(full_donation_options)).to eq(full_donation_options)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'raises when provided an incorrect set of base hash values' do
|
121
|
+
expect { client.validate_donation_options({}) }.to raise_error(RuntimeError)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#validate_donationpage_options' do
|
126
|
+
it 'sends back the correct options when provided a valid hash' do
|
127
|
+
expect(client.validate_donationpage_options(expected_donationpage)).to eq(expected_donationpage)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'raises when provided an incorrect set of hash values' do
|
131
|
+
expect { client.validate_donationpage_options({}) }.to raise_error(RuntimeError)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#validate_donation_user_options' do
|
136
|
+
it 'sends back the correct options when provided a valid hash' do
|
137
|
+
expect(client.validate_donation_user_options(expected_user)).to eq(expected_user)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'raises when provided an incorrect set of hash values' do
|
141
|
+
expect { client.validate_donation_user_options({}) }.to raise_error(RuntimeError)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#validate_donation_order_options' do
|
146
|
+
it 'sends back the correct options when provided a correct hash' do
|
147
|
+
expect(client.validate_donation_order_options(expected_order)).to eq(expected_order)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'raises when provided an incorrect set of hash values' do
|
151
|
+
expect { client.validate_donation_order_options({}) }.to raise_error(RuntimeError)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'fills in default values if they are not provided' do
|
155
|
+
sent_values = expected_order.tap { |hash|
|
156
|
+
hash.delete(:card_num)
|
157
|
+
hash.delete(:card_code)
|
158
|
+
}
|
159
|
+
expect(client.validate_donation_order_options(sent_values)).to eq(expected_order)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
|
66
166
|
end
|
67
167
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionkit_connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Boersma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.4.
|
135
|
+
rubygems_version: 2.4.8
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: A gem for interacting with the ActionKit API.
|