money-fixer-io 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d81fd4bcd190187d09ae4dfb34353f2085ac5248
4
- data.tar.gz: b62fb58ab92382d54fd48507ea52df941ae82db6
3
+ metadata.gz: c21f00db45612059aa6e22318ca1e0235575fb23
4
+ data.tar.gz: acc00e17238140e59115f630ede9e490535fd28d
5
5
  SHA512:
6
- metadata.gz: fcdb71085d4d6bc9e0ae99629180a56930bae9dd5df43b39c926c2dcd40382cf5f419a2e1196b5d1397e4ecae72cf98087a96bd31d9c4601d4fc0ea034918b0e
7
- data.tar.gz: 290d4f2f43125aebed80691728bd7433c7e1faace82c758b97d3f6dfe4e54ab61651795ffd7cbb4c136b1fef9e32ac9cf0efc2526644f1b6a7678f41f552bc3c
6
+ metadata.gz: cf258b0f407c631c21bf028b0552a107541c2381f15aa81d32a852e422ec5b1493b2e3d9b41f1cde3ad97efef24a23bffa2569544d9b345127a6edf15d9a5e69
7
+ data.tar.gz: 67d09df341bace5f6e626d6ed42169b20f5dbe94c9c9a2f9727b5a7846e97e8d4ff63dc888824aab85ed33b7ffb415d532adc63a1c033dcf1e0c190c1d40a03d
@@ -2,8 +2,7 @@ AllCops:
2
2
  DisplayCopNames: true
3
3
  DisplayStyleGuide: true
4
4
  Exclude:
5
- - db/schema.rb
6
- - spec/dummy/db/schema.rb
5
+ - money-fixer-io.gemspec
7
6
 
8
7
  # https://github.com/AtomLinter/linter-rubocop/issues/2
9
8
  Style/FileName:
data/Gemfile CHANGED
@@ -1,15 +1,14 @@
1
1
  source "https://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
3
+ ruby "2.3.1"
4
+
8
5
  group :development do
9
- gem "rspec", "~> 2.8.0"
6
+ gem "rspec", "3.5.0"
10
7
  gem "rdoc", "~> 3.12"
11
8
  gem "bundler", "~> 1.0"
12
9
  gem "jeweler", "2.1.1"
13
- gem "simplecov", ">= 0"
10
+
11
+ gem "money", "6.7.1"
12
+
14
13
  gem "rubocop", "0.43.0"
15
14
  end
@@ -6,8 +6,7 @@ GEM
6
6
  builder (3.2.2)
7
7
  descendants_tracker (0.0.4)
8
8
  thread_safe (~> 0.3, >= 0.3.1)
9
- diff-lcs (1.1.3)
10
- docile (1.1.5)
9
+ diff-lcs (1.2.5)
11
10
  faraday (0.9.2)
12
11
  multipart-post (>= 1.2, < 3)
13
12
  git (1.3.0)
@@ -19,6 +18,7 @@ GEM
19
18
  oauth2 (~> 1.0)
20
19
  hashie (3.4.6)
21
20
  highline (1.7.8)
21
+ i18n (0.7.0)
22
22
  jeweler (2.1.1)
23
23
  builder
24
24
  bundler (>= 1.0)
@@ -32,6 +32,9 @@ GEM
32
32
  json (1.8.3)
33
33
  jwt (1.5.6)
34
34
  mini_portile2 (2.1.0)
35
+ money (6.7.1)
36
+ i18n (>= 0.6.4, <= 0.7.0)
37
+ sixarm_ruby_unaccent (>= 1.1.1, < 2)
35
38
  multi_json (1.12.1)
36
39
  multi_xml (0.5.5)
37
40
  multipart-post (2.0.0)
@@ -53,14 +56,19 @@ GEM
53
56
  rake (11.3.0)
54
57
  rdoc (3.12.2)
55
58
  json (~> 1.4)
56
- rspec (2.8.0)
57
- rspec-core (~> 2.8.0)
58
- rspec-expectations (~> 2.8.0)
59
- rspec-mocks (~> 2.8.0)
60
- rspec-core (2.8.0)
61
- rspec-expectations (2.8.0)
62
- diff-lcs (~> 1.1.2)
63
- rspec-mocks (2.8.0)
59
+ rspec (3.5.0)
60
+ rspec-core (~> 3.5.0)
61
+ rspec-expectations (~> 3.5.0)
62
+ rspec-mocks (~> 3.5.0)
63
+ rspec-core (3.5.3)
64
+ rspec-support (~> 3.5.0)
65
+ rspec-expectations (3.5.0)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.5.0)
68
+ rspec-mocks (3.5.0)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.5.0)
71
+ rspec-support (3.5.0)
64
72
  rubocop (0.43.0)
65
73
  parser (>= 2.3.1.1, < 3.0)
66
74
  powerpack (~> 0.1)
@@ -69,11 +77,7 @@ GEM
69
77
  unicode-display_width (~> 1.0, >= 1.0.1)
70
78
  ruby-progressbar (1.8.1)
71
79
  semver (1.0.1)
