active_exchange 0.7.0 → 1.0.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 1.0.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_exchange}
8
- s.version = "0.7.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["pjammer"]
12
- s.date = %q{2011-05-18}
12
+ s.date = %q{2011-07-13}
13
13
  s.description = %q{Foreign Exchange for your Rails app.}
14
14
  s.email = %q{philipjingram@yahoo.com}
15
15
  s.extra_rdoc_files = [
@@ -26,18 +26,16 @@ Gem::Specification.new do |s|
26
26
  "app/models/exchange_rate.rb",
27
27
  "db/migrate/20091021192708_create_exchange_rates.rb",
28
28
  "lib/active_exchange.rb",
29
- "lib/active_exchange/active_exchange.rb",
30
29
  "lib/tasks/daily_exchange_rates.rake",
31
30
  "test/helper.rb",
32
31
  "test/test_active_exchange.rb"
33
32
  ]
34
33
  s.homepage = %q{http://github.com/pjammer/active_exchange}
35
34
  s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.3.7}
35
+ s.rubygems_version = %q{1.6.2}
37
36
  s.summary = %q{Foreign Exchange for your Rails app}
38
37
 
39
38
  if s.respond_to? :specification_version then
40
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
39
  s.specification_version = 3
42
40
 
43
41
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -1,8 +1,51 @@
1
- require 'active_exchange' if defined?(Rails) && Rails::VERSION::MAJOR == 3
1
+ require "cgi"
2
+ require "uri"
3
+ require "net/https"
4
+ require "rexml/document"
5
+ require "date"
2
6
  require 'rails'
3
7
 
4
8
  module ActiveExchange
5
9
  class Engine < Rails::Engine
6
10
 
7
11
  end
12
+ # Originially massaged from the web post of http://geoff.evason.name/2008/10/27/simple-currency-conversion-rate-api-consumption-for-ruby-rails/
13
+ # The active_exchange gem is used to go out to XavierMedia and pull quotes for the currencies they offer.
14
+
15
+ # We'll need to have a task to look for new data and parse it into DB, to cut down calls.
16
+ def self.retrieve_data(date = Date.today - 1)
17
+ url = URI.parse("http://api.finance.xaviermedia.com/api/#{date.year}/#{date.strftime("%m")}/#{date.strftime("%d")}.xml")
18
+ resp = Net::HTTP.get(url)
19
+ xml = REXML::Document.new(resp)
20
+ end
21
+
22
+ def self.get_daily_data
23
+ #Get data
24
+ daily_rates = ActiveExchange.retrieve_data
25
+ #put into database. Run the migrations, obviously, before you do this.
26
+ if daily_rates.root.attributes["responsecode"] == "200"
27
+ daily_rates.elements.each("//exchange_rates/fx") { |element|
28
+ ExchangeRate.create(:currency => element.elements[1].text, :rate => element.elements[2].text)
29
+ }
30
+ end
31
+ end
32
+
33
+ #used to find an exchange rate on a certain day. this will make a call to the api.
34
+ def self.exchange_rate_on(date, currency_from = "USD", currency_to = "AUD")
35
+ xml = retrieve_data(date)
36
+ us_to_eur = 1.0
37
+ au_to_eur = 1.0
38
+ xml.elements.each("//exchange_rates/fx") { |el|
39
+ if el.elements[1].text == currency_from
40
+ us_to_eur = el.elements[2].text.to_f rescue 1.0
41
+ end
42
+ if el.elements[1].text == currency_to
43
+ au_to_eur = el.elements[2].text.to_f rescue 1.0
44
+ end
45
+ }
46
+
47
+ return us_to_eur/au_to_eur
48
+ end
8
49
  end
50
+
51
+ require 'active_exchange' if defined?(Rails) && Rails::VERSION::MAJOR == 3
@@ -8,7 +8,7 @@ class TestActiveExchange < Test::Unit::TestCase
8
8
  end
