currency_conversion 0.0.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/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/currency_conversion.gemspec +14 -0
- data/lib/currency_conversion.rb +5 -0
- data/lib/currency_conversion/gateway.rb +26 -0
- data/lib/currency_conversion/model.rb +14 -0
- metadata +83 -0
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'currency_conversion'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.summary = "Currency Conversion"
|
5
|
+
s.description = "Currency conversion gem"
|
6
|
+
s.add_runtime_dependency 'rest-client', ['~> 1.6.7']
|
7
|
+
s.add_runtime_dependency 'json', ['~> 1.7.5']
|
8
|
+
s.authors = ["Victor Creed"]
|
9
|
+
s.email = 'a2ninek@yahoo.com'
|
10
|
+
#s.files = ["lib/currency_conversion.rb"]
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
module CurrencyConversion
|
4
|
+
class Gateway
|
5
|
+
def initialize(params={})
|
6
|
+
@options = params
|
7
|
+
end
|
8
|
+
def convert_payment
|
9
|
+
response = RestClient.get("http://www.google.com/ig/calculator?hl=en&q=#{@options[:value]}#{@options[:from].upcase}=?#{@options[:to].upcase}").body
|
10
|
+
response.gsub!(/(lhs|rhs|error|icc)/, '"\1"')
|
11
|
+
response_hash = JSON.parse(response)
|
12
|
+
|
13
|
+
if response_hash['error'].nil? or response_hash['error'] == ''
|
14
|
+
encoding_options = {
|
15
|
+
:invalid => :replace, # Replace invalid byte sequences
|
16
|
+
:undef => :replace, # Replace anything not defined in ASCII
|
17
|
+
:replace => '', # Use a blank for those replacements
|
18
|
+
:universal_newline => true # Always break lines with \n
|
19
|
+
}
|
20
|
+
response_hash['rhs'].encode(Encoding.find('ASCII'), encoding_options).to_f
|
21
|
+
else
|
22
|
+
raise Exception, "An error occurred: #{response_hash['error']}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "currency_conversion/gateway.rb"
|
2
|
+
module CurrencyConversion
|
3
|
+
module Model
|
4
|
+
def conversion_fields(*fields)
|
5
|
+
fields.each do |field|
|
6
|
+
define_method "#{field.to_s}_to" do |args|
|
7
|
+
return self.send(field) if args.nil? || args == "usd"
|
8
|
+
@gateway = CurrencyConversion::Gateway.new value: self.send(field), from: "usd", to: args
|
9
|
+
@gateway.convert_payment
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: currency_conversion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Victor Creed
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.6.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.7
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.7.5
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.7.5
|
46
|
+
description: Currency conversion gem
|
47
|
+
email: a2ninek@yahoo.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- .gitignore
|
53
|
+
- .ruby-gemset
|
54
|
+
- .ruby-version
|
55
|
+
- currency_conversion.gemspec
|
56
|
+
- lib/currency_conversion.rb
|
57
|
+
- lib/currency_conversion/gateway.rb
|
58
|
+
- lib/currency_conversion/model.rb
|
59
|
+
homepage:
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.25
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Currency Conversion
|
83
|
+
test_files: []
|