fxpotato 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +6 -0
- data/lib/fxpotato/paths.rb +5 -0
- data/lib/fxpotato/rate_fetcher.rb +21 -0
- data/lib/fxpotato/rate_store.rb +2 -10
- data/lib/fxpotato/version.rb +1 -1
- data/lib/fxpotato/xml_repo.rb +20 -0
- data/lib/fxpotato.rb +14 -5
- metadata +4 -2
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5dc3b4c256444b86d08ce4cf7a31d3e764e5678
|
4
|
+
data.tar.gz: 619de4799993b072db5461327ba7ec82cc8fd57b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0231eaf96ff38a710c06ff0c8ad934652f128666ef7b594c9e43f5c242b1322eeafced918d3e52f48285f362729ef4cb1d1f666d9117a605f8818b803dc2f4f
|
7
|
+
data.tar.gz: 445e77fc2ba6d65143ac75b3d8dd1f01e8ef8e5a3550ebb28aa900a7627397d7318fe572bf47bb2165fd977630c121d1bd889130424f4bfbe08376faae93b40d
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
|
+
require 'fxpotato'
|
3
4
|
|
4
5
|
Rake::TestTask.new(:test) do |t|
|
5
6
|
t.libs << 'test'
|
@@ -7,6 +8,11 @@ Rake::TestTask.new(:test) do |t|
|
|
7
8
|
t.test_files = FileList['test/**/*_test.rb']
|
8
9
|
end
|
9
10
|
|
11
|
+
desc "Download new exchange rate data"
|
12
|
+
task :fetch_new_rates do
|
13
|
+
FxPotato.fetch_new_rates
|
14
|
+
end
|
15
|
+
|
10
16
|
desc "Bump version and release gem"
|
11
17
|
task :bump_release do
|
12
18
|
sh %{ gem bump && rake release }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module FxPotato
|
4
|
+
class RateFetcher
|
5
|
+
def self.fetch(source_url, destination)
|
6
|
+
uri = URI(source_url)
|
7
|
+
|
8
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
9
|
+
request = Net::HTTP::Get.new uri
|
10
|
+
|
11
|
+
http.request request do |response|
|
12
|
+
open destination, 'w' do |io|
|
13
|
+
response.read_body do |chunk|
|
14
|
+
io.write chunk
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/fxpotato/rate_store.rb
CHANGED
@@ -1,15 +1,7 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
|
3
1
|
module FxPotato
|
4
2
|
class RateStore
|
5
|
-
def
|
6
|
-
|
7
|
-
@data.remove_namespaces!
|
8
|
-
end
|
9
|
-
|
10
|
-
def get(date, currency)
|
11
|
-
query = "//Cube[@time=\'#{date.to_s}\']//Cube[@currency=\'#{currency}\']"
|
12
|
-
@data.at_xpath(query)["rate"].to_f
|
3
|
+
def self.get(repo, date, currency)
|
4
|
+
repo.find(date, currency)
|
13
5
|
end
|
14
6
|
end
|
15
7
|
end
|
data/lib/fxpotato/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module FxPotato
|
4
|
+
class XmlRepo
|
5
|
+
def initialize(data)
|
6
|
+
@data = Nokogiri::XML(data || local_data)
|
7
|
+
@data.remove_namespaces!
|
8
|
+
end
|
9
|
+
|
10
|
+
def local_data
|
11
|
+
source_file = File.join(DATA_DIRECTORY, DATA_FILE)
|
12
|
+
File.open(source_file)
|
13
|
+
end
|
14
|
+
|
15
|
+
def find(date, currency)
|
16
|
+
query = "//Cube[@time=\'#{date.to_s}\']//Cube[@currency=\'#{currency}\']"
|
17
|
+
@data.at_xpath(query)["rate"].to_f
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/fxpotato.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
require 'fxpotato/version'
|
2
|
-
require 'fxpotato/
|
2
|
+
require 'fxpotato/paths'
|
3
|
+
require 'fxpotato/xml_repo'
|
3
4
|
require 'fxpotato/rate_store'
|
5
|
+
require 'fxpotato/rate_fetcher'
|
6
|
+
require 'fxpotato/rate_calculator'
|
4
7
|
|
5
8
|
module FxPotato
|
6
9
|
def self.at(date, from_currency, to_currency)
|
7
10
|
raise "Must specify date" if date.nil?
|
8
11
|
raise "Must specify from_currency" if from_currency.nil?
|
9
12
|
raise "Must specify to_currency" if to_currency.nil?
|
10
|
-
from =
|
11
|
-
to =
|
13
|
+
from = RateStore.get(@repo, date, from_currency)
|
14
|
+
to = RateStore.get(@repo, date, to_currency)
|
12
15
|
RateCalculator.calculate(from, to)
|
13
16
|
end
|
14
17
|
|
18
|
+
def self.fetch_new_rates
|
19
|
+
Dir.mkdir DATA_DIRECTORY if !File.exists? DATA_DIRECTORY
|
20
|
+
destination = File.join(DATA_DIRECTORY, DATA_FILE)
|
21
|
+
RateFetcher.fetch(DATA_SOURCE_URL, destination)
|
22
|
+
end
|
23
|
+
|
15
24
|
module_function
|
16
|
-
def
|
17
|
-
def
|
25
|
+
def repo; @repo ||= XmlRepo end
|
26
|
+
def repo= v; @repo = v end
|
18
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fxpotato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liam Stupid Name Humphreys
|
@@ -90,7 +90,6 @@ extensions: []
|
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
92
92
|
- ".gitignore"
|
93
|
-
- ".travis.yml"
|
94
93
|
- CODE_OF_CONDUCT.md
|
95
94
|
- Dockerfile
|
96
95
|
- Gemfile
|
@@ -101,9 +100,12 @@ files:
|
|
101
100
|
- bin/setup
|
102
101
|
- fxpotato.gemspec
|
103
102
|
- lib/fxpotato.rb
|
103
|
+
- lib/fxpotato/paths.rb
|
104
104
|
- lib/fxpotato/rate_calculator.rb
|
105
|
+
- lib/fxpotato/rate_fetcher.rb
|
105
106
|
- lib/fxpotato/rate_store.rb
|
106
107
|
- lib/fxpotato/version.rb
|
108
|
+
- lib/fxpotato/xml_repo.rb
|
107
109
|
- shippable.yml
|
108
110
|
homepage: https://github.com/Angry-Potato/fxpotato
|
109
111
|
licenses:
|