Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
creating exchangerate gem repo
Browse files Browse the repository at this point in the history
  • Loading branch information
giridhar committed May 19, 2010
0 parents commit 0da5abb
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
doc
Manifest
pkg
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2010 Giridhar Bandi

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 changes: 21 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
= EchangeRate

== Description
This is a Ruby interface into the exchangerate-api service.

== Installation

gem install exhangerate

== Usage

Before you use this library please get the api key from http://www.exchangerate-api.com/api-key

require 'rubygems'
require 'exchangerate'

er=ExchangeRate.new("my-api-key")
er.convert("USD","INR","300.00")



13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rubygems'
require 'rake'
require 'echoe'

Echoe.new('exchangerate', '0.1.0') do |p|
p.description = "A gem to convert currencies with ease!"
p.url = "http://github.com/giridhar/exhangerate"
p.author = "Giridhar Bandi"
p.email = "giridhar dot bandi at gmail.com"
p.ignore_pattern = ["tmp/*", "script/*"]
p.development_dependencies = []
end

Binary file added exchangerate-0.1.0.gem
Binary file not shown.
30 changes: 30 additions & 0 deletions exchangerate.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{exchangerate}
s.version = "0.1.0"

s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Giridhar Bandi"]
s.date = %q{2010-05-20}
s.description = %q{A gem to convert currencies with ease!}
s.email = %q{giridhar dot bandi at gmail.com}
s.extra_rdoc_files = ["README.rdoc", "lib/exchangerate.rb"]
s.files = ["MIT-LICENSE", "Manifest", "README.rdoc", "Rakefile", "exchangerate.gemspec", "lib/exchangerate.rb"]
s.homepage = %q{http://github.com/giridhar/exhangerate}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Exchangerate", "--main", "README.rdoc"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{exchangerate}
s.rubygems_version = %q{1.3.7}
s.summary = %q{A gem to convert currencies with ease!}

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
else
end
else
end
end
26 changes: 26 additions & 0 deletions lib/exchangerate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'net/http'

class UnsupportedCurrencyException < RuntimeError
end

class ExchangeRate
HOST = "www.exchangerate-api.com"
SUPPORTED_CODES=['EUR','USD','JPY','GBP','BGN','CZK','DKK','EEK','HUF','LTL','LVL','PLN','RON','SEK','CHF','NOK','HRK','RUB','TRY','AUD','BRL','CAD','CNY','HKD','IDR','INR','KRW','MXN','MYR','NZD','PHP','SGD','THB','ZAR']

def initialize(api_key)
@api_key = api_key
end

def convert(from_curr,to_curr,amount)
begin
raise UnsupportedCurrencyException, "The currency is not supported " if !SUPPORTED_CODES.include?(from_curr) || !SUPPORTED_CODES.include?(to_curr)
http = Net::HTTP.new(HOST, 80)
url = "/"+from_curr+"/"+to_curr+"/"+amount.to_s+"?k=#{@api_key}"
response = http.get(url)
return response.body
rescue => e
puts "Error: #{e}"
end
end
end

0 comments on commit 0da5abb

Please sign in to comment.