alpha_card 0.2.2 → 0.2.3
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/Rakefile +1 -1
- data/alpha_card.gemspec +5 -5
- data/lib/alpha_card.rb +15 -18
- data/lib/alpha_card/account.rb +3 -3
- data/lib/alpha_card/alpha_card_object.rb +2 -2
- data/lib/alpha_card/alpha_card_response.rb +1 -1
- data/lib/alpha_card/billing.rb +1 -1
- data/lib/alpha_card/order.rb +1 -1
- data/lib/alpha_card/sale.rb +6 -4
- data/lib/alpha_card/shipping.rb +3 -3
- data/lib/alpha_card/utils.rb +4 -4
- data/lib/alpha_card/version.rb +2 -2
- data/spec/alpha_card/alpha_card_account_spec.rb +1 -1
- data/spec/alpha_card/alpha_card_response_spec.rb +1 -1
- data/spec/alpha_card/alpha_card_spec.rb +1 -1
- data/spec/alpha_card/alpha_card_utils_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c5e5fb8c704ad1100003d8eb8023a7adf9c782d
|
4
|
+
data.tar.gz: 8207975985e90e9287e360eccda6ffdc649a0cba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eb401a030e241fa9345168a1efe3dbcfdb26b1a3a4a8cb490bc6d94013cfdfc22ff029e753bdcc1e7e6854b57a6a0afd91c6263a4644a7c30da437c2f1ff5ab
|
7
|
+
data.tar.gz: 63c3e4f5fa8936433ad872e45e652357f4c773f8b3a003eb9dc75abcc2edf7f59e078fee5e0df6e62c5691d7651c212171d4638b4ca66f5db7c35fea11c6ed3c
|
data/Rakefile
CHANGED
data/alpha_card.gemspec
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2
2
|
|
3
3
|
require 'alpha_card/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = 'alpha_card'
|
7
7
|
gem.version = AlphaCard::VERSION
|
8
|
-
gem.date = '2014-07-
|
8
|
+
gem.date = '2014-07-24'
|
9
9
|
gem.summary = 'Alpha Card Services DirectPost API for Ruby'
|
10
10
|
gem.description = 'Gem for creating sales with Alpha Card Services DirectPost API'
|
11
11
|
gem.authors = ['Nikita Bulaj']
|
12
12
|
gem.email = 'bulajnikita@gmail.com'
|
13
|
-
gem.require_paths = [
|
14
|
-
gem.files = `git ls-files`.split(
|
13
|
+
gem.require_paths = ['lib']
|
14
|
+
gem.files = `git ls-files`.split($RS)
|
15
15
|
gem.homepage = 'http://github.com/budev/alpha_card'
|
16
16
|
gem.license = 'MIT'
|
17
17
|
gem.required_ruby_version = '>= 1.9.3'
|
@@ -19,5 +19,5 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_dependency 'virtus', '~> 1.0'
|
20
20
|
gem.add_dependency 'rest_client', '~> 1.7'
|
21
21
|
|
22
|
-
gem.add_development_dependency
|
22
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
23
23
|
end
|
data/lib/alpha_card.rb
CHANGED
@@ -83,9 +83,7 @@ module AlphaCard
|
|
83
83
|
#
|
84
84
|
# #=> AlphaCard::AlphaCardError: AlphaCard::AlphaCardError
|
85
85
|
def self.request(params = {}, account)
|
86
|
-
unless account.filled?
|
87
|
-
raise AlphaCardError.new('You must set credentials to create the sale!')
|
88
|
-
end
|
86
|
+
fail AlphaCardError, 'You must set credentials to create the sale!' unless account.filled?
|
89
87
|
|
90
88
|
begin
|
91
89
|
response = RestClient.post(@api_base, params.merge(account.attributes))
|
@@ -130,22 +128,21 @@ module AlphaCard
|
|
130
128
|
#
|
131
129
|
# @raise [AlphaCard::AlphaCardError]
|
132
130
|
# AlphaCardError Exception.
|
133
|
-
def self.handle_connection_errors(
|
134
|
-
case
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
131
|
+
def self.handle_connection_errors(error)
|
132
|
+
case error
|
133
|
+
when RestClient::ServerBrokeConnection, RestClient::RequestTimeout
|
134
|
+
message = "Could not connect to Alpha Card Gateway (#{@api_base}). " \
|
135
|
+
'Please check your internet connection and try again. ' \
|
136
|
+
'If this problem persists, you should check Alpha Card services status.'
|
137
|
+
|
138
|
+
when SocketError
|
139
|
+
message = 'Unexpected error communicating when trying to connect to Alpha Card Gateway. ' \
|
140
|
+
'You may be seeing this message because your DNS is not working.'
|
141
|
+
|
142
|
+
else
|
143
|
+
message = 'Unexpected error communicating with Alpha Card Gateway.'
|
146
144
|
end
|
147
145
|
|
148
|
-
raise APIConnectionError
|
146
|
+
raise APIConnectionError, "#{message}\n\n(Network error: #{error.message})"
|
149
147
|
end
|
150
148
|
end
|
151
|
-
|
data/lib/alpha_card/account.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module AlphaCard
|
2
2
|
##
|
3
3
|
# Implementation of Alpha Card Services account object.
|
4
|
-
# Contains credentials (username and password) for
|
4
|
+
# Contains credentials (username and password) for
|
5
5
|
# the Alpha Card Gateway API access.
|
6
6
|
class Account < AlphaCardObject
|
7
7
|
attribute :username, String
|
@@ -42,7 +42,7 @@ module AlphaCard
|
|
42
42
|
# #=> false
|
43
43
|
def filled?
|
44
44
|
attrs = [username, password]
|
45
|
-
!attrs.empty? && attrs.all? {|attr| attr && !attr.strip.empty? }
|
45
|
+
!attrs.empty? && attrs.all? { |attr| attr && !attr.strip.empty? }
|
46
46
|
end
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
data/lib/alpha_card/billing.rb
CHANGED
data/lib/alpha_card/order.rb
CHANGED
data/lib/alpha_card/sale.rb
CHANGED
@@ -41,13 +41,15 @@ module AlphaCard
|
|
41
41
|
# #=> true
|
42
42
|
def create(order, account)
|
43
43
|
[:ccexp, :ccnumber, :amount].each do |attr|
|
44
|
-
|
44
|
+
fail Exception, "No #{attr} information provided" if self[attr].nil? || self[attr].empty?
|
45
45
|
end
|
46
46
|
|
47
|
-
params =
|
48
|
-
[order, order.billing, order.shipping].compact.each
|
47
|
+
params = filled_attributes || {}
|
48
|
+
[order, order.billing, order.shipping].compact.each do |obj|
|
49
|
+
params.merge!(obj ? obj.filled_attributes : {})
|
50
|
+
end
|
49
51
|
|
50
52
|
AlphaCard.request(params, account).success?
|
51
53
|
end
|
52
54
|
end
|
53
|
-
end
|
55
|
+
end
|
data/lib/alpha_card/shipping.rb
CHANGED
@@ -16,7 +16,7 @@ module AlphaCard
|
|
16
16
|
|
17
17
|
##
|
18
18
|
# Overloaded <code>filled_attributes</code> method from
|
19
|
-
# <code>AlphaCard::AlphaCardObject</code>. All
|
19
|
+
# <code>AlphaCard::AlphaCardObject</code>. All attribute names of
|
20
20
|
# the Alpha Card Shipping object must start with "shipping_"
|
21
21
|
# prefix.
|
22
22
|
#
|
@@ -29,7 +29,7 @@ module AlphaCard
|
|
29
29
|
#
|
30
30
|
# #=> {shipping_firstname: 'John', shipping_state: 'NY'}
|
31
31
|
def filled_attributes
|
32
|
-
Hash[super.map {|k, v| ["shipping_#{k}".to_sym, v] }]
|
32
|
+
Hash[super.map { |k, v| ["shipping_#{k}".to_sym, v] }]
|
33
33
|
end
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
data/lib/alpha_card/utils.rb
CHANGED
@@ -40,7 +40,7 @@ module AlphaCard
|
|
40
40
|
# Parse query string to a <code>Hash</code> by breaking it up
|
41
41
|
# at the '&' and ';' characters.
|
42
42
|
#
|
43
|
-
# @param [String]
|
43
|
+
# @param [String] query
|
44
44
|
# query string
|
45
45
|
# @param [String] d
|
46
46
|
# delimiter for the params
|
@@ -56,12 +56,12 @@ module AlphaCard
|
|
56
56
|
#
|
57
57
|
# query = AlphaCard::Utils.parse_query("cars[]=Saab&cars[]=Audi")
|
58
58
|
# #=> {"cars[]"=>["Saab", "Audi"]}
|
59
|
-
def parse_query(
|
59
|
+
def parse_query(query, d = nil, &unescaper)
|
60
60
|
unescaper ||= method(:unescape)
|
61
61
|
|
62
62
|
params = {}
|
63
63
|
|
64
|
-
(
|
64
|
+
(query || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
|
65
65
|
next if p.empty?
|
66
66
|
k, v = p.split('=', 2).map(&unescaper)
|
67
67
|
|
@@ -80,4 +80,4 @@ module AlphaCard
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
|
-
end
|
83
|
+
end
|
data/lib/alpha_card/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alpha_card
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Bulaj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|