rate_man 0.0.4
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/lib/currency_duo.rb +28 -0
- data/lib/rate_man.rb +40 -0
- metadata +62 -0
data/lib/currency_duo.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module RateMan
|
2
|
+
class CurrencyDuo
|
3
|
+
attr_accessor :from, :to, :raw, :rate
|
4
|
+
def initialize(from_cur, to_cur)
|
5
|
+
@from = from_cur
|
6
|
+
@to = to_cur
|
7
|
+
end
|
8
|
+
|
9
|
+
def query
|
10
|
+
self.raw = RateMan.query(from, to)
|
11
|
+
self.rate = raw[3].to_f
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def hash
|
16
|
+
raise ArgumentError, "you must query google for the rate first" unless rate && raw
|
17
|
+
{from_to: from + ':' + to,
|
18
|
+
from_cur: [1, from],
|
19
|
+
to_cur: [rate, to],
|
20
|
+
rate: rate,
|
21
|
+
inv_rate: 1 / rate}
|
22
|
+
end
|
23
|
+
|
24
|
+
def json
|
25
|
+
hash.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/rate_man.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
4
|
+
require "./lib/currency_duo"
|
5
|
+
|
6
|
+
module RateMan
|
7
|
+
|
8
|
+
@@_ran_once = false
|
9
|
+
@@google_api_url = "https://www.googleapis.com/customsearch/v1"
|
10
|
+
|
11
|
+
mattr_accessor :api_key, :google_api_url, :custom_search_id
|
12
|
+
|
13
|
+
def self.query_url(from_cur, to_cur)
|
14
|
+
"#{@@google_api_url}?key=#{self.api_key}&cx=#{@@custom_search_id}&q=1%20#{from_cur}%20to%20#{to_cur}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.setup
|
18
|
+
yield self if @@_ran_once == false
|
19
|
+
@@_ran_once = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.cleanup
|
23
|
+
@@_ran_once = false
|
24
|
+
self.api_key = nil
|
25
|
+
self.custom_search_id = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.query(from_cur, to_cur)
|
29
|
+
JSON.parse(IO.read open(self.query_url(from_cur, to_cur)))['items'].first['snippet'].split('...').last.split(' ')
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get(from_cur, to_cur)
|
33
|
+
RateMan::CurrencyDuo.new('EUR', 'CHF').query.json
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
alias_method :rate, :get
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rate_man
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Riboulet
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: active_support
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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: '0'
|
30
|
+
description: simple gem to get currency exchance rates from google
|
31
|
+
email: riboulet@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/rate_man.rb
|
37
|
+
- lib/currency_duo.rb
|
38
|
+
homepage: http://github.com/mcansky/rate_man
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.24
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: simple gem to get currency exchance rates from google
|
62
|
+
test_files: []
|