google_currency 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +12 -0
- data/lib/money/bank/google_currency.rb +53 -10
- metadata +58 -87
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
Google Currency 1.1.0
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Features
|
5
|
+
--------
|
6
|
+
- Deprecated #get_google_rate, use #get_rate (thanks RMU Alumni)
|
7
|
+
|
8
|
+
Bugfixes
|
9
|
+
---------
|
10
|
+
- Fixed an issue when rates over 1000 did not parse correctly (thanks Brandon
|
11
|
+
Anderson)
|
12
|
+
|
1
13
|
Google Currency 1.0.3
|
2
14
|
=====================
|
3
15
|
|
@@ -5,6 +5,10 @@ require 'json'
|
|
5
5
|
class Money
|
6
6
|
module Bank
|
7
7
|
class GoogleCurrency < Money::Bank::VariableExchange
|
8
|
+
|
9
|
+
SERVICE_HOST = "www.google.com"
|
10
|
+
SERVICE_PATH = "/ig/calculator"
|
11
|
+
|
8
12
|
# @return [Hash] Stores the currently known rates.
|
9
13
|
attr_reader :rates
|
10
14
|
|
@@ -58,14 +62,13 @@ class Money
|
|
58
62
|
# @bank.get_rate(:USD, :EUR) #=> 0.776337241
|
59
63
|
def get_rate(from, to)
|
60
64
|
@mutex.synchronize{
|
61
|
-
@rates[rate_key_for(from, to)] ||=
|
65
|
+
@rates[rate_key_for(from, to)] ||= fetch_rate(from, to)
|
62
66
|
}
|
63
67
|
end
|
64
68
|
|
65
69
|
##
|
66
70
|
# Returns the requested rate after querying Google.
|
67
71
|
#
|
68
|
-
#
|
69
72
|
# @param [String, Symbol, Currency] from Currency to convert from
|
70
73
|
# @param [String, Symbol, Currency] to Currency to convert to
|
71
74
|
#
|
@@ -74,20 +77,60 @@ class Money
|
|
74
77
|
# @example
|
75
78
|
# @bank = GoogleCurrency.new #=> <Money::Bank::GoogleCurrency...>
|
76
79
|
# @bank.get_google_rate(:USD, :EUR) #=> 0.776337241
|
80
|
+
#
|
81
|
+
# @deprecated
|
77
82
|
def get_google_rate(from, to)
|
78
|
-
|
79
|
-
|
83
|
+
warn "#get_google_rate is deprecated, please use #get_rate"
|
84
|
+
fetch_rate(from, to)
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
80
88
|
|
81
|
-
|
89
|
+
##
|
90
|
+
# Queries for the requested rate and returns it.
|
91
|
+
#
|
92
|
+
# @param [String, Symbol, Currency] from Currency to convert from
|
93
|
+
# @param [String, Symbol, Currency] to Currency to convert to
|
94
|
+
#
|
95
|
+
# @return [Float] The requested rate.
|
96
|
+
def fetch_rate(from, to)
|
97
|
+
from, to = Currency.wrap(from), Currency.wrap(to)
|
98
|
+
|
99
|
+
data = build_uri(from, to).read
|
100
|
+
data = fix_response_json_data(data)
|
101
|
+
|
102
|
+
error = data['error']
|
103
|
+
raise UnknownRate unless error == '' || error == '0'
|
104
|
+
BigDecimal(data['rhs'].gsub(/[^\d\.]/, ''))
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Build a URI for the given arguments.
|
109
|
+
#
|
110
|
+
# @param [Currency] from The currency to convert from.
|
111
|
+
# @param [Currency] to The currency to convert to.
|
112
|
+
#
|
113
|
+
# @return [URI::HTTP]
|
114
|
+
def build_uri(from, to)
|
115
|
+
uri = URI::HTTP.build(
|
116
|
+
:host => SERVICE_HOST,
|
117
|
+
:path => SERVICE_PATH,
|
118
|
+
:query => "hl=en&q=1#{from.iso_code}%3D%3F#{to.iso_code}"
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Takes the invalid JSON returned by Google and fixes it.
|
124
|
+
#
|
125
|
+
# @param [String] data The JSON string to fix.
|
126
|
+
#
|
127
|
+
# @return [Hash]
|
128
|
+
def fix_response_json_data(data)
|
82
129
|
data.gsub!(/lhs:/, '"lhs":')
|
83
130
|
data.gsub!(/rhs:/, '"rhs":')
|
84
131
|
data.gsub!(/error:/, '"error":')
|
85
132
|
data.gsub!(/icc:/, '"icc":')
|
86
|
-
|
87
|
-
|
88
|
-
error = data['error']
|
89
|
-
raise UnknownRate unless error == '' || error == '0'
|
90
|
-
BigDecimal(data['rhs'].split(' ')[0])
|
133
|
+
JSON.parse(data)
|
91
134
|
end
|
92
135
|
end
|
93
136
|
end
|
metadata
CHANGED
@@ -1,95 +1,74 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_currency
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
version: 1.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease: !!null
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Shane Emmons
|
13
9
|
- Donald Ball
|
14
|
-
autorequire:
|
10
|
+
autorequire: !!null
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2011-02-08 00:00:00.000000000 -05:00
|
14
|
+
default_executable: !!null
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
22
17
|
name: rspec
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirement: &10381764 !ruby/object:Gem::Requirement
|
25
19
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
segments:
|
30
|
-
- 2
|
31
|
-
- 0
|
32
|
-
- 0
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
33
23
|
version: 2.0.0
|
34
24
|
type: :development
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: yard
|
38
25
|
prerelease: false
|
39
|
-
|
26
|
+
version_requirements: *10381764
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yard
|
29
|
+
requirement: &10381476 !ruby/object:Gem::Requirement
|
40
30
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
- 5
|
47
|
-
- 8
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
48
34
|
version: 0.5.8
|
49
35
|
type: :development
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: json
|
53
36
|
prerelease: false
|
54
|
-
|
37
|
+
version_requirements: *10381476
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: json
|
40
|
+
requirement: &10381176 !ruby/object:Gem::Requirement
|
55
41
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
segments:
|
60
|
-
- 1
|
61
|
-
- 4
|
62
|
-
- 0
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
63
45
|
version: 1.4.0
|
64
46
|
type: :development
|
65
|
-
version_requirements: *id003
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: money
|
68
47
|
prerelease: false
|
69
|
-
|
48
|
+
version_requirements: *10381176
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: money
|
51
|
+
requirement: &10380900 !ruby/object:Gem::Requirement
|
70
52
|
none: false
|
71
|
-
requirements:
|
53
|
+
requirements:
|
72
54
|
- - ~>
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
- 3
|
76
|
-
- 5
|
77
|
-
version: "3.5"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '3.5'
|
78
57
|
type: :runtime
|
79
|
-
|
80
|
-
|
81
|
-
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *10380900
|
60
|
+
description: GoogleCurrency extends Money::Bank::Base and gives you access to the
|
61
|
+
current Google Currency exchange rates.
|
62
|
+
email:
|
82
63
|
- semmons99+RubyMoney@gmail.com
|
83
64
|
- donald.ball@gmail.com
|
84
65
|
executables: []
|
85
|
-
|
86
66
|
extensions: []
|
87
|
-
|
88
|
-
extra_rdoc_files:
|
67
|
+
extra_rdoc_files:
|
89
68
|
- LICENSE
|
90
69
|
- README.md
|
91
70
|
- CHANGELOG.md
|
92
|
-
files:
|
71
|
+
files:
|
93
72
|
- lib/money/bank/google_currency.rb
|
94
73
|
- LICENSE
|
95
74
|
- README.md
|
@@ -97,36 +76,28 @@ files:
|
|
97
76
|
has_rdoc: true
|
98
77
|
homepage: http://rubymoney.github.com/google_currency
|
99
78
|
licenses: []
|
100
|
-
|
101
|
-
|
102
|
-
rdoc_options:
|
79
|
+
post_install_message: !!null
|
80
|
+
rdoc_options:
|
103
81
|
- --charset=UTF-8
|
104
|
-
require_paths:
|
82
|
+
require_paths:
|
105
83
|
- lib
|
106
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
85
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
|
112
|
-
|
113
|
-
version: "0"
|
114
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
91
|
none: false
|
116
|
-
requirements:
|
117
|
-
- -
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
segments:
|
120
|
-
- 1
|
121
|
-
- 3
|
122
|
-
- 7
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
123
95
|
version: 1.3.7
|
124
|
-
requirements:
|
96
|
+
requirements:
|
125
97
|
- json
|
126
|
-
rubyforge_project:
|
127
|
-
rubygems_version: 1.
|
128
|
-
signing_key:
|
98
|
+
rubyforge_project: !!null
|
99
|
+
rubygems_version: 1.5.0
|
100
|
+
signing_key: !!null
|
129
101
|
specification_version: 3
|
130
102
|
summary: Access the Google Currency exchange rate data.
|
131
103
|
test_files: []
|
132
|
-
|