fixer 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Fixer
2
+ ====
3
+
4
+ Fixer is a Ruby wrapper to the [current and historical foreign exchange rate feeds provided by the European Central Bank](http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html).
5
+
6
+ Implement your own caching.
7
+
8
+ Usage
9
+ -----
10
+
11
+ # Get daily rate
12
+ Fixer.get('daily')
13
+
14
+ # Get 90-day historical
15
+ Fixer.get('hist-90d')
16
+
17
+ # Get historical
18
+ Fixer.get('hist')
19
+
20
+ # It doesn't get simpler than this.
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ module Fixer
6
+ BASE_URL = 'http://www.ecb.europa.eu/stats/eurofxref/'
7
+
8
+ class << self
9
+ def daily
10
+ get('daily')
11
+ end
12
+
13
+ def historical
14
+ get('hist')
15
+ end
16
+
17
+ def historical_90
18
+ get('hist-90d')
19
+ end
20
+
21
+ private
22
+
23
+ def get(type)
24
+ url = BASE_URL + "eurofxref-#{type}.xml"
25
+ feed = open(url).read
26
+ doc = Nokogiri::XML(feed)
27
+ doc.xpath('/gesmes:Envelope/xmlns:Cube/xmlns:Cube', doc.root.namespaces).map do |snapshot|
28
+ {
29
+ :date => snapshot['time'],
30
+ :rates => snapshot.xpath('./xmlns:Cube').map do |fx|
31
+ {
32
+ :currency => fx['currency'],
33
+ :rate => fx['rate']
34
+ }
35
+ end
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Fixer
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fixer do
4
+ context ".download" do
5
+ it "downloads daily rates" do
6
+ rates = Fixer.daily
7
+ rates.size.should eql 1
8
+ rates.first.should have_key :date
9
+ rates.first.should have_key :rates
10
+ end
11
+
12
+ it "downloads 90-day historical" do
13
+ rates = Fixer.historical_90
14
+ # We should have more than 50 working days in a three-month period
15
+ rates.size.should > 50
16
+ rates.each do |rate|
17
+ rate.should have_key :date
18
+ rate.should have_key :rates
19
+ end
20
+ end
21
+
22
+ it "downloads historical" do
23
+ rates = Fixer.historical
24
+ # We should have a lot of working days in history
25
+ rates.size.should > 1000
26
+ rates.each do |rate|
27
+ rate.should have_key :date
28
+ rate.should have_key :rates
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "rspec"
4
+
5
+ require File.expand_path("../../lib/fixer", __FILE__)
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Hakan Ensari
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-06 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 4
30
+ - 0
31
+ version: 1.4.0
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - "="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 0
58
+ - 0
59
+ - rc
60
+ version: 2.0.0.rc
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: *id003
64
+ description: Fixer is a Ruby wrapper to the current and historical foreign exchange or FX rate feeds provided by the European Central Bank.
65
+ email:
66
+ - code@papercavalier.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files: []
72
+
73
+ files:
74
+ - lib/fixer/version.rb
75
+ - lib/fixer.rb
76
+ - LICENSE
77
+ - README.markdown
78
+ - spec/fixer_spec.rb
79
+ - spec/spec_helper.rb
80
+ has_rdoc: true
81
+ homepage: http://github.com/papercavalier/fixer
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --charset=UTF-8
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: -429173017695343870
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 1
105
+ - 3
106
+ - 7
107
+ version: 1.3.7
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: A Ruby wrapper to the European Central Bank exchange rate feeds
115
+ test_files:
116
+ - spec/fixer_spec.rb
117
+ - spec/spec_helper.rb