72
- simplecov (0.12.0)
73
- docile (~> 1.1.0)
74
- json (>= 1.8, < 3)
75
- simplecov-html (~> 0.10.0)
76
- simplecov-html (0.10.0)
80
+ sixarm_ruby_unaccent (1.1.1)
77
81
  thread_safe (0.3.5)
78
82
  unicode-display_width (1.1.1)
79
83
 
@@ -83,10 +87,10 @@ PLATFORMS
83
87
  DEPENDENCIES
84
88
  bundler (~> 1.0)
85
89
  jeweler (= 2.1.1)
90
+ money (= 6.7.1)
86
91
  rdoc (~> 3.12)
87
- rspec (~> 2.8.0)
92
+ rspec (= 3.5.0)
88
93
  rubocop (= 0.43.0)
89
- simplecov
90
94
 
91
95
  BUNDLED WITH
92
96
  1.12.5
@@ -1,9 +1,9 @@
1
- = money-fixer-io
1
+ # money-fixer-io
2
2
 
3
3
  Description goes here.
4
4
 
5
- == Contributing to money-fixer-io
6
-
5
+ ## Contributing to money-fixer-io
6
+
7
7
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
8
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
9
  * Fork the project.
@@ -12,7 +12,7 @@ Description goes here.
12
12
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
13
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
14
 
15
- == Copyright
15
+ ## Copyright
16
16
 
17
17
  Copyright (c) 2016 kaspernj. See LICENSE.txt for
18
18
  further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -1,10 +1,8 @@
1
1
  require "money"
2
- require "money/rates_store/rate_removal_support"
3
2
  require "open-uri"
4
3
 
5
4
  class Money::Bank::FixerIo < Money::Bank::VariableExchange
6
5
  SERVICE_HOST = "api.fixer.io".freeze
7
- SERVICE_PATH = "/".freeze
8
6
 
9
7
  # @return [Hash] Stores the currently known rates.
10
8
  attr_reader :rates
@@ -34,9 +32,8 @@ class Money::Bank::FixerIo < Money::Bank::VariableExchange
34
32
  end
35
33
  end
36
34
 
37
- def initialize(*)
38
- super
39
- @store.extend Money::RatesStore::RateRemovalSupport
35
+ def cache
36
+ @@money_bank_fixer_io_cache ||= {} # rubocop:disable Style/ClassVars
40
37
  end
41
38
 
42
39
  ##
@@ -87,13 +84,24 @@ class Money::Bank::FixerIo < Money::Bank::VariableExchange
87
84
  expire_rates
88
85
 
89
86
  if args[:exchanged_at]
90
- fetch_rate(from, to, exchanged_at: args.fetch(:exchanged_at))
91
- raise "stub"
87
+ get_rate_with_exchange_rate(from, to, args)
92
88
  else
93
89
  store.get_rate(from, to) || store.add_rate(from, to, fetch_rate(from, to))
94
90
  end
95
91
  end
96
92
 
93
+ def get_rate_with_exchange_rate(from, to, args = {})
94
+ exchanged_at = args.fetch(:exchanged_at).strftime("%Y-%m-%d")
95
+
96
+ if cache[from] && cache[from][to] && cache[from][to][exchanged_at]
97
+ cache[from][to][exchanged_at]
98
+ else
99
+ cache[from] ||= {}
100
+ cache[from][to] ||= {}
101
+ cache[from][to][exchanged_at] = fetch_rate(from, to, exchanged_at: exchanged_at)
102
+ end
103
+ end
104
+
97
105
  ##
98
106
  # Flushes all the rates if they are expired.
99
107
  #
@@ -118,11 +126,12 @@ private
118
126
  #
119
127
  # @return [BigDecimal] The requested rate.
120
128
  def fetch_rate(from, to, args = {})
121
- from = Currency.wrap(from)
122
- to = Currency.wrap(to)
129
+ from = Money::Currency.wrap(from)
130
+ to = Money::Currency.wrap(to)
131
+ uri = build_uri(from, to, args)
123
132
 
124
- data = JSON.parse(build_uri(from, to, args).read)
125
- rate = data.fetch("rates").fetch(to)
133
+ data = JSON.parse(uri.read)
134
+ rate = data.fetch("rates").fetch(to.iso_code)
126
135
  rate = 1 / extract_rate(build_uri(to, from).read) if rate < 0.1
127
136
  rate
128
137
  end
@@ -134,13 +143,18 @@ private
134
143
  # @param [Currency] to The currency to convert to.
135
144
  #
136
145
  # @return [URI::HTTP]
137
- def build_uri(from, _to, _args = {})
146
+ def build_uri(from, _to, args = {})
147
+ if args[:exchanged_at]
148
+ path = "/#{args.fetch(:exchanged_at)}"
149
+ else
150
+ path = "/latest"
151
+ end
152
+
138
153
  query = "base=#{from.iso_code}"
139
- query << "&date=#{args.fetch(:exchange_at).strftime("%Y-%m-%D")}"
140
154
 
141
155
  uri = URI::HTTP.build(
142
156
  host: SERVICE_HOST,
143
- path: SERVICE_PATH,
157
+ path: path,
144
158
  query: query
145
159
  )
