mula 0.0.3 → 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.
Binary file
Binary file
@@ -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
@@ -0,0 +1,5 @@
1
+ module Mula
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Mula
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -14,6 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "mula"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Mula::VERSION
17
- gem.add_dependency 'activesupport', '~> 3.2'
17
+ gem.add_dependency 'activesupport', '~> 3.1'
18
18
  gem.add_development_dependency 'rspec'
19
19
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mula do
4
+ it "should convert my monies" do
5
+
6
+ class MulaTest
7
+ include Mula::Helpers
8
+ end
9
+
10
+ test = MulaTest.new
11
+ puts test.convert(1,'USD','GBP')
12
+ test.convert.class.should be String
13
+
14
+ end
15
+ end
@@ -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.3
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.2'
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.2'
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