genial 0.0.4 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e210725901b7405b6afec8c73c85338d717e78b
4
- data.tar.gz: dab2527014cb395789696a7152f7531906b36394
3
+ metadata.gz: 328e5cc051e131d211e2c03e020f81446aa6f986
4
+ data.tar.gz: b9b983c1c1f7e3cf9d4c86442f57e281192e1418
5
5
  SHA512:
6
- metadata.gz: a7200656f4e267e9462ce5280f8c8cb36ba5465d7c5f36bd56cfae9825d24b994c5e490ae49e112029552b350ff9bc51423be278aed3a8732fc05ff659c702d5
7
- data.tar.gz: ec32a273aea488a1bb9e0cb58cd0444b1bc92069fea9256f299b451df3e8be91bfc98da74db7753af7f87b881901418a5c372675dd7ffca629eb22c914bac596
6
+ metadata.gz: af319bf3d15822ccc1f8d8d1906d057945134e8ec796d8bd2e5e2d97dddd0e250db85bb6f99554a4089705f491112cc336c9cf9151d220899ffe5ce1fc7b6ded
7
+ data.tar.gz: 914c3b807175973df8c85353adc1c5054b7a3a2ffbcc6cd7f390d6ea709a1a3667271322bcd7abbb378d7cddadc3886f12b7b70bac210c021f69806319c3010f
data/README.md CHANGED
@@ -42,6 +42,12 @@ Genial::Currency.euro
42
42
  Genial::Currency.pound
43
43
  ```
44
44
 
45
+ To convert a value from one currency to another is also pretty simple. Just pass the following params like this:
46
+ ```ruby
47
+ Genial::Currency.convert("USD","BRL","30.99")
48
+ # => 116.96
49
+
50
+ ```
45
51
 
46
52
  We can get the value of any currency in the world. Based on [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217), we just need to pass the country code to method `find` and we are done. Ex: to get `Canadian dollar` value:
47
53
 
@@ -4,6 +4,7 @@ require "httparty"
4
4
  module Genial
5
5
  class Currency
6
6
  include HTTParty
7
+
7
8
  base_uri "http://api.xgeek.com.br/taxa-cambio"
8
9
 
9
10
  def self.find(code)
@@ -22,10 +23,27 @@ module Genial
22
23
  parse_response(get("/currency?code=GBP"))
23
24
  end
24
25
 
26
+ def self.convert(from, to, value)
27
+ convert_response(get("/convert?from=#{from}&to=#{to}&value=#{value}"))
28
+ end
29
+
25
30
  private
26
31
 
27
32
  def self.parse_response(response)
28
33
  response.parsed_response["buying_rate"].to_f.round(2)
29
34
  end
35
+
36
+ def self.convert_response(response)
37
+ case response.code
38
+ when 200
39
+ response.parsed_response["result"].to_f.round(2)
40
+ when 404
41
+ puts "moeda(s) não encontrada(s)"
42
+ when 400
43
+ puts "solicitação inválida"
44
+ when 500
45
+ puts "erro interno."
46
+ end
47
+ end
30
48
  end
31
49
  end
@@ -1,3 +1,3 @@
1
1
  module Genial
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renan Gurgel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-16 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler