active_exchange 0.3.0 → 0.4.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/README.rdoc CHANGED
@@ -12,8 +12,8 @@ I personally wouldn't use this if my model was, say an F/X trader on a big time
12
12
 
13
13
  == Usage
14
14
 
15
- * add config.gem 'active_exchange' to your environment.rb file
16
- * For now: Copy the rake file and migration into your app's (for rake) lib/task directory and (for migration file)db/migrate
15
+ * add gem 'active_exchange' to your GEMFILE (Rails 3)
16
+ * For now: Copy the rake file and migration into your app's (for rake) lib/task directory and (for migration file)db/migrate -- Will fix later hopefully.
17
17
  * Run "rake db:migrate" to migrate the migration files.
18
18
  * Run the rake task : "sudo rake active_exchange:daily_seed" to get yesterday's closing Exchange Rate data (When doing today's it's hit and miss).
19
19
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -1,45 +1,40 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_exchange}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.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{2010-10-20}
12
+ s.date = %q{2011-05-18}
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 = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "active_exchange.gemspec",
27
- "app/models/exchange_rate.rb",
28
- "db/migrate/20091021192708_create_exchange_rates.rb",
29
- "lib/active_exchange.rb",
30
- "tasks/daily_exchange_rates.rake",
31
- "test/helper.rb",
32
- "test/test_active_exchange.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "active_exchange.gemspec",
26
+ "app/models/exchange_rate.rb",
27
+ "db/migrate/20091021192708_create_exchange_rates.rb",
28
+ "lib/active_exchange.rb",
29
+ "lib/active_exchange/active_exchange.rb",
30
+ "tasks/daily_exchange_rates.rake",
31
+ "test/helper.rb",
32
+ "test/test_active_exchange.rb"
33
33
  ]
34
34
  s.homepage = %q{http://github.com/pjammer/active_exchange}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
35
  s.require_paths = ["lib"]
37
36
  s.rubygems_version = %q{1.3.7}
38
37
  s.summary = %q{Foreign Exchange for your Rails app}
39
- s.test_files = [
40
- "test/helper.rb",
41
- "test/test_active_exchange.rb"
42
- ]
43
38
 
44
39
  if s.respond_to? :specification_version then
45
40
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -1,45 +1 @@
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
1
+ require 'active_exchange' if defined?(Rails) && Rails::VERSION::MAJOR == 3
@@ -0,0 +1,45 @@
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
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_exchange
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - pjammer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-20 00:00:00 -04:00
18
+ date: 2011-05-18 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -30,7 +30,6 @@ extra_rdoc_files:
30
30
  - README.rdoc
31
31
  files:
32
32
  - .document
33
- - .gitignore
34
33
  - LICENSE
35
34
  - README.rdoc
36
35
  - Rakefile
@@ -39,6 +38,7 @@ files:
39
38
  - app/models/exchange_rate.rb
40
39
  - db/migrate/20091021192708_create_exchange_rates.rb
41
40
  - lib/active_exchange.rb
41
+ - lib/active_exchange/active_exchange.rb
42
42
  - tasks/daily_exchange_rates.rake
43
43
  - test/helper.rb
44
44
  - test/test_active_exchange.rb
@@ -47,8 +47,8 @@ homepage: http://github.com/pjammer/active_exchange
47
47
  licenses: []
48
48
 
49
49
  post_install_message:
50
- rdoc_options:
51
- - --charset=UTF-8
50
+ rdoc_options: []
51
+
52
52
  require_paths:
53
53
  - lib
54
54
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -76,6 +76,5 @@ rubygems_version: 1.3.7
76
76
  signing_key:
77
77
  specification_version: 3
78
78
  summary: Foreign Exchange for your Rails app
79
- test_files:
80
- - test/helper.rb
81
- - test/test_active_exchange.rb
79
+ test_files: []
80
+
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC