mula 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/mula/helpers.rb +22 -0
- data/lib/mula/railtie.rb +5 -0
- data/lib/mula/version.rb +1 -1
- data/mula.gemspec +1 -1
- data/spec/mula_spec.rb +15 -0
- data/spec/spec_helper.rb +1 -0
- metadata +12 -4
data/.DS_Store
ADDED
Binary file
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/mula/helpers.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
|
+
require 'iconv'
|
4
|
+
|
5
|
+
API_BASE = "http://www.google.com/ig/calculator"
|
6
|
+
|
7
|
+
module Mula
|
8
|
+
module Helpers
|
9
|
+
def convert(amount=1, current_currency='USD', target_currency='GBP')
|
10
|
+
uri = URI.parse("#{API_BASE}?hl=en&q=#{amount}#{current_currency}=?#{target_currency}")
|
11
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
12
|
+
response = http.request(Net::HTTP::Get.new(uri.request_uri))
|
13
|
+
# fix the mess than Google have made of the JSON
|
14
|
+
fixed_json_str = response.body.gsub!(/(['"])?([a-zA-Z0-9_]+)(['"])?:/, '"\2":')
|
15
|
+
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
16
|
+
valid_string = ic.iconv(fixed_json_str + ' ')[0..-2]
|
17
|
+
parsed_response = ActiveSupport::JSON.decode(valid_string)
|
18
|
+
return parsed_response["rhs"].split(" ")[0]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/mula/railtie.rb
ADDED
data/lib/mula/version.rb
CHANGED
data/mula.gemspec
CHANGED
data/spec/mula_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/mula")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mula
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '3.
|
21
|
+
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '3.
|
29
|
+
version: '3.1'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rspec
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,14 +50,20 @@ executables: []
|
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
|
+
- .DS_Store
|
53
54
|
- .gitignore
|
54
55
|
- Gemfile
|
55
56
|
- LICENSE
|
56
57
|
- README.md
|
57
58
|
- Rakefile
|
59
|
+
- lib/.DS_Store
|
58
60
|
- lib/mula.rb
|
61
|
+
- lib/mula/helpers.rb
|
62
|
+
- lib/mula/railtie.rb
|
59
63
|
- lib/mula/version.rb
|
60
64
|
- mula.gemspec
|
65
|
+
- spec/mula_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
61
67
|
homepage: ''
|
62
68
|
licenses: []
|
63
69
|
post_install_message:
|
@@ -82,4 +88,6 @@ rubygems_version: 1.8.18
|
|
82
88
|
signing_key:
|
83
89
|
specification_version: 3
|
84
90
|
summary: Currency conversion made simple via the Google API
|
85
|
-
test_files:
|
91
|
+
test_files:
|
92
|
+
- spec/mula_spec.rb
|
93
|
+
- spec/spec_helper.rb
|