exchangerate 0.1.0 → 0.1.1

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/Manifest CHANGED
@@ -1,6 +1,8 @@
1
1
  MIT-LICENSE
2
- Manifest
3
2
  README.rdoc
4
3
  Rakefile
5
4
  exchangerate.gemspec
6
5
  lib/exchangerate.rb
6
+ test/exchangerate_test.rb
7
+ test/test_helper.rb
8
+ Manifest
@@ -1,21 +1,25 @@
1
- = EchangeRate
1
+ = ExchangeRate
2
2
 
3
3
  == Description
4
- This is a Ruby interface into the exchangerate-api service.
4
+ This is a Ruby interface into the exchangerate-api service. http://www.exchangerate-api.com/ claims to serv accurate currency exchange rates from the European Central Reserve Bank as they are released.
5
5
 
6
6
  == Installation
7
7
 
8
- gem install exhangerate
8
+ gem install exchangerate
9
9
 
10
10
  == Usage
11
11
 
12
12
  Before you use this library please get the api key from http://www.exchangerate-api.com/api-key
13
13
 
14
- require 'rubygems'
15
- require 'exchangerate'
16
-
17
- er=ExchangeRate.new("my-api-key")
18
- er.convert("USD","INR","300.00")
19
-
20
-
14
+ require 'rubygems'
15
+ require 'exchangerate'
16
+
17
+ #To convert 300 USD to Indian Rupee
18
+ er=ExchangeRate.new("my-api-key")
19
+ er.convert("USD","INR","300.00")
20
+ =>"14047.51"
21
+
22
+ #To convert USD to EUR
23
+ er.convert("USD","INR","300.00")
24
+ =>"243.23"
21
25
 
data/Rakefile CHANGED
@@ -2,9 +2,9 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('exchangerate', '0.1.0') do |p|
6
- p.description = "A gem to convert currencies with ease!"
7
- p.url = "http://github.com/giridhar/exhangerate"
5
+ Echoe.new('exchangerate', '0.1.1') do |p|
6
+ p.description = "A gem to convert currencies with ease and at real time ."
7
+ p.url = "http://github.com/giridhar/exchangerate"
8
8
  p.author = "Giridhar Bandi"
9
9
  p.email = "giridhar dot bandi at gmail.com"
10
10
  p.ignore_pattern = ["tmp/*", "script/*"]
@@ -2,21 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{exchangerate}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Giridhar Bandi"]
9
9
  s.date = %q{2010-05-20}
10
- s.description = %q{A gem to convert currencies with ease!}
10
+ s.description = %q{A gem to convert currencies with ease and at real time .}
11
11
  s.email = %q{giridhar dot bandi at gmail.com}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/exchangerate.rb"]
13
- s.files = ["MIT-LICENSE", "Manifest", "README.rdoc", "Rakefile", "exchangerate.gemspec", "lib/exchangerate.rb"]
14
- s.homepage = %q{http://github.com/giridhar/exhangerate}
13
+ s.files = ["MIT-LICENSE", "README.rdoc", "Rakefile", "exchangerate.gemspec", "lib/exchangerate.rb", "test/exchangerate_test.rb", "test/test_helper.rb", "Manifest"]
14
+ s.homepage = %q{http://github.com/giridhar/exchangerate}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Exchangerate", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{exchangerate}
18
18
  s.rubygems_version = %q{1.3.7}
19
- s.summary = %q{A gem to convert currencies with ease!}
19
+ s.summary = %q{A gem to convert currencies with ease and at real time .}
20
+ s.test_files = ["test/exchangerate_test.rb", "test/test_helper.rb"]
20
21
 
21
22
  if s.respond_to? :specification_version then
22
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -11,15 +11,18 @@ class ExchangeRate
11
11
  @api_key = api_key
12
12
  end
13
13
 
14
+ #converts
14
15
  def convert(from_curr,to_curr,amount)
15
16
  begin
16
- raise UnsupportedCurrencyException, "The currency is not supported " if !SUPPORTED_CODES.include?(from_curr) || !SUPPORTED_CODES.include?(to_curr)
17
+ raise UnsupportedCurrencyException if !SUPPORTED_CODES.include?(from_curr) || !SUPPORTED_CODES.include?(to_curr)
17
18
  http = Net::HTTP.new(HOST, 80)
18
19
  url = "/"+from_curr+"/"+to_curr+"/"+amount.to_s+"?k=#{@api_key}"
19
20
  response = http.get(url)
20
21
  return response.body
21
- rescue => e
22
- puts "Error: #{e}"
22
+ rescue UnsupportedCurrencyException => e
23
+ raise UnsupportedCurrencyException
24
+ rescue => err_msg
25
+ puts #{err_msg}
23
26
  end
24
27
  end
25
28
  end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ class ExchangeRateTest < Test::Unit::TestCase
3
+ def test_supported_covertion
4
+ setup_net_http
5
+ er=ExchangeRate.new("my-api-key")
6
+ amt = er.convert("USD","INR","300")
7
+ assert_not_nil amt
8
+ end
9
+
10
+ def test_unsupported_covertion
11
+ er=ExchangeRate.new("my-api-key")
12
+ assert_raises (UnsupportedCurrencyException) do
13
+ er.convert("unknowcurrency","INR","300")
14
+ end
15
+ end
16
+
17
+ def setup_net_http
18
+ response = {'code' => '200','readbody'=>'true'}
19
+ response.stubs(:body).returns('2000')
20
+ server = mock()
21
+ server.stubs(:get).returns(response)
22
+ Net::HTTP.stubs(:new).returns(server)
23
+ end
24
+ end
25
+
@@ -0,0 +1,6 @@
1
+ require 'test/unit'
2
+ $:.unshift File.dirname(__FILE__) + '/../lib'
3
+ require 'exchangerate'
4
+ require 'rubygems'
5
+ require 'mocha'
6
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Giridhar Bandi
@@ -18,7 +18,7 @@ date: 2010-05-20 00:00:00 +05:30
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description: A gem to convert currencies with ease!
21
+ description: A gem to convert currencies with ease and at real time .
22
22
  email: giridhar dot bandi at gmail.com
23
23
  executables: []
24
24
 
@@ -29,13 +29,15 @@ extra_rdoc_files:
29
29
  - lib/exchangerate.rb
30
30
  files:
31
31
  - MIT-LICENSE
32
- - Manifest
33
32
  - README.rdoc
34
33
  - Rakefile
35
34
  - exchangerate.gemspec
36
35
  - lib/exchangerate.rb
36
+ - test/exchangerate_test.rb
37
+ - test/test_helper.rb
38
+ - Manifest
37
39
  has_rdoc: true
38
- homepage: http://github.com/giridhar/exhangerate
40
+ homepage: http://github.com/giridhar/exchangerate
39
41
  licenses: []
40
42
 
41
43
  post_install_message:
@@ -71,6 +73,7 @@ rubyforge_project: exchangerate
71
73
  rubygems_version: 1.3.7
72
74
  signing_key:
73
75
  specification_version: 3
74
- summary: A gem to convert currencies with ease!
75
- test_files: []
76
-
76
+ summary: A gem to convert currencies with ease and at real time .
77
+ test_files:
78
+ - test/exchangerate_test.rb
79
+ - test/test_helper.rb