goog_currency 0.0.4 → 0.0.5
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.
- data/.travis.yml +1 -0
- data/README.md +10 -0
- data/goog_currency.gemspec +1 -1
- data/lib/goog_currency.rb +14 -17
- data/lib/goog_currency/version.rb +1 -1
- data/spec/goog_currency_spec.rb +8 -2
- metadata +8 -8
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -30,6 +30,16 @@ Throws GoogCurrency::Exception in case of any error.
|
|
30
30
|
|
31
31
|
Throws GoogCurrency::NoMethodException if conversion method syntax is invalid.
|
32
32
|
|
33
|
+
## Ruby versions support
|
34
|
+
|
35
|
+
Supports Ruby 1.9.2 and 2.0.0
|
36
|
+
|
37
|
+
Ruby 1.8.7, has encoding issues.
|
38
|
+
|
39
|
+
## TODO
|
40
|
+
|
41
|
+
Fix for Ruby 1.8.7
|
42
|
+
|
33
43
|
## Contributing
|
34
44
|
|
35
45
|
1. Fork it
|
data/goog_currency.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["girish.sonawane@gmail.com"]
|
11
11
|
gem.description = %q{Ruby Gem for currency conversion using Google API}
|
12
12
|
gem.summary = %q{Simple Ruby interface to Google Currency API}
|
13
|
-
gem.add_runtime_dependency 'rest-client'
|
13
|
+
gem.add_runtime_dependency 'rest-client'
|
14
14
|
gem.add_runtime_dependency 'json'
|
15
15
|
|
16
16
|
gem.add_development_dependency "rspec", "~> 2.12.0"
|
data/lib/goog_currency.rb
CHANGED
@@ -1,39 +1,36 @@
|
|
1
1
|
require "goog_currency/version"
|
2
2
|
require 'rest_client'
|
3
3
|
require 'json'
|
4
|
-
|
4
|
+
|
5
5
|
module GoogCurrency
|
6
6
|
def self.method_missing(meth, *args)
|
7
7
|
from, to = meth.to_s.split("_to_")
|
8
|
-
|
8
|
+
|
9
9
|
if from.nil? or to.nil?
|
10
10
|
raise NoMethodException, "GoogCurrency accepts methods in 'usd_to_inr' or 'gbp_to_usd' format"
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
response = RestClient.get("http://www.google.com/ig/calculator?hl=en&q=#{args.first}#{from.upcase}=?#{to.upcase}").body
|
14
|
-
|
14
|
+
|
15
15
|
# response is not valid json
|
16
|
+
# Remove unicode character used as thousands separator by the Google API
|
17
|
+
encoding_options = {
|
18
|
+
:invalid => :replace, # Replace invalid byte sequences
|
19
|
+
:undef => :replace, # Replace anything not defined in ASCII
|
20
|
+
:replace => '' # Use a blank for those replacements
|
21
|
+
#:universal_newline => true # Always break lines with \n
|
22
|
+
}
|
23
|
+
response = response.encode(Encoding.find('ASCII'), encoding_options)
|
16
24
|
response.gsub!(/(lhs|rhs|error|icc)/, '"\1"')
|
17
25
|
response_hash = JSON.parse(response)
|
18
26
|
|
19
27
|
if response_hash['error'].nil? or response_hash['error'] == ''
|
20
|
-
|
21
|
-
# Remove unicode character used as thousands separator by the Google API
|
22
|
-
# Thanks to Nathan Long, http://stackoverflow.com/a/9420531
|
23
|
-
#
|
24
|
-
#encoding_options = {
|
25
|
-
#:invalid => :replace, # Replace invalid byte sequences
|
26
|
-
#:undef => :replace, # Replace anything not defined in ASCII
|
27
|
-
#:replace => '', # Use a blank for those replacements
|
28
|
-
#:universal_newline => true # Always break lines with \n
|
29
|
-
#}
|
30
|
-
#response_hash['rhs'].encode(Encoding.find('ASCII'), encoding_options).to_f
|
31
|
-
Iconv.conv('ASCII//IGNORE', 'UTF8', response_hash['rhs']).to_f
|
28
|
+
response_hash['rhs'].to_f
|
32
29
|
else
|
33
30
|
raise Exception, "An error occurred: #{response_hash['error']}"
|
34
31
|
end
|
35
32
|
end
|
36
|
-
|
33
|
+
|
37
34
|
class Exception < StandardError; end
|
38
35
|
class NoMethodException < StandardError; end
|
39
36
|
end
|
data/spec/goog_currency_spec.rb
CHANGED
@@ -10,7 +10,7 @@ VALID
|
|
10
10
|
valid100_response =<<-VALID_100
|
11
11
|
{lhs: "100 U.S. dollar",rhs: "5\u0080483.6587 Indian rupees",error: "",icc: true}
|
12
12
|
VALID_100
|
13
|
-
|
13
|
+
|
14
14
|
invalid_response =<<-INVALID
|
15
15
|
{lhs: "",rhs: "",error: "4",icc: false}
|
16
16
|
INVALID
|
@@ -34,6 +34,12 @@ describe "GoogCurrency" do
|
|
34
34
|
usd = GoogCurrency.usd_to_inr(100)
|
35
35
|
usd.should == 5483.6587
|
36
36
|
end
|
37
|
+
|
38
|
+
it "ignores new thousands separator correctly" do
|
39
|
+
# performs live api call, not possible to reproduce the string
|
40
|
+
# returned by the api
|
41
|
+
expect { GoogCurrency.usd_to_inr(100) }.to_not raise_error
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
describe "invalid currencies" do
|
@@ -52,4 +58,4 @@ describe "GoogCurrency" do
|
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
55
|
-
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goog_currency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -17,15 +17,15 @@ dependencies:
|
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: '0'
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ! '>='
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: '0'
|
29
29
|
prerelease: false
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: json
|
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
segments:
|
107
107
|
- 0
|
108
108
|
version: '0'
|
109
|
-
hash:
|
109
|
+
hash: 3862151153092687607
|
110
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
111
|
none: false
|
112
112
|
requirements:
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
segments:
|
116
116
|
- 0
|
117
117
|
version: '0'
|
118
|
-
hash:
|
118
|
+
hash: 3862151153092687607
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
121
|
rubygems_version: 1.8.25
|