fixer-rb 0.1.1 → 0.1.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 065eb6e50203610856ddd30d898e87aa72a65e39
4
- data.tar.gz: eed378c39a31922b725ebfc660af1a26707e3bed
3
+ metadata.gz: 1f71d6fcdbe0db8212b251cc4e2bae06f155999f
4
+ data.tar.gz: 325efc74ed133115b6335e1c1b1e040e0f191352
5
5
  SHA512:
6
- metadata.gz: 1da31d88fb91b3d0c860549b0cb4cd8a61dff6c1066a387e54294b44ba61f8c47157133d3d102792a6d17cca34c2ec3b9bfba82e8eaa0b4e09549533412d6c49
7
- data.tar.gz: 95f71dd6520c9512f3b271c22a8988d0f5ac708a6304cb4d516023d510829f01743a8d90c7c08fe9eebd19d5f46e0b64c39fa409be3f7c87139c38f59683246b
6
+ metadata.gz: 990d428765fecf8dba42e9532593afc4bd3d47b25c06f302d1431288bb958e7d701c56eab155105c6c780603d3ecaa869d56070167cce0c6eb67dc1b95178c8a
7
+ data.tar.gz: a0f611cd42928b3feb9213598c163b0cbb6418e3822cf76e1930abbc88ee10c15b195deb2e5692b521dc7bf00c8cda19a7d73dd9390fa78fc83af5ffd01d1a40
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Fixer
2
2
 
3
+ [![Build Status](https://travis-ci.org/gaotongfei/fixer.svg?branch=master)](https://travis-ci.org/gaotongfei/fixer)
4
+
3
5
  Fixer is a simple API wrapper of [http://fixer.io/](http://fixer.io/) to provide a clean way of converting currency
4
6
 
5
7
  # Install
@@ -16,12 +18,51 @@ To convert Chinese Yuan to US Dollars, simply do this
16
18
  require 'fixer'
17
19
 
18
20
  fixer = Fixer::Request.new 'CNY'
19
- params = {target: 'USD', ammount: 200}
21
+ params = {target: 'USD', ammount: 1000}
20
22
 
21
23
  fixer.transfer(params)
24
+ $ 149.75
22
25
  ```
23
26
 
24
27
  ```
25
- $ 149.75
28
+ fixer.get_rate do |rate|
29
+ rate.USD
30
+ end
31
+
32
+ $ 0.14975
26
33
  ```
27
34
 
35
+ # Supported Currencies
36
+
37
+ * CNY
38
+ * AUD
39
+ * BGN
40
+ * BRL
41
+ * CAD
42
+ * CHF
43
+ * CZK
44
+ * DKK
45
+ * GBP
46
+ * HKD
47
+ * HRK
48
+ * HUF
49
+ * IDR
50
+ * ILS
51
+ * INR
52
+ * JPY
53
+ * KRW
54
+ * MXN
55
+ * MYR
56
+ * NOK
57
+ * NZD
58
+ * PHP
59
+ * PLN
60
+ * RON
61
+ * RUB
62
+ * SEK
63
+ * SGD
64
+ * THB
65
+ * TRY
66
+ * USD
67
+ * ZAR
68
+ * EUR
data/lib/fixer.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'ostruct'
2
+
1
3
  require 'httparty'
2
4
 
3
5
  require "fixer/version"
data/lib/fixer/request.rb CHANGED
@@ -2,6 +2,7 @@ module Fixer
2
2
  class Request
3
3
  attr_reader :response
4
4
  def initialize(base = Fixer.base)
5
+ @base = base
5
6
  base_host = "https://api.fixer.io/latest?base=#{base}"
6
7
  @response = HTTParty.get(base_host)
7
8
  end
@@ -22,6 +23,15 @@ module Fixer
22
23
  end
23
24
  end
24
25
 
26
+ def get_rate
27
+ result = JSON.parse @response.body, symbolize_names: true
28
+ base = {base: @base}
29
+ rates = result[:rates]
30
+ currencies = base.merge(rates)
31
+ r_obj = OpenStruct.new currencies
32
+ yield r_obj
33
+ end
34
+
25
35
  private
26
36
  def valid_currency?(currency)
27
37
  valid_currencies = ["EUR", "AUD", "BGN", "BRL", "CAD", "CHF", "CNY",
data/lib/fixer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fixer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixer-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taff Gao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2017-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler