open_exchange_rates 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a144239c7adf3916dba057f3eb01743f02c3bea2
4
+ data.tar.gz: 97349586862a5cb230ada7866986a950ca415efe
5
+ SHA512:
6
+ metadata.gz: d5968641119f615e0fe16a554fc659206c85037c5239bd42d469f7455007e29bc324596a2b7b265a19854cf0ca2d763b3cbaeb06be8ac1b07c8f28a603f9c00d
7
+ data.tar.gz: 3e7255bdb2b8ddda10c6c42c4428eba23c6d3230fd7b8a7dffe1ab57e56cdf8cefa86857565451c1cf6476253c9114408242dedb1fa6bc53143e4af41ae2a284
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # OpenExchangeRates
2
2
 
3
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/vlado/open_exchange_rates)
3
+ [![Code Climate](https://codeclimate.com/github/vlado/open_exchange_rates.png)](https://codeclimate.com/github/vlado/open_exchange_rates)
4
4
  [![Gem Version](https://badge.fury.io/rb/open_exchange_rates.png)](http://badge.fury.io/rb/open_exchange_rates)
5
5
 
6
6
  Ruby gem for currency conversion based on [Open Exchange Rates API](http://openexchangerates.org) - free / open source hourly-updated currency data for everybody
7
7
 
8
8
  ## Accuracy
9
9
 
10
- Please see [https://github.com/currencybot/open-exchange-rates/#accuracy](https://github.com/currencybot/open-exchange-rates/#accuracy) and/or [http://openexchangerates.org/documentation/#specification](http://openexchangerates.org/documentation/#specification)
10
+ Please see [https://github.com/josscrowcroft/open-exchange-rates#accuracy](https://github.com/josscrowcroft/open-exchange-rates#accuracy)
11
11
 
12
12
  ## Installation
13
13
 
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
 
26
26
  ## Configuration
27
27
 
28
- You will need App ID to use OpenExchangeRates, you can get one for free [here](https://openexchangerates.org/signup/). Wanna know [why App ID is needed](http://www.josscrowcroft.com/2012/projects/open-exchange-rates-update-the-partys-not-over-it-just-got-a-little-too-noisy/).
28
+ You will need App ID to use OpenExchangeRates, you can get one [here](https://openexchangerates.org/signup/) for [free](https://openexchangerates.org/signup/free). Wanna know [why App ID is needed](http://www.josscrowcroft.com/2012/projects/open-exchange-rates-update-the-partys-not-over-it-just-got-a-little-too-noisy/).
29
29
 
30
30
  **Option 1**
31
31
 
@@ -96,7 +96,15 @@ If you omit **:from** or **:to** option conversion will be related to base curre
96
96
  4. Push to the branch (`git push origin my-new-feature`)
97
97
  5. Create new Pull Request
98
98
 
99
+ ## Running tests
100
+
101
+ 1. Copy env.example to .env `cp env.example .env`
102
+ 2. Open `.env` and enter your API ID
103
+ 3. Run `rake`
104
+
105
+
99
106
  ## Licence and Terms
100
107
 
101
- Licence - [http://openexchangerates.org/license](http://openexchangerates.org/license)
102
- Terms - [http://openexchangerates.org/terms](http://openexchangerates.org/terms)
108
+ This project rocks and uses MIT-LICENSE.
109
+
110
+ Please check Open Exchange Rates API [license](http://openexchangerates.org/license) and [terms](http://openexchangerates.org/terms) also.
@@ -10,6 +10,13 @@ module OpenExchangeRates
10
10
  end
11
11
  end
12
12
 
13
+ class RateNotFoundError < StandardError
14
+ def initialize(from_curr, to_curr)
15
+ msg = "Rate not found for #{from_curr} => #{to_curr}"
16
+ super(msg)
17
+ end
18
+ end
19
+
13
20
  attr_reader :app_id
14
21
 
15
22
  def initialize(options = {})
@@ -32,6 +39,10 @@ module OpenExchangeRates
32
39
  from_curr = response.base_currency if from_curr.empty?
33
40
  to_curr = response.base_currency if to_curr.empty?
34
41
 
42
+ unless rates[from_curr] && rates[to_curr]
43
+ raise RateNotFoundError.new(from_curr, to_curr)
44
+ end
45
+
35
46
  if from_curr == to_curr
36
47
  rate = 1
37
48
  elsif from_curr == response.base_currency
@@ -1,3 +1,3 @@
1
1
  module OpenExchangeRates
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -14,9 +14,11 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "open_exchange_rates"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = OpenExchangeRates::VERSION
17
+ gem.license = "MIT"
17
18
 
18
19
  gem.add_dependency('yajl-ruby')
19
20
 
20
21
  gem.add_development_dependency('rr')
21
22
  gem.add_development_dependency('rake')
23
+ gem.add_development_dependency('dotenv')
22
24
  end
data/test/rates_test.rb CHANGED
@@ -181,8 +181,8 @@ class TestOpenExchangeRates < Test::Unit::TestCase
181
181
  assert_equal "USD", on_rates.base
182
182
 
183
183
  assert_equal 1, on_rates.rates["USD"]
184
- assert_equal 0.991118, on_rates.rates["AUD"]
185
- assert_equal 5.795542, on_rates.rates["HRK"]
184
+ assert_equal 0.989596, on_rates.rates["AUD"]
185
+ assert_equal 5.793188, on_rates.rates["HRK"]
186
186
  end
187
187
 
188
188
  def test_round
@@ -209,6 +209,18 @@ class TestOpenExchangeRates < Test::Unit::TestCase
209
209
  end
210
210
  end
211
211
 
212
+ def test_invalid_currency_code_fails_with_rate_not_found_error
213
+ fx = OpenExchangeRates::Rates.new
214
+
215
+ assert_raise(OpenExchangeRates::Rates::RateNotFoundError) do
216
+ fx.exchange_rate(:from => "???", :to => "AUD", :on => "2012-05-10")
217
+ end
218
+
219
+ assert_raise(OpenExchangeRates::Rates::RateNotFoundError) do
220
+ fx.exchange_rate(:from => "USD", :to => "???", :on => "2012-05-10")
221
+ end
222
+ end
223
+
212
224
  private
213
225
 
214
226
  def assets_root
data/test/test_helper.rb CHANGED
@@ -1,19 +1,13 @@
1
1
  require "rubygems"
2
2
  require "test/unit"
3
3
  require "rr"
4
+ require 'dotenv'
4
5
  require "open_exchange_rates"
5
6
 
6
7
  # Pick up ENV variables from .env file if exists
7
- dot_env_file_path = File.expand_path("../../.env", __FILE__)
8
- if File.exist?(dot_env_file_path)
9
- File.open(dot_env_file_path).each_line do |line|
10
- key, value = line.strip.split("=")
11
- ENV[key] = value unless key.nil? || value.nil?
12
- end
13
- end
8
+ Dotenv.load
14
9
 
15
10
  OpenExchangeRates.configuration.app_id = ENV['OPEN_EXCHANGE_RATES_APP_ID']
16
11
 
17
12
  class Test::Unit::TestCase
18
- include RR::Adapters::TestUnit
19
- end
13
+ end
metadata CHANGED
@@ -1,75 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: open_exchange_rates
3
- version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 0
10
- version: 0.4.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Vlado Cingel
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-01-14 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: yajl-ruby
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
26
17
  - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
32
20
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rr
36
21
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
40
31
  - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
46
34
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
49
42
  name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
50
49
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
54
59
  - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
60
62
  type: :development
61
- version_requirements: *id003
62
- description: Ruby library for Open Exchange Rates API - free / open source hourly-updated currency data for everybody
63
- email:
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Ruby library for Open Exchange Rates API - free / open source hourly-updated
70
+ currency data for everybody
71
+ email:
64
72
  - vladocingel@gmail.com
65
73
  executables: []
66
-
67
74
  extensions: []
68
-
69
75
  extra_rdoc_files: []
70
-
71
- files:
72
- - .gitignore
76
+ files:
77
+ - ".gitignore"
73
78
  - Gemfile
74
79
  - LICENSE
75
80
  - README.md
@@ -87,39 +92,30 @@ files:
87
92
  - test/rates_test.rb
88
93
  - test/test_helper.rb
89
94
  homepage: https://github.com/vlado/open_exchange_rates
90
- licenses: []
91
-
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
92
98
  post_install_message:
93
99
  rdoc_options: []
94
-
95
- require_paths:
100
+ require_paths:
96
101
  - lib
97
- required_ruby_version: !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
100
104
  - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
106
- required_rubygems_version: !ruby/object:Gem::Requirement
107
- none: false
108
- requirements:
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
109
  - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
- version: "0"
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
115
112
  requirements: []
116
-
117
113
  rubyforge_project:
118
- rubygems_version: 1.8.12
114
+ rubygems_version: 2.1.11
119
115
  signing_key:
120
- specification_version: 3
116
+ specification_version: 4
121
117
  summary: Ruby library for Open Exchange Rates API
122
- test_files:
118
+ test_files:
123
119
  - test/assets/2012-05-10.json
124
120
  - test/assets/latest.json
125
121
  - test/rates_test.rb