146
160
  uri
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: money-fixer-io 0.0.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "money-fixer-io"
9
+ s.version = "0.0.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["kaspernj"]
14
+ s.date = "2016-10-01"
15
+ s.description = "fixer.io support for money"
16
+ s.email = "k@spernj.org"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ ".rubocop.yml",
25
+ "Gemfile",
26
+ "Gemfile.lock",
27
+ "LICENSE.txt",
28
+ "README.md",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "lib/money-fixer-io.rb",
32
+ "money-fixer-io.gemspec",
33
+ "shippable.yml",
34
+ "spec/money-fixer-io_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = "http://github.com/kaspernj/money-fixer-io"
38
+ s.licenses = ["MIT"]
39
+ s.rubygems_version = "2.5.1"
40
+ s.summary = "fixer.io support for money"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 4
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<rspec>, ["= 3.5.0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["= 2.1.1"])
50
+ s.add_development_dependency(%q<money>, ["= 6.7.1"])
51
+ s.add_development_dependency(%q<rubocop>, ["= 0.43.0"])
52
+ else
53
+ s.add_dependency(%q<rspec>, ["= 3.5.0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
56
+ s.add_dependency(%q<jeweler>, ["= 2.1.1"])
57
+ s.add_dependency(%q<money>, ["= 6.7.1"])
58
+ s.add_dependency(%q<rubocop>, ["= 0.43.0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<rspec>, ["= 3.5.0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
64
+ s.add_dependency(%q<jeweler>, ["= 2.1.1"])
65
+ s.add_dependency(%q<money>, ["= 6.7.1"])
66
+ s.add_dependency(%q<rubocop>, ["= 0.43.0"])
67
+ end
68
+ end
69
+
@@ -0,0 +1,3 @@
1
+ script:
2
+ - bundle exec rspec
3
+ - bundle exec rubocop
@@ -1,7 +1,34 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
1
+ require "spec_helper"
2
2
 
3
- describe "MoneyFixerIo" do
4
- it "fails" do
5
- raise "hey buddy, you should probably rename this file and start specing for real"
3
+ describe Money::Bank::FixerIo do
4
+ let(:bank) { Money::Bank::FixerIo.new }
5
+ let(:currency_eur) { Money::Currency.new("EUR") }
6
+ let(:currency_dkk) { Money::Currency.new("DKK") }
7
+
8
+ describe "#get_rate" do
9
+ it "returns the right rates" do
10
+ result = bank.get_rate(currency_eur, currency_dkk, exchanged_at: Time.new(2004, 1, 1))
11
+ result = format("%.2f", result).to_f
12
+
13
+ expect(result).to eq 7.45
14
+
15
+ result = bank.get_rate(currency_eur, currency_dkk, exchanged_at: Time.new(2016, 1, 1))
16
+ result = format("%.2f", result).to_f
17
+
18
+ expect(result).to eq 7.46
19
+ end
20
+
21
+ it "does caching" do
22
+ bank.get_rate(currency_eur, currency_dkk, exchanged_at: Time.new(2004, 1, 1))
23
+
24
+ expect(bank.cache).to have_key currency_eur
25
+ expect(bank.cache.fetch(currency_eur)).to have_key currency_dkk
26
+ expect(bank.cache.fetch(currency_eur).fetch(currency_dkk)).to have_key "2004-01-01"
27
+
28
+ result = bank.cache.fetch(currency_eur).fetch(currency_dkk).fetch("2004-01-01")
29
+ result = format("%.2f", result).to_f
30
+
31
+ expect(result).to eq 7.45
32
+ end
6
33
  end
7
34
  end
@@ -1,19 +1,3 @@
1
- require "simplecov"
2
-
3
- module SimpleCov::Configuration
4
- def clean_filters
5
- @filters = []
6
- end
7
- end
8
-
9
- SimpleCov.configure do
10
- clean_filters
11
- load_adapter "test_frameworks"
12
- end
13
-
14
- ENV["COVERAGE"] && SimpleCov.start do
15
- add_filter "/.rvm/"
16
- end
17
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
18
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
19
3
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money-fixer-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2016-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.8.0
19
+ version: 3.5.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.8.0
26
+ version: 3.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.1.1
69
69
  - !ruby/object:Gem::Dependency
70
- name: simplecov
70
+ name: money
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 6.7.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 6.7.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +100,7 @@ executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files:
102
102
  - LICENSE.txt
103
- - README.rdoc
103
+ - README.md
104
104
  files:
105
105
  - ".document"
106
106
  - ".rspec"
@@ -108,10 +108,12 @@ files:
108
108
  - Gemfile
109
109
  - Gemfile.lock
110
110
  - LICENSE.txt
111
- - README.rdoc
111
+ - README.md
112
112
  - Rakefile
113
113
  - VERSION
114
114
  - lib/money-fixer-io.rb
115
+ - money-fixer-io.gemspec
116
+ - shippable.yml
115
117
  - spec/money-fixer-io_spec.rb
116
118
  - spec/spec_helper.rb
117
119
  homepage: http://github.com/kaspernj/money-fixer-io