exchange 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/lib/exchange/base.rb +1 -1
- data/lib/exchange/configuration.rb +1 -1
- data/lib/exchange/external_api/base.rb +1 -6
- data/lib/exchange/external_api/ecb.rb +1 -1
- data/lib/exchange/external_api/open_exchange_rates.rb +1 -1
- data/lib/exchange/external_api/xavier_media.rb +1 -1
- data/spec/exchange/configuration_spec.rb +2 -2
- data/spec/exchange/external_api/call_spec.rb +5 -5
- data/spec/exchange/external_api/configuration_spec.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -16,8 +16,8 @@ Just install it as a gem
|
|
16
16
|
Then require it
|
17
17
|
require 'exchange'
|
18
18
|
|
19
|
-
===
|
20
|
-
|
19
|
+
=== Production Ready
|
20
|
+
Exchange is production-ready. It is in use on {rightclearing.com}[http://rightclearing.com], a music licensing service worth noticing. If you use this gem in production, {drop a note}[mailto:beat.richartz@gmail.com] so your app can be listed here.
|
21
21
|
|
22
22
|
== Features
|
23
23
|
|
data/lib/exchange/base.rb
CHANGED
@@ -99,10 +99,6 @@ module Exchange
|
|
99
99
|
# @return [Exchange::Cache] The cache subclass
|
100
100
|
attr_reader :cache
|
101
101
|
|
102
|
-
# @attr_reader
|
103
|
-
# @return [Exchange::API] The api subclass
|
104
|
-
attr_reader :api
|
105
|
-
|
106
102
|
# @attr_reader
|
107
103
|
# @return [Exchange::Helper] The Exchange Helper
|
108
104
|
attr_reader :helper
|
@@ -112,7 +108,6 @@ module Exchange
|
|
112
108
|
#
|
113
109
|
def initialize *args
|
114
110
|
@cache = Exchange.configuration.cache.subclass
|
115
|
-
@api = Exchange.configuration.api.subclass
|
116
111
|
@helper = Exchange::Helper.instance
|
117
112
|
|
118
113
|
super *args
|
@@ -130,7 +125,7 @@ module Exchange
|
|
130
125
|
# #=> 1.232231231
|
131
126
|
#
|
132
127
|
def rate(from, to, opts={})
|
133
|
-
rate = cache.cached(
|
128
|
+
rate = cache.cached(self.class, opts.merge(:key_for => [from, to])) do
|
134
129
|
update(opts)
|
135
130
|
|
136
131
|
rate_from = rates[from]
|
@@ -123,7 +123,7 @@ module Exchange
|
|
123
123
|
# @version 0.6
|
124
124
|
#
|
125
125
|
def call_opts time
|
126
|
-
{:format => :xml, :at => time, :cache => :file, :cache_period => time >= Time.now - 90 * 86400 ? :daily : :monthly}
|
126
|
+
{:format => :xml, :at => time, :api => self.class, :cache => :file, :cache_period => time >= Time.now - 90 * 86400 ? :daily : :monthly}
|
127
127
|
end
|
128
128
|
|
129
129
|
end
|
@@ -27,7 +27,7 @@ module Exchange
|
|
27
27
|
def update(opts={})
|
28
28
|
time = helper.assure_time(opts[:at])
|
29
29
|
|
30
|
-
Call.new(api_url(time), :at => time) do |result|
|
30
|
+
Call.new(api_url(time), :at => time, :api => self.class) do |result|
|
31
31
|
@base = result['base'].downcase.to_sym
|
32
32
|
@rates = extract_rates(result)
|
33
33
|
@timestamp = result['timestamp'].to_i
|
@@ -27,7 +27,7 @@ module Exchange
|
|
27
27
|
time = helper.assure_time(opts[:at], :default => :now)
|
28
28
|
api_url = api_url(time)
|
29
29
|
|
30
|
-
Call.new(api_url, api_opts(opts.merge(:at => time))) do |result|
|
30
|
+
Call.new(api_url, api_opts(opts.merge(:at => time, :api => self.class))) do |result|
|
31
31
|
@base = extract_base_currency result
|
32
32
|
@rates = extract_rates result
|
33
33
|
@timestamp = extract_timestamp result
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
describe "Exchange::Configuration" do
|
5
5
|
let(:subject) { Exchange::Configuration.new }
|
6
6
|
it "should have a standard configuration" do
|
7
|
-
subject.api.retries.should ==
|
7
|
+
subject.api.retries.should == 7
|
8
8
|
subject.api.subclass.should == Exchange::ExternalAPI::XavierMedia
|
9
9
|
subject.cache.subclass.should == Exchange::Cache::Memory
|
10
10
|
subject.cache.host.should be_nil
|
@@ -67,7 +67,7 @@ describe "Exchange::Configuration" do
|
|
67
67
|
it "should restore the defaults" do
|
68
68
|
subject.reset
|
69
69
|
subject.api.subclass.should == Exchange::ExternalAPI::XavierMedia
|
70
|
-
subject.api.retries.should ==
|
70
|
+
subject.api.retries.should == 7
|
71
71
|
subject.api.app_id.should be_nil
|
72
72
|
subject.api.fallback.should == [Exchange::ExternalAPI::Ecb]
|
73
73
|
subject.cache.subclass.should == Exchange::Cache::Memory
|
@@ -15,7 +15,7 @@ describe "Exchange::ExternalAPI::Call" do
|
|
15
15
|
describe "initialization" do
|
16
16
|
context "with a json api" do
|
17
17
|
before(:each) do
|
18
|
-
mock_api('JSON_API', fixture('api_responses/example_json_api.json'),
|
18
|
+
mock_api('JSON_API', fixture('api_responses/example_json_api.json'), 7)
|
19
19
|
end
|
20
20
|
it "should call the api and yield a block with the result" do
|
21
21
|
Exchange::ExternalAPI::Call.new('JSON_API') do |result|
|
@@ -34,7 +34,7 @@ describe "Exchange::ExternalAPI::Call" do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
it "should raise if the maximum recall size is reached" do
|
37
|
-
@uri_mock.should_receive(:open).at_most(
|
37
|
+
@uri_mock.should_receive(:open).at_most(7).times.and_return do
|
38
38
|
raise OpenURI::HTTPError.new('404', 'URI')
|
39
39
|
end
|
40
40
|
lambda { Exchange::ExternalAPI::Call.new('JSON_API') }.should raise_error(Exchange::ExternalAPI::APIError)
|
@@ -42,7 +42,7 @@ describe "Exchange::ExternalAPI::Call" do
|
|
42
42
|
end
|
43
43
|
context "with socket errors" do
|
44
44
|
it "should raise an error immediately" do
|
45
|
-
@uri_mock.should_receive(:open).at_most(
|
45
|
+
@uri_mock.should_receive(:open).at_most(7).times.and_raise(SocketError)
|
46
46
|
lambda { Exchange::ExternalAPI::Call.new('JSON_API') }.should raise_error(Exchange::ExternalAPI::APIError)
|
47
47
|
end
|
48
48
|
end
|
@@ -50,7 +50,7 @@ describe "Exchange::ExternalAPI::Call" do
|
|
50
50
|
end
|
51
51
|
context "with an xml api" do
|
52
52
|
before(:each) do
|
53
|
-
mock_api('XML_API', fixture('api_responses/example_xml_api.xml'),
|
53
|
+
mock_api('XML_API', fixture('api_responses/example_xml_api.xml'), 7)
|
54
54
|
end
|
55
55
|
it "should call the api and yield a block with the result" do
|
56
56
|
Exchange::ExternalAPI::Call.new('XML_API', :format => :xml) do |result|
|
@@ -69,7 +69,7 @@ describe "Exchange::ExternalAPI::Call" do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
it "should raise if the maximum recall size is reached" do
|
72
|
-
@uri_mock.should_receive(:open).at_most(
|
72
|
+
@uri_mock.should_receive(:open).at_most(7).times.and_return do
|
73
73
|
raise OpenURI::HTTPError.new('404', 'URI')
|
74
74
|
end
|
75
75
|
lambda { Exchange::ExternalAPI::Call.new('XML_API') }.should raise_error(Exchange::ExternalAPI::APIError)
|
@@ -59,7 +59,7 @@ describe "Exchange::ExternalAPI::Configuration" do
|
|
59
59
|
it "should restore the defaults" do
|
60
60
|
subject.reset
|
61
61
|
subject.subclass.should == Exchange::ExternalAPI::XavierMedia
|
62
|
-
subject.retries.should ==
|
62
|
+
subject.retries.should == 7
|
63
63
|
subject.app_id.should be_nil
|
64
64
|
subject.fallback.should == [Exchange::ExternalAPI::Ecb]
|
65
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.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-
|
12
|
+
date: 2013-04-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|