currency_converter 1.0.1 → 1.0.2
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.
- checksums.yaml +8 -8
- data/README.md +1 -1
- data/currency_converter.gemspec +1 -0
- data/lib/currency_converter.rb +17 -8
- data/lib/currency_converter/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTUxNzgxMzNiMDcwNDZlZGRhNThmNTkxZDkxODRjZWEyNzVjNzkxNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTcyZDdmMjFjNmU5ODlmZWNhNTczYTczYmFiMWFhZDJiYTk4NmUyYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTg0MTg1YWI5YjUxNDM3YmZiMzlmMTQ0NTk0YTU1NmVhYWM1NzBkMzAxY2Fj
|
10
|
+
YTljNjg5YzVhMTQzNWUzOGJhMWFmNjQzMmVlOGY0MmQ1YzExM2NhODJhYTA2
|
11
|
+
ZjA0NzNlNTMzZmM3ZjFlNzliZTdiMDc2MzBmMTdhZWIzODIxMTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Mzk0YWExMWRlYzc2ZTA5YjQxMTIwMDU0ZTdkNTUwNTkxNjFmNDUyM2RlZjdk
|
14
|
+
N2Q3Yzg3OTM3YWYzYmZmZGE2MzFlMzlmZDI0MWU3NjdkMDgwMGUzZjM3YjI5
|
15
|
+
YWZjM2JhNTZiNTdhYmQ2NjliYTE0M2RmMDg3ZmY2NzdjNDI2NmM=
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# CurrencyConverter
|
2
2
|
|
3
|
-
|
3
|
+
Simple Ruby API to get exchange rates from currencies using themoneyconverter.com website. You can convert currencies directly through this library.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
data/currency_converter.gemspec
CHANGED
data/lib/currency_converter.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'currency_converter/exceptions'
|
2
|
+
require 'currency_converter/currencies'
|
3
|
+
require 'currency_converter/version'
|
4
|
+
require 'net/http'
|
5
|
+
require 'nokogiri'
|
5
6
|
|
6
7
|
module CurrencyConverter
|
7
8
|
class << self
|
@@ -23,9 +24,13 @@ module CurrencyConverter
|
|
23
24
|
def exchange(from, to, fixnum)
|
24
25
|
@from_currency = from.upcase.to_sym
|
25
26
|
@to_currency = to.upcase.to_sym
|
27
|
+
|
26
28
|
validate_currency
|
29
|
+
|
27
30
|
ex_rate = exchange_rate
|
31
|
+
|
28
32
|
validate_rate(ex_rate)
|
33
|
+
|
29
34
|
ex_rate.to_f * fixnum
|
30
35
|
end
|
31
36
|
|
@@ -33,12 +38,16 @@ module CurrencyConverter
|
|
33
38
|
|
34
39
|
# Returns the Float value of rate or nil
|
35
40
|
def exchange_rate
|
36
|
-
http = Net::HTTP.new(
|
37
|
-
url = "/
|
41
|
+
http = Net::HTTP.new('themoneyconverter.com', 80)
|
42
|
+
url = "/CurrencyConverter.aspx?from=#{from_currency.to_s.upcase}&to=#{to_currency.to_s.upcase}"
|
38
43
|
response = http.get(url)
|
39
|
-
|
40
|
-
|
44
|
+
|
45
|
+
doc = Nokogiri::HTML(response.body)
|
46
|
+
result = doc.css('div.cc-rate textarea').first.text
|
47
|
+
|
48
|
+
regexp = Regexp.new('(\\d+(?:\\.\\d+)?)')
|
41
49
|
regexp.match result
|
50
|
+
|
42
51
|
return $1
|
43
52
|
rescue Timeout::Error
|
44
53
|
raise StandardError, "Please check your internet connection"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currency_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diganta Mandal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|