currency_wiz 0.0.1 → 0.0.2

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/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ lib/currency_wiz/config.rb
data/README.md CHANGED
@@ -18,7 +18,20 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- As of right now, you can only look up a country's code using the country name.
21
+ gem install currency_wiz
22
+
23
+ Example:
24
+
25
+ country = CurrencyWiz.get_code("Canada")
26
+
27
+ "CAD"
28
+
29
+ exchange_rate = CurrencyWiz.exchange_rate(country)
30
+
31
+ 1.020983
32
+
33
+ ## TODO
34
+ fix names for country code lookup
22
35
 
23
36
  ## Contributing
24
37
 
data/currency_wiz.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_dependency "httparty"
24
25
  end
@@ -1,3 +1,3 @@
1
1
  module CurrencyWiz
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/currency_wiz.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require "currency_wiz/version"
2
+ require_relative "./currency_wiz/config"
3
+
4
+ require 'httparty'
2
5
 
3
6
  module CurrencyWiz
4
7
  extend self
@@ -30,7 +33,7 @@ module CurrencyWiz
30
33
  "BWP"=> "Botswanan Pula",
31
34
  "BYR"=> "Belarusian Ruble",
32
35
  "BZD"=> "Belize Dollar",
33
- "CAD"=> "Canadian Dollar",
36
+ "CAD"=> "Canadian Dollar Canada",
34
37
  "CDF"=> "Congolese Franc",
35
38
  "CHF"=> "Swiss Franc",
36
39
  "CLF"=> "Chilean Unit of Account (UF)",
@@ -179,4 +182,21 @@ module CurrencyWiz
179
182
  end
180
183
  return "Invalid country name"
181
184
  end
185
+
186
+ def exchange_rate(country_code)
187
+ response = HTTParty.get("http://openexchangerates.org/api/latest.json?app_id=#{CurrencyWiz::Config::API_KEY}")
188
+
189
+ response["rates"].each do |k, v|
190
+ if k == country_code
191
+ return v
192
+ end
193
+ end
194
+
195
+ return nil
196
+
197
+ end
198
+
199
+
182
200
  end
201
+
202
+
@@ -16,4 +16,13 @@ describe CurrencyWiz do
16
16
  end
17
17
  end
18
18
 
19
+ describe "#exchange_rate" do
20
+ it "should return nil for an invalid country code" do
21
+ CurrencyWiz.exchange_rate("AAAA").should be_nil
22
+ end
23
+
24
+ it "should return an integer for a valid country code" do
25
+ CurrencyWiz.exchange_rate("USD").should_not be_nil
26
+ end
27
+ end
19
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: currency_wiz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-06-05 00:00:00.000000000 Z
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: httparty
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: A gem to get the current exchange rate. Sign up for an API key at https://openexchangerates.org/
63
79
  email:
64
80
  - scott.chiang1@gmail.com