oanda_ruby_client 1.0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b6a110cfa0b814c238cb2091a87bde5e44a445d
4
+ data.tar.gz: e4ae890af891f40ac95f4b00d6a1d0432282f2c5
5
+ SHA512:
6
+ metadata.gz: 1f18a1c04037ba10094f202cd3e4b4e0a0218ac0d7dfefe65ea3074606e46f4dca42f049573348b7c3c544ffb3562a09b9f8ae8af93389490e2ff1ff822e82cf
7
+ data.tar.gz: 481e65dc821d0625895d38ad06fbfc5a56820231511e18e9ae613de917088066c18c09ad1b2c805cedbbb251283875aac56a810a383fb343afaa2951a3ef61f6
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in oanda_ruby_client.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oanda_ruby_client (1.0.0.0)
5
+ addressable (~> 2.3.7)
6
+ httparty
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.7)
12
+ crack (0.4.2)
13
+ safe_yaml (~> 1.0.0)
14
+ diff-lcs (1.2.5)
15
+ docile (1.1.5)
16
+ httparty (0.13.3)
17
+ json (~> 1.8)
18
+ multi_xml (>= 0.5.2)
19
+ json (1.8.2)
20
+ multi_json (1.10.1)
21
+ multi_xml (0.5.5)
22
+ rake (10.4.2)
23
+ rspec (3.2.0)
24
+ rspec-core (~> 3.2.0)
25
+ rspec-expectations (~> 3.2.0)
26
+ rspec-mocks (~> 3.2.0)
27
+ rspec-core (3.2.0)
28
+ rspec-support (~> 3.2.0)
29
+ rspec-expectations (3.2.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.2.0)
32
+ rspec-mocks (3.2.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.2.0)
35
+ rspec-support (3.2.1)
36
+ safe_yaml (1.0.4)
37
+ simplecov (0.9.1)
38
+ docile (~> 1.1.0)
39
+ multi_json (~> 1.0)
40
+ simplecov-html (~> 0.8.0)
41
+ simplecov-html (0.8.0)
42
+ vcr (2.9.3)
43
+ webmock (1.20.4)
44
+ addressable (>= 2.3.6)
45
+ crack (>= 0.3.2)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.8)
52
+ oanda_ruby_client!
53
+ rake (~> 10.0)
54
+ rspec
55
+ simplecov (~> 0.9.1)
56
+ vcr (~> 2.9.3)
57
+ webmock (~> 1.20.4)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Frontera Consulting, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # Oanda Ruby Client
2
+
3
+ The Oanda Ruby Client provides a simple client class to retrieve exchange rates from Oanda using the Exchange Rate API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'oanda_ruby_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install oanda_ruby_client
20
+
21
+ ## Usage
22
+
23
+ ### Getting Started
24
+
25
+ Initialize the client as follows:
26
+
27
+ ```ruby
28
+ require 'oanda_ruby_client'
29
+
30
+ client = OandaRubyClient::ExchangeRatesClient.new('MY_API_KEY') # Provide your API Key as the parameter
31
+ ```
32
+
33
+ If you store the API key in an environment variable named `OANDA_RUBY_CLIENT_API_KEY`, you can omit the parameter:
34
+
35
+ ```ruby
36
+ client = OandaRubyClient::ExchangeRatesClient.new
37
+ ```
38
+
39
+ ### Get Rates
40
+
41
+ Create a request specifying the base currency as the first parameter, and any optional paramters as a hash. The keys of the optional paramters are the same as those for the [Exchange Rate API](http://developer.oanda.com/exchange-rates-api/v1/rates/#input-query-parameters):
42
+
43
+ For example, to specify a base currency of USD, a quote currency of GBP, and a date of February 11, 2015:
44
+
45
+ ```ruby
46
+ rates_request = OandaRubyClient::RatesRequest.new('USD', quote: 'GBP', date: '2015-02-11')
47
+ ```
48
+
49
+ Date parameters can be specified using a string in the format of `YYYY-MM-DD` or by using an instance of `Date`:
50
+
51
+ ```ruby
52
+ require 'date'
53
+
54
+ rates_request = OandaRubyClient::RatesRequest.new('USD', quote: 'GBP', date: Date.new(2015, 2, 11))
55
+ ```
56
+
57
+ Multi-value parameters (e.g., quote currency) can be specified using arrays:
58
+
59
+ ```ruby
60
+ rates_request = OandaRubyClient::RatesRequest.new('USD', quote: [ 'GBP', 'EUR' ], date: '2015-02-11')
61
+ ```
62
+
63
+ Pass the rates request as a parameter into the `rates` method of the client:
64
+
65
+ ```ruby
66
+ rates_result = client.rates(rates_request)
67
+ ```
68
+
69
+ The returning object will be an `OpenStruct` with the attributes `base_currency` (String), `meta` (Hash), `quotes` (Hash).
70
+
71
+ ### Get Currencies
72
+
73
+ To obtain the collection of supported currencies, use the `currencies` method:
74
+
75
+ ```ruby
76
+ currencies_result = client.currencies
77
+ ```
78
+
79
+ The returning object will be a hash of currency codes to descriptions.
80
+
81
+ ### Get Remaining Quotes
82
+
83
+ For plans that have a limited number of quotes, use the `remaining_quotes` method to return the number of remaining quotes:
84
+
85
+ ```ruby
86
+ remaining_quotes_result = client.remaining_quotes
87
+ ```
88
+
89
+ ### Additional Resources
90
+
91
+ * http://developer.oanda.com/exchange-rates-api/
92
+
93
+ ## Contributing
94
+
95
+ 1. Fork it
96
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
97
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
98
+ 4. Push to the branch (`git push origin my-new-feature`)
99
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ require 'irb'
5
+ require 'irb/completion'
6
+ require 'oanda_ruby_client'
7
+ ARGV.clear
8
+ IRB.start
9
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oanda_ruby_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,138 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.oanda.com/rates/api/v1/currencies.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - Bearer {OANDA_API_KEY}
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Date:
18
+ - Thu, 12 Feb 2015 23:41:21 GMT
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '9394'
23
+ Connection:
24
+ - keep-alive
25
+ Server:
26
+ - nginx
27
+ Vary:
28
+ - Accept-Encoding
29
+ X-Oanda-Exchange-Rates-Api-Version:
30
+ - 1.0.2
31
+ Set-Cookie:
32
+ - opc_id=A5E39DDE-B310-11E4-A953-BAED8E3C4C4D; path=/; Expires=Sun, 09-Feb-2025
33
+ 23:41:21 GMT
34
+ body:
35
+ encoding: UTF-8
36
+ string: '{"currencies":[{"code":"ADF","description":"Andorran Franc"},{"code":"ADP","description":"Andorran
37
+ Peseta"},{"code":"AED","description":"Utd. Arab Emir. Dirham"},{"code":"AFA","description":"Afghanistan
38
+ Old Afghani"},{"code":"AFN","description":"Afghan Afghani"},{"code":"ALL","description":"Albanian
39
+ Lek"},{"code":"AMD","description":"Armenian Dram"},{"code":"ANG","description":"NL
40
+ Antillian Guilder"},{"code":"AOA","description":"Angolan Kwanza"},{"code":"AON","description":"Angolan
41
+ Old Kwanza"},{"code":"ARS","description":"Argentine Peso"},{"code":"ATS","description":"Austrian
42
+ Schilling"},{"code":"AUD","description":"Australian Dollar"},{"code":"AWG","description":"Aruban
43
+ Florin"},{"code":"AZM","description":"Azerbaijan Old Manat"},{"code":"AZN","description":"Azerbaijan
44
+ New Manat"},{"code":"BAM","description":"Bosnian Mark"},{"code":"BBD","description":"Barbados
45
+ Dollar"},{"code":"BDT","description":"Bangladeshi Taka"},{"code":"BEF","description":"Belgian
46
+ Franc"},{"code":"BGL","description":"Bulgarian Old Lev"},{"code":"BGN","description":"Bulgarian
47
+ Lev"},{"code":"BHD","description":"Bahraini Dinar"},{"code":"BIF","description":"Burundi
48
+ Franc"},{"code":"BMD","description":"Bermudian Dollar"},{"code":"BND","description":"Brunei
49
+ Dollar"},{"code":"BOB","description":"Bolivian Boliviano"},{"code":"BRL","description":"Brazilian
50
+ Real"},{"code":"BSD","description":"Bahamian Dollar"},{"code":"BTC","description":"Bitcoin"},{"code":"BTN","description":"Bhutan
51
+ Ngultrum"},{"code":"BWP","description":"Botswana Pula"},{"code":"BYR","description":"Belarusian
52
+ Ruble"},{"code":"BZD","description":"Belize Dollar"},{"code":"CAD","description":"Canadian
53
+ Dollar"},{"code":"CDF","description":"Congolese Franc"},{"code":"CHF","description":"Swiss
54
+ Franc"},{"code":"CLP","description":"Chilean Peso"},{"code":"CNY","description":"Chinese
55
+ Yuan Renminbi"},{"code":"COP","description":"Colombian Peso"},{"code":"CRC","description":"Costa
56
+ Rican Colon"},{"code":"CUC","description":"Cuban Convertible Peso"},{"code":"CUP","description":"Cuban
57
+ Peso"},{"code":"CVE","description":"Cape Verde Escudo"},{"code":"CYP","description":"Cypriot
58
+ Pound"},{"code":"CZK","description":"Czech Koruna"},{"code":"DEM","description":"German
59
+ Mark"},{"code":"DJF","description":"Djibouti Franc"},{"code":"DKK","description":"Danish
60
+ Krone"},{"code":"DOP","description":"Dominican Peso"},{"code":"DZD","description":"Algerian
61
+ Dinar"},{"code":"ECS","description":"Ecuador Sucre"},{"code":"EEK","description":"Estonian
62
+ Kroon"},{"code":"EGP","description":"Egyptian Pound"},{"code":"ERN","description":"Eritrean
63
+ Nakfa"},{"code":"ESP","description":"Spanish Peseta"},{"code":"ETB","description":"Ethiopian
64
+ Birr"},{"code":"EUR","description":"Euro"},{"code":"FIM","description":"Finnish
65
+ Markka"},{"code":"FJD","description":"Fiji Dollar"},{"code":"FKP","description":"Falkland
66
+ Islands Pound"},{"code":"FRF","description":"French Franc"},{"code":"GBP","description":"United
67
+ Kingdom Pound"},{"code":"GEL","description":"Georgian Lari"},{"code":"GHC","description":"Ghanian
68
+ Old Cedi"},{"code":"GHS","description":"Ghanaian New Cedi"},{"code":"GIP","description":"Gibraltar
69
+ Pound"},{"code":"GMD","description":"Gambian Dalasi"},{"code":"GNF","description":"Guinea
70
+ Franc"},{"code":"GRD","description":"Greek Drachma"},{"code":"GTQ","description":"Guatemalan
71
+ Quetzal"},{"code":"GYD","description":"Guyanan Dollar"},{"code":"HKD","description":"Hong
72
+ Kong Dollar"},{"code":"HNL","description":"Honduran Lempira"},{"code":"HRK","description":"Croatian
73
+ Kuna"},{"code":"HTG","description":"Haitian Gourde"},{"code":"HUF","description":"Hungarian
74
+ Forint"},{"code":"IDR","description":"Indonesian Rupiah"},{"code":"IEP","description":"Irish
75
+ Punt"},{"code":"ILS","description":"Israeli New Shekel"},{"code":"INR","description":"Indian
76
+ Rupee"},{"code":"IQD","description":"Iraqi Dinar"},{"code":"IRR","description":"Iranian
77
+ Rial"},{"code":"ISK","description":"Iceland Krona"},{"code":"ITL","description":"Italian
78
+ Lira"},{"code":"JMD","description":"Jamaican Dollar"},{"code":"JOD","description":"Jordanian
79
+ Dinar"},{"code":"JPY","description":"Japanese Yen"},{"code":"KES","description":"Kenyan
80
+ Shilling"},{"code":"KGS","description":"Kyrgyzstanian Som"},{"code":"KHR","description":"Cambodian
81
+ Riel"},{"code":"KMF","description":"Comoros Franc"},{"code":"KPW","description":"North
82
+ Korean Won"},{"code":"KRW","description":"Korean Won"},{"code":"KWD","description":"Kuwaiti
83
+ Dinar"},{"code":"KYD","description":"Cayman Islands Dollar"},{"code":"KZT","description":"Kazakhstan
84
+ Tenge"},{"code":"LAK","description":"Lao Kip"},{"code":"LBP","description":"Lebanese
85
+ Pound"},{"code":"LKR","description":"Sri Lanka Rupee"},{"code":"LRD","description":"Liberian
86
+ Dollar"},{"code":"LSL","description":"Lesotho Loti"},{"code":"LTL","description":"Lithuanian
87
+ Litas"},{"code":"LUF","description":"Luxembourg Franc"},{"code":"LVL","description":"Latvian
88
+ Lats"},{"code":"LYD","description":"Libyan Dinar"},{"code":"MAD","description":"Moroccan
89
+ Dirham"},{"code":"MDL","description":"Moldovan Leu"},{"code":"MGA","description":"Malagasy
90
+ Ariary"},{"code":"MGF","description":"Malagasy Old Franc"},{"code":"MKD","description":"Macedonian
91
+ Denar"},{"code":"MMK","description":"Myanmar Kyat"},{"code":"MNT","description":"Mongolian
92
+ Tugrik"},{"code":"MOP","description":"Macau Pataca"},{"code":"MRO","description":"Mauritanian
93
+ Ouguiya"},{"code":"MTL","description":"Maltese Lira"},{"code":"MUR","description":"Mauritius
94
+ Rupee"},{"code":"MVR","description":"Maldive Rufiyaa"},{"code":"MWK","description":"Malawi
95
+ Kwacha"},{"code":"MXN","description":"Mexican Peso"},{"code":"MYR","description":"Malaysian
96
+ Ringgit"},{"code":"MZM","description":"Mozambique Old Metical"},{"code":"MZN","description":"Mozambique
97
+ New Metical"},{"code":"NAD","description":"Namibia Dollar"},{"code":"NGN","description":"Nigerian
98
+ Naira"},{"code":"NIO","description":"Nicaraguan Cordoba Oro"},{"code":"NLG","description":"Dutch
99
+ Guilder"},{"code":"NOK","description":"Norwegian Kroner"},{"code":"NPR","description":"Nepalese
100
+ Rupee"},{"code":"NZD","description":"New Zealand Dollar"},{"code":"OMR","description":"Omani
101
+ Rial"},{"code":"PAB","description":"Panamanian Balboa"},{"code":"PEN","description":"Peruvian
102
+ Nuevo Sol"},{"code":"PGK","description":"Papua New Guinea Kina"},{"code":"PHP","description":"Philippine
103
+ Peso"},{"code":"PKR","description":"Pakistan Rupee"},{"code":"PLN","description":"Polish
104
+ Zloty"},{"code":"PTE","description":"Portuguese Escudo"},{"code":"PYG","description":"Paraguay
105
+ Guarani"},{"code":"QAR","description":"Qatari Rial"},{"code":"ROL","description":"Romanian
106
+ Old Leu"},{"code":"RON","description":"Romanian New Leu"},{"code":"RSD","description":"Serbian
107
+ Dinar"},{"code":"RUB","description":"Russian Rouble"},{"code":"RWF","description":"Rwandan
108
+ Franc"},{"code":"SAR","description":"Saudi Riyal"},{"code":"SBD","description":"Solomon
109
+ Islands Dollar"},{"code":"SCR","description":"Seychelles Rupee"},{"code":"SDD","description":"Sudanese
110
+ Old Dinar"},{"code":"SDG","description":"Sudanese Pound"},{"code":"SDP","description":"Sudanese
111
+ Old Pound"},{"code":"SEK","description":"Swedish Krona"},{"code":"SGD","description":"Singapore
112
+ Dollar"},{"code":"SHP","description":"St. Helena Pound"},{"code":"SIT","description":"Slovenian
113
+ Tolar"},{"code":"SKK","description":"Slovak Koruna"},{"code":"SLL","description":"Sierra
114
+ Leone Leone"},{"code":"SOS","description":"Somali Shilling"},{"code":"SRD","description":"Suriname
115
+ Dollar"},{"code":"SRG","description":"Suriname Old Guilder"},{"code":"STD","description":"Sao
116
+ Tome/Principe Dobra"},{"code":"SVC","description":"El Salvador Colon"},{"code":"SYP","description":"Syrian
117
+ Pound"},{"code":"SZL","description":"Swaziland Lilangeni"},{"code":"THB","description":"Thai
118
+ Baht"},{"code":"TJS","description":"Tajikistan Somoni"},{"code":"TMM","description":"Turkmenistan
119
+ Old Manat"},{"code":"TMT","description":"Turkmenistan New Manat"},{"code":"TND","description":"Tunisian
120
+ Dinar"},{"code":"TOP","description":"Tongan Pa''anga"},{"code":"TRL","description":"Turkish
121
+ Old Lira"},{"code":"TRY","description":"Turkish Lira"},{"code":"TTD","description":"Trinidad/Tobago
122
+ Dollar"},{"code":"TWD","description":"Taiwan Dollar"},{"code":"TZS","description":"Tanzanian
123
+ Shilling"},{"code":"UAH","description":"Ukraine Hryvnia"},{"code":"UGX","description":"Uganda
124
+ Shilling"},{"code":"USD","description":"US Dollar"},{"code":"UYU","description":"Uruguayan
125
+ Peso"},{"code":"UZS","description":"Uzbekistan Som"},{"code":"VEB","description":"Venezuelan
126
+ Bolivar"},{"code":"VEF","description":"Venezuelan Bolivar Fuerte"},{"code":"VND","description":"Vietnamese
127
+ Dong"},{"code":"VUV","description":"Vanuatu Vatu"},{"code":"WST","description":"Samoan
128
+ Tala"},{"code":"XAF","description":"CFA Franc BEAC"},{"code":"XAG","description":"Silver
129
+ (oz.)"},{"code":"XAU","description":"Gold (oz.)"},{"code":"XCD","description":"East
130
+ Carribean Dollar"},{"code":"XEU","description":"ECU"},{"code":"XOF","description":"CFA
131
+ Franc BCEAO"},{"code":"XPD","description":"Palladium (oz.)"},{"code":"XPF","description":"CFP
132
+ Franc"},{"code":"XPT","description":"Platinum (oz.)"},{"code":"YER","description":"Yemen
133
+ Rial"},{"code":"YUN","description":"Yugoslavian Old Dinar"},{"code":"ZAR","description":"South
134
+ African Rand"},{"code":"ZMK","description":"Zambian Kwacha"},{"code":"ZMW","description":"Zambian
135
+ Kwacha"},{"code":"ZWD","description":"Zimbabwe Dollar"}]}'
136
+ http_version:
137
+ recorded_at: Thu, 12 Feb 2015 23:41:21 GMT
138
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,35 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.oanda.com/rates/api/v1/remaining_quotes.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - Bearer
12
+ response:
13
+ status:
14
+ code: 400
15
+ message: Bad Request
16
+ headers:
17
+ Date:
18
+ - Thu, 12 Feb 2015 23:41:21 GMT
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '77'
23
+ Connection:
24
+ - keep-alive
25
+ Server:
26
+ - nginx
27
+ X-Oanda-Exchange-Rates-Api-Version:
28
+ - 1.0.2
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"code":8,"message":"Malformed Authorization header or invalid access
32
+ token"}'
33
+ http_version:
34
+ recorded_at: Thu, 12 Feb 2015 23:41:21 GMT
35
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,41 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.oanda.com/rates/api/v1/rates/USD.json?date=2015-02-11&quote=GBP
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - Bearer {OANDA_API_KEY}
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Date:
18
+ - Thu, 12 Feb 2015 23:41:20 GMT
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '311'
23
+ Connection:
24
+ - keep-alive
25
+ Server:
26
+ - nginx
27
+ Vary:
28
+ - Accept-Encoding
29
+ X-Oanda-Exchange-Rates-Api-Version:
30
+ - 1.0.2
31
+ X-Rate-Limit-Remaining:
32
+ - '99992'
33
+ Set-Cookie:
34
+ - opc_id=A5A76274-B310-11E4-8347-B169D88622F7; path=/; Expires=Sun, 09-Feb-2025
35
+ 23:41:20 GMT
36
+ body:
37
+ encoding: UTF-8
38
+ string: '{"base_currency":"USD","meta":{"effective_params":{"data_set":"oanda","date":"2015-02-11","decimal_places":5,"fields":["averages"],"quote_currencies":["GBP"]},"request_time":"2015-02-12T23:41:20+0000","skipped_currencies":[]},"quotes":{"GBP":{"ask":"0.65542","bid":"0.65533","date":"2015-02-11T21:00:00+0000"}}}'
39
+ http_version:
40
+ recorded_at: Thu, 12 Feb 2015 23:41:20 GMT
41
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.oanda.com/rates/api/v1/remaining_quotes.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - Bearer {OANDA_API_KEY}
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Date:
18
+ - Thu, 12 Feb 2015 23:41:21 GMT
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '26'
23
+ Connection:
24
+ - keep-alive
25
+ Server:
26
+ - nginx
27
+ Vary:
28
+ - Accept-Encoding
29
+ X-Oanda-Exchange-Rates-Api-Version:
30
+ - 1.0.2
31
+ Set-Cookie:
32
+ - opc_id=A61A0FCC-B310-11E4-9820-ED2700000000; path=/; Expires=Sun, 09-Feb-2025
33
+ 23:41:21 GMT
34
+ body:
35
+ encoding: UTF-8
36
+ string: '{"remaining_quotes":99992}'
37
+ http_version:
38
+ recorded_at: Thu, 12 Feb 2015 23:41:21 GMT
39
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,6 @@
1
+ require "oanda_ruby_client/version"
2
+ require "oanda_ruby_client/exchange_rates_client"
3
+ require "oanda_ruby_client/rates_request"
4
+
5
+ module OandaRubyClient
6
+ end
@@ -0,0 +1,80 @@
1
+ require 'httparty'
2
+ require 'ostruct'
3
+
4
+ module OandaRubyClient
5
+
6
+ class ExchangeRatesClient
7
+
8
+ # @param api_key [String] The API key for the Excange Rates API.
9
+ # @param use_ssl [Boolean] If +true+, sets the URL endpoint scheme to +https+. If
10
+ # +false+, sets the scheme to +http+.
11
+ def initialize(api_key = ENV['OANDA_RUBY_CLIENT_API_KEY'], use_ssl = true)
12
+ @api_key, @use_ssl = api_key, use_ssl
13
+ end
14
+
15
+ # @return [Hash<String, String>] a hash of the supported currency codes to their descriptions
16
+ def currencies
17
+ currencies_response = HTTParty.get("#{oanda_endpoint}#{CURRENCIES_PATH}", headers: oanda_headers)
18
+ handle_response(currencies_response.response)
19
+ result = {}
20
+ currencies_response.parsed_response['currencies'].each do |currency|
21
+ result[currency['code']] = currency['description']
22
+ end
23
+ result
24
+ end
25
+
26
+ # Returns the exchanges rates based on the specified request
27
+ #
28
+ # @param rates_request [OandaRubyClient::RatesRequest] Request criteria
29
+ # @return [OpenStruct] An object structured similarly to the response from the Exchange Rate API
30
+ def rates(rates_request)
31
+ rates_uri = "#{oanda_endpoint}#{RATES_BASE_PATH}#{rates_request.base_currency}.json?#{rates_request.query_string}"
32
+ rates_response = HTTParty.get(rates_uri, headers: oanda_headers)
33
+ handle_response(rates_response.response)
34
+ OpenStruct.new(rates_response.parsed_response)
35
+ end
36
+
37
+ # Returns the number of remaining quote requests
38
+ #
39
+ # @return [Fixnum, 'unlimited'] Number of remaining quote requests
40
+ def remaining_quotes
41
+ remaining_quotes_response = HTTParty.get("#{oanda_endpoint}#{REMAINING_QUOTES_PATH}", headers: oanda_headers)
42
+ handle_response(remaining_quotes_response.response)
43
+ remaining_quotes_response.parsed_response['remaining_quotes']
44
+ end
45
+
46
+ private
47
+
48
+ OANDA_ENDPOINT = '//www.oanda.com/rates/api/v1/' #:nodoc:
49
+
50
+ RATES_BASE_PATH = 'rates/' #:nodoc:
51
+ CURRENCIES_PATH = 'currencies.json' #:nodoc:
52
+ REMAINING_QUOTES_PATH = 'remaining_quotes.json' #:nodoc:
53
+
54
+ attr_accessor :api_key, :use_ssl
55
+
56
+ def handle_response(response)
57
+ if response.code_type != Net::HTTPOK
58
+ if response.body
59
+ raise JSON.parse(response.body)['message']
60
+ else
61
+ raise response
62
+ end
63
+ end
64
+ end
65
+
66
+ def oanda_headers
67
+ { 'Authorization' => "Bearer #{@api_key}"}
68
+ end
69
+
70
+ def oanda_endpoint
71
+ "#{scheme}#{OANDA_ENDPOINT}"
72
+ end
73
+
74
+ def scheme
75
+ @use_ssl ? 'https:' : 'http:'
76
+ end
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,30 @@
1
+ require 'date'
2
+ require 'addressable/uri'
3
+
4
+ module OandaRubyClient
5
+
6
+ class RatesRequest
7
+
8
+ attr_accessor :base_currency, :query_params
9
+
10
+ # @param base_currency [String] Currency code for the base currency
11
+ # @param query_params [Hash] Optional query parameters
12
+ def initialize(base_currency, query_params = {})
13
+ @base_currency, @query_params = base_currency.to_s.upcase, query_params
14
+ end
15
+
16
+ # @return [String] the query string that will be passed to the API
17
+ def query_string
18
+ [ :date, :start, :end ].each do |date_key|
19
+ if query_params[date_key] && query_params[date_key].is_a?(Date)
20
+ query_params[date_key] = query_params[date_key].iso8601
21
+ end
22
+ end
23
+ uri = Addressable::URI.new
24
+ uri.query_values = query_params
25
+ uri.query
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,3 @@
1
+ module OandaRubyClient
2
+ VERSION = "1.0.0.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'oanda_ruby_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oanda_ruby_client"
8
+ spec.version = OandaRubyClient::VERSION
9
+ spec.authors = ["David Massad"]
10
+ spec.email = ["david.massad@fronteraconsulting.net"]
11
+
12
+ spec.summary = "Oanda Ruby Client"
13
+ spec.description = 'Provides a client for the Oanda Exchange Rate API'
14
+ spec.homepage = "https://github.com/FronteraConsulting/oanda_ruby_client"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'httparty'
22
+ spec.add_dependency 'addressable', '~> 2.3.7'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.8"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'vcr', '~> 2.9.3'
28
+ spec.add_development_dependency 'webmock', '~> 1.20.4'
29
+ spec.add_development_dependency 'simplecov', '~> 0.9.1'
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oanda_ruby_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - David Massad
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: addressable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.3.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.9.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.9.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.20.4
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.20.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.1
125
+ description: Provides a client for the Oanda Exchange Rate API
126
+ email:
127
+ - david.massad@fronteraconsulting.net
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - CODE_OF_CONDUCT.md
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - fixtures/vcr_cassettes/oanda/currencies.yml
144
+ - fixtures/vcr_cassettes/oanda/missing_api_key.yml
145
+ - fixtures/vcr_cassettes/oanda/rates.yml
146
+ - fixtures/vcr_cassettes/oanda/remaining_quotes.yml
147
+ - lib/oanda_ruby_client.rb
148
+ - lib/oanda_ruby_client/exchange_rates_client.rb
149
+ - lib/oanda_ruby_client/rates_request.rb
150
+ - lib/oanda_ruby_client/version.rb
151
+ - oanda_ruby_client.gemspec
152
+ homepage: https://github.com/FronteraConsulting/oanda_ruby_client
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.4.5
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Oanda Ruby Client
176
+ test_files: []
177
+ has_rdoc: