active_utils 2.0.2 → 2.1.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/Gemfile +2 -0
- data/README.md +1 -0
- data/lib/active_utils/common/currency_code.rb +50 -0
- data/lib/active_utils/common/network_connection_retries.rb +5 -4
- data/lib/active_utils/version.rb +1 -1
- data/lib/active_utils.rb +1 -0
- data/test/unit/currency_code_test.rb +31 -0
- metadata +17 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 180170853acf22a66e870a16f3081c97ccf1e7c4
|
4
|
+
data.tar.gz: 5dc60932763444c415f3cbffe1674daf606b9eb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29f63bd7f1ab24c9f97175354540cbc93a9572217daf94fde33bef40c9091af9dab98c971cd2b50a683e89eea6ffaca24517ab7263df0d2617f4c1a4a7d23d10
|
7
|
+
data.tar.gz: e81f8f53400e9fef54fe7460bfb7ea46801fccae99bce30d6861e51cd9b269b9c50cbccecfcd8de6dd43e163bd09fe4324aa16075c7e556bbc0a0fb4d3c126e7
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -13,3 +13,4 @@ Active Utils extracts commonly used modules and classes used by [Active Merchant
|
|
13
13
|
* Utils - common utils such as uid generator
|
14
14
|
* Validateable - module used for making models validateable
|
15
15
|
* NetworkConnectionRetries - module for retrying network connections when connection errors occur
|
16
|
+
* CurrencyCode - ensure currency codes are ISO, and convert colloquial codes to ISO.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module ActiveMerchant
|
2
|
+
class InvalidCurrencyCodeError < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class CurrencyCode
|
6
|
+
ISO_CURRENCIES = [
|
7
|
+
"AED", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD",
|
8
|
+
"BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CHF", "CLP", "CNY", "COP", "CRC",
|
9
|
+
"CZK", "DKK", "DOP", "DZD", "EGP", "ETB", "EUR", "FJD", "GBP", "GEL", "GHS", "GMD", "GTQ", "GYD",
|
10
|
+
"HKD", "HNL", "HRK", "HUF", "IDR", "ILS", "INR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS",
|
11
|
+
"KHR", "KRW", "KWD", "KYD", "KZT", "LBP", "LKR", "LTL", "LVL", "MAD", "MDL", "MGA", "MKD", "MMK",
|
12
|
+
"MNT", "MOP", "MUR", "MVR", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR",
|
13
|
+
"PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SCR", "SEK",
|
14
|
+
"SGD", "STD", "SYP", "THB", "TND", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "VEF",
|
15
|
+
"VND", "VUV", "WST", "XAF", "XCD", "XOF", "XPF", "ZAR", "ZMW"
|
16
|
+
]
|
17
|
+
|
18
|
+
NON_ISO_TO_ISO = {
|
19
|
+
"ARN" => "ARS",
|
20
|
+
"AZM" => "AZN",
|
21
|
+
"CHP" => "CLP",
|
22
|
+
"DHS" => "AED",
|
23
|
+
"ECD" => "XCD",
|
24
|
+
"GHC" => "GHS",
|
25
|
+
"JAD" => "JMD",
|
26
|
+
"JYE" => "JPY",
|
27
|
+
"KUD" => "KWD",
|
28
|
+
"MZM" => "MZN",
|
29
|
+
"NTD" => "TWD",
|
30
|
+
"NMP" => "MXN",
|
31
|
+
"RDD" => "DOP",
|
32
|
+
"RMB" => "CNY",
|
33
|
+
"SFR" => "CHF",
|
34
|
+
"SID" => "SGD",
|
35
|
+
"UKL" => "GBP",
|
36
|
+
"WON" => "KRW"
|
37
|
+
}
|
38
|
+
|
39
|
+
def self.standardize(code)
|
40
|
+
code = code.upcase
|
41
|
+
|
42
|
+
return code if is_iso?(code)
|
43
|
+
NON_ISO_TO_ISO[code] || raise(InvalidCurrencyCodeError, "#{code} is not an ISO currency, nor can it be converted to one.")
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.is_iso?(code)
|
47
|
+
ISO_CURRENCIES.include? code
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -2,10 +2,11 @@ module ActiveMerchant
|
|
2
2
|
module NetworkConnectionRetries
|
3
3
|
DEFAULT_RETRIES = 3
|
4
4
|
DEFAULT_CONNECTION_ERRORS = {
|
5
|
-
EOFError
|
6
|
-
Errno::ECONNRESET
|
7
|
-
Timeout::Error
|
8
|
-
Errno::ETIMEDOUT
|
5
|
+
EOFError => "The remote server dropped the connection",
|
6
|
+
Errno::ECONNRESET => "The remote server reset the connection",
|
7
|
+
Timeout::Error => "The connection to the remote server timed out",
|
8
|
+
Errno::ETIMEDOUT => "The connection to the remote server timed out",
|
9
|
+
OpenSSL::SSL::SSLError => "The SSL connection to the remote server could not be established"
|
9
10
|
}
|
10
11
|
|
11
12
|
def self.included(base)
|
data/lib/active_utils/version.rb
CHANGED
data/lib/active_utils.rb
CHANGED
@@ -17,4 +17,5 @@ module ActiveMerchant
|
|
17
17
|
autoload :RequiresParameters, 'active_utils/common/requires_parameters'
|
18
18
|
autoload :Utils, 'active_utils/common/utils'
|
19
19
|
autoload :Validateable, 'active_utils/common/validateable'
|
20
|
+
autoload :CurrencyCode, 'active_utils/common/currency_code'
|
20
21
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CurrencyCodeTest < Test::Unit::TestCase
|
4
|
+
def test_is_iso_should_return_true_for_iso_currencies
|
5
|
+
assert CurrencyCode.is_iso?('CAD')
|
6
|
+
assert CurrencyCode.is_iso?('USD')
|
7
|
+
assert CurrencyCode.is_iso?('TWD')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_is_iso_should_return_false_for_non_iso_currencies
|
11
|
+
assert !CurrencyCode.is_iso?('NTD')
|
12
|
+
assert !CurrencyCode.is_iso?('RMB')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_standardize_should_not_change_iso_currencies
|
16
|
+
assert_equal 'CAD', CurrencyCode.standardize('CAD')
|
17
|
+
assert_equal 'USD', CurrencyCode.standardize('usd')
|
18
|
+
assert_equal 'TWD', CurrencyCode.standardize('TWD')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_standardize_should_convert_known_non_iso_to_iso
|
22
|
+
assert_equal 'TWD', CurrencyCode.standardize('NTD')
|
23
|
+
assert_equal 'CNY', CurrencyCode.standardize('rmb')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_standardize_should_raise_for_unknwon_currencies
|
27
|
+
assert_raise InvalidCurrencyCodeError do
|
28
|
+
CurrencyCode.standardize('Not Real')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.3.11
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.3.11
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: i18n
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mocha
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description:
|
@@ -73,7 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
77
77
|
- Gemfile
|
78
78
|
- MIT-LICENSE
|
79
79
|
- README.md
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/active_utils.rb
|
83
83
|
- lib/active_utils/common/connection.rb
|
84
84
|
- lib/active_utils/common/country.rb
|
85
|
+
- lib/active_utils/common/currency_code.rb
|
85
86
|
- lib/active_utils/common/error.rb
|
86
87
|
- lib/active_utils/common/network_connection_retries.rb
|
87
88
|
- lib/active_utils/common/post_data.rb
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- test/unit/connection_test.rb
|
96
97
|
- test/unit/country_code_test.rb
|
97
98
|
- test/unit/country_test.rb
|
99
|
+
- test/unit/currency_code_test.rb
|
98
100
|
- test/unit/network_connection_retries_test.rb
|
99
101
|
- test/unit/post_data_test.rb
|
100
102
|
- test/unit/posts_data_test.rb
|
@@ -109,17 +111,17 @@ require_paths:
|
|
109
111
|
- lib
|
110
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
113
|
requirements:
|
112
|
-
- -
|
114
|
+
- - ">="
|
113
115
|
- !ruby/object:Gem::Version
|
114
116
|
version: '0'
|
115
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
118
|
requirements:
|
117
|
-
- -
|
119
|
+
- - ">="
|
118
120
|
- !ruby/object:Gem::Version
|
119
121
|
version: '0'
|
120
122
|
requirements: []
|
121
123
|
rubyforge_project: active_utils
|
122
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.2.2
|
123
125
|
signing_key:
|
124
126
|
specification_version: 4
|
125
127
|
summary: Common utils used by active_merchant, active_fulfillment, and active_shipping
|
@@ -128,6 +130,7 @@ test_files:
|
|
128
130
|
- test/unit/connection_test.rb
|
129
131
|
- test/unit/country_code_test.rb
|
130
132
|
- test/unit/country_test.rb
|
133
|
+
- test/unit/currency_code_test.rb
|
131
134
|
- test/unit/network_connection_retries_test.rb
|
132
135
|
- test/unit/post_data_test.rb
|
133
136
|
- test/unit/posts_data_test.rb
|