9
9
  def test_for_amount_on_oct_seventh
10
10
  actual = ActiveExchange.exchange_rate_on(Date.parse("10/07/2009"))
11
- assert_equal("0.889898255813954", actual.to_s)
11
+ assert_equal("0.7748606465997769", actual.to_s)
12
12
  end
13
13
  def test_retrieve_data_returns_a_200
14
14
  actual = ActiveExchange.retrieve_data
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_exchange
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 7
9
- - 0
10
- version: 0.7.0
4
+ prerelease:
5
+ version: 1.0.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - pjammer
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-05-18 00:00:00 -04:00
13
+ date: 2011-07-13 00:00:00 -04:00
19
14
  default_executable:
20
15
  dependencies: []
21
16
 
@@ -38,7 +33,6 @@ files:
38
33
  - app/models/exchange_rate.rb
39
34
  - db/migrate/20091021192708_create_exchange_rates.rb
40
35
  - lib/active_exchange.rb
41
- - lib/active_exchange/active_exchange.rb
42
36
  - lib/tasks/daily_exchange_rates.rake
43
37
  - test/helper.rb
44
38
  - test/test_active_exchange.rb
@@ -56,23 +50,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
50
  requirements:
57
51
  - - ">="
58
52
  - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
53
  version: "0"
63
54
  required_rubygems_version: !ruby/object:Gem::Requirement
64
55
  none: false
65
56
  requirements:
66
57
  - - ">="
67
58
  - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
59
  version: "0"
72
60
  requirements: []
73
61
 
74
62
  rubyforge_project:
75
- rubygems_version: 1.3.7
63
+ rubygems_version: 1.6.2
76
64
  signing_key:
77
65
  specification_version: 3
78
66
  summary: Foreign Exchange for your Rails app
@@ -1,45 +0,0 @@
1
- require "cgi"
2
- require "uri"
3
- require "net/https"
4
- require "rexml/document"
5
- require "date"
6
-
7
- module ActiveExchange
8
- # Originially massaged from the web post of http://geoff.evason.name/2008/10/27/simple-currency-conversion-rate-api-consumption-for-ruby-rails/
9
- # The active_exchange gem is used to go out to XavierMedia and pull quotes for the currencies they offer.
10
-
11
- # We'll need to have a task to look for new data and parse it into DB, to cut down calls.
12
- def self.retrieve_data(date = Date.today - 1)
13
- url = URI.parse("http://api.finance.xaviermedia.com/api/#{date.year}/#{date.strftime("%m")}/#{date.strftime("%d")}.xml")
14
- resp = Net::HTTP.get(url)
15
- xml = REXML::Document.new(resp)
16
- end
17
-
18
- def self.get_daily_data
19
- #Get data
20
- daily_rates = ActiveExchange.retrieve_data
21
- #put into database. Run the migrations, obviously, before you do this.
22
- if daily_rates.root.attributes["responsecode"] == "200"
23
- daily_rates.elements.each("//exchange_rates/fx") { |element|
24
- ExchangeRate.create(:currency => element.elements[1].text, :rate => element.elements[2].text)
25
- }
26
- end
27
- end
28
-
29
- #used to find an exchange rate on a certain day. this will make a call to the api.
30
- def self.exchange_rate_on(date, currency_from = "USD", currency_to = "AUD")
31
- xml = retrieve_data(date)
32
- us_to_eur = 1.0
33
- au_to_eur = 1.0
34
- xml.elements.each("//exchange_rates/fx") { |el|
35
- if el.elements[1].text == currency_from
36
- us_to_eur = el.elements[2].text.to_f rescue 1.0
37
- end
38
- if el.elements[1].text == currency_to
39
- au_to_eur = el.elements[2].text.to_f rescue 1.0
40
- end
41
- }
42
-
43
- return us_to_eur/au_to_eur
44
- end
45
- end