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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWFkYjk0YWUzNjBiNjhlZDQyNjE1YTgxY2VjMTNjODdhODMxZDk5Nw==
4
+ NTUxNzgxMzNiMDcwNDZlZGRhNThmNTkxZDkxODRjZWEyNzVjNzkxNA==
5
5
  data.tar.gz: !binary |-
6
- NjUzOTIxZmMwNTM1MmVlZTRiNjBjZGU0NmQ5ZmE3OGYwYmFhNzE5Yg==
6
+ YTcyZDdmMjFjNmU5ODlmZWNhNTczYTczYmFiMWFhZDJiYTk4NmUyYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjE1YmQyNzMyYWVhMDBmMTZhMjgxMjg0MmEwMDM0ZmEwMWIxMjhjMTZkODQx
10
- NDhiNGQzY2RlN2MwOWNmMTNiMzY5ZDdhYWVmNmFkOTUxZjMxZTkyN2UyZjU0
11
- NGQzZjAyODNkZDE0ZGU3YmI3ZjYwMjk0ZDA5OWJhN2FiMDljYzY=
9
+ MTg0MTg1YWI5YjUxNDM3YmZiMzlmMTQ0NTk0YTU1NmVhYWM1NzBkMzAxY2Fj
10
+ YTljNjg5YzVhMTQzNWUzOGJhMWFmNjQzMmVlOGY0MmQ1YzExM2NhODJhYTA2
11
+ ZjA0NzNlNTMzZmM3ZjFlNzliZTdiMDc2MzBmMTdhZWIzODIxMTE=
12
12
  data.tar.gz: !binary |-
13
- YjJmMzkwNjZiNjhhMzk1ODFlOTFmYTcxYmRjMmQ1NWQ4NDcyNDc5YWM1NThl
14
- OWJlZjVlNjBjNWEyZjQ2M2RiMWViZjg2OTIzNWMyYWY1ZTZlNTUxNThmMmEz
15
- OTZjYzQ5ZDRjMzc4YjhlYmNjZDMwNGNkYTEyYjgzNTc4YzFhOTA=
13
+ Mzk0YWExMWRlYzc2ZTA5YjQxMTIwMDU0ZTdkNTUwNTkxNjFmNDUyM2RlZjdk
14
+ N2Q3Yzg3OTM3YWYzYmZmZGE2MzFlMzlmZDI0MWU3NjdkMDgwMGUzZjM3YjI5
15
+ YWZjM2JhNTZiNTdhYmQ2NjliYTE0M2RmMDg3ZmY2NzdjNDI2NmM=
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CurrencyConverter
2
2
 
3
- Google provides a web site to converts currencies using exchange rates but they have not provided any API for ruby. This is a small library that converts currencies exchange rate. You can convert currencies directly through this library.
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
 
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.required_ruby_version = ">= 1.8.7"
24
+ spec.add_dependency 'nokogiri'
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.3"
26
27
  spec.add_development_dependency "rake"
@@ -1,7 +1,8 @@
1
- require "currency_converter/exceptions"
2
- require "currency_converter/currencies"
3
- require "currency_converter/version"
4
- require "net/http"
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("www.google.com", 80)
37
- url = "/finance/converter?a=1&from=#{from_currency.to_s.upcase}&to=#{to_currency.to_s.upcase}"
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
- result = response.body
40
- regexp = Regexp.new("(\\d+\\.{0,1}\\d*)\\s+#{to_currency}")
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"
@@ -1,3 +1,3 @@
1
1
  module CurrencyConverter
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
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.1
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-07-01 00:00:00.000000000 Z
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