├── .rspec ├── lib ├── arbolito │ ├── version.rb │ ├── currency │ │ ├── non_expirable_rate.rb │ │ ├── quote.rb │ │ └── rate.rb │ ├── store │ │ └── memory.rb │ └── exchange │ │ ├── yahoo_finance.rb │ │ └── alpha_vantage.rb └── arbolito.rb ├── .travis.yml ├── Gemfile ├── .gitignore ├── Rakefile ├── bin ├── setup └── console ├── spec ├── spec_helper.rb ├── support │ └── exchange_spy.rb ├── exchange │ ├── alpha_vantage_spec.rb │ └── yahoo_finance_spec.rb └── arbolito_spec.rb ├── LICENSE.txt ├── arbolito.gemspec ├── CODE_OF_CONDUCT.md └── README.md /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /lib/arbolito/version.rb: -------------------------------------------------------------------------------- 1 | module Arbolito 2 | VERSION = "0.3.1" 3 | end 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.1.5 4 | before_install: gem install bundler -v 1.10.4 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in arbolito.gemspec 4 | gemspec -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | .env -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task :default => :spec 7 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 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 8 | -------------------------------------------------------------------------------- /lib/arbolito/currency/non_expirable_rate.rb: -------------------------------------------------------------------------------- 1 | module Arbolito 2 | module Currency 3 | class NonExpirableRate < Rate 4 | def expired?(expiration_time) 5 | false 6 | end 7 | end 8 | end 9 | end -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'arbolito' 3 | require 'pry' 4 | 5 | Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f } 6 | 7 | RSpec.configure do |config| 8 | config.after(:each) do 9 | Arbolito::Store::Memory.clear 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/support/exchange_spy.rb: -------------------------------------------------------------------------------- 1 | module Arbolito 2 | module Exchange 3 | class Spy 4 | attr_reader :times_called 5 | 6 | def initialize 7 | @times_called = 0 8 | end 9 | 10 | def find_current_rate(quote) 11 | @times_called += 1 12 | Arbolito::Currency::Rate.new(BigDecimal.new(15), quote.to_hash) 13 | end 14 | end 15 | end 16 | end -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "arbolito" 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 15 | -------------------------------------------------------------------------------- /spec/exchange/alpha_vantage_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Arbolito::Exchange::AlphaVantage do 4 | let(:api_key) { ENV['ALPHA_VANTAGE_API_KEY'] } 5 | subject(:exchange) { Arbolito::Exchange::AlphaVantage.new(api_key) } 6 | let(:quote) { Arbolito::Currency::Quote.new('USD' => 'UYU') } 7 | 8 | it 'gives you the current rate of the desired currency conversion' do 9 | rate = exchange.find_current_rate(quote) 10 | 11 | expect(rate).to be_a(Arbolito::Currency::Rate) 12 | 13 | expect(rate.quote).to eq(quote) 14 | expect(rate.price).to be > 0 15 | expect(rate.rated_at).to be_between(Time.now - 60, Time.now) 16 | end 17 | end -------------------------------------------------------------------------------- /spec/exchange/yahoo_finance_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Arbolito::Exchange::YahooFinance do 4 | subject(:exchange) { Arbolito::Exchange::YahooFinance } 5 | let(:quote) { Arbolito::Currency::Quote.new('USD' => 'UYU') } 6 | 7 | # DEPRECATED Yahoo doesn't support anymore Yahoo Finance so use Alpha Vantage instead 8 | it 'gives you the current rate of the desired currency conversion' do 9 | rate = exchange.find_current_rate(quote) 10 | 11 | expect(rate).to be_a(Arbolito::Currency::Rate) 12 | 13 | expect(rate.quote).to eq(quote) 14 | expect(rate.price).to eq(0.0) 15 | expect(rate.rated_at).to be_between(Time.now - 60, Time.now) 16 | end 17 | end -------------------------------------------------------------------------------- /lib/arbolito/currency/quote.rb: -------------------------------------------------------------------------------- 1 | module Arbolito 2 | module Currency 3 | class Quote 4 | attr_reader :from, :to 5 | 6 | def initialize(hash) 7 | raise ArgumentError.new('You must specify 1 quote rate') if hash.size != 1 8 | 9 | @from = hash.keys.first.to_sym 10 | @to = hash.values.first.to_sym 11 | end 12 | 13 | def to_hash 14 | { @from => @to } 15 | end 16 | 17 | def backwards 18 | Quote.new( @to => @from ) 19 | end 20 | 21 | def ==(other_currency_quote) 22 | raise TypeError unless other_currency_quote.is_a?(Quote) 23 | 24 | @from == other_currency_quote.from && @to == other_currency_quote.to 25 | end 26 | end 27 | end 28 | end -------------------------------------------------------------------------------- /lib/arbolito/store/memory.rb: -------------------------------------------------------------------------------- 1 | module Arbolito 2 | module Store 3 | class Memory 4 | class << self 5 | def mutex 6 | @@mutex ||= Mutex.new 7 | end 8 | 9 | def add(rate) 10 | synchronize do 11 | hash[rate.quote.to_hash] = rate 12 | end 13 | end 14 | 15 | def fetch(quote) 16 | synchronize do 17 | hash[quote.to_hash] 18 | end 19 | end 20 | 21 | def clear 22 | synchronize do 23 | @@hash = {} 24 | end 25 | end 26 | 27 | def synchronize(&block) 28 | mutex.synchronize(&block) 29 | end 30 | 31 | def hash 32 | @@hash ||= {} 33 | end 34 | end 35 | end 36 | end 37 | end -------------------------------------------------------------------------------- /lib/arbolito/currency/rate.rb: -------------------------------------------------------------------------------- 1 | module Arbolito 2 | module Currency 3 | class Rate 4 | attr_reader :quote, :price, :rated_at 5 | 6 | def initialize(price, from_to_hash, rated_at = Time.now) 7 | @quote = Quote.new(from_to_hash) 8 | @price = BigDecimal.new(price) 9 | @rated_at = rated_at 10 | end 11 | 12 | def convert(money) 13 | @price * BigDecimal.new(money) 14 | end 15 | 16 | def backwards 17 | self.class.new(BigDecimal.new(1) / @price, @quote.backwards.to_hash) 18 | end 19 | 20 | def expired?(expiration_time) 21 | (Time.now - rated_at) > expiration_time 22 | end 23 | 24 | def ==(other_currency_rate) 25 | raise TypeError unless other_currency_rate.is_a?(CurrencyRate) 26 | 27 | @quote == other_currency_rate.quote && @price == @other.price 28 | end 29 | end 30 | end 31 | end -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 jvillarejo 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. 22 | -------------------------------------------------------------------------------- /arbolito.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'arbolito/version' 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "arbolito" 8 | s.version = Arbolito::VERSION 9 | s.authors = ["jvillarejo"] 10 | s.email = ["contact@jonvillage.com"] 11 | 12 | s.summary = "A currency conversion api for the minimalist developer" 13 | s.description = "A currency conversion that fetch from external source and also let's you add a fixed rate for different currencies" 14 | s.homepage = "https://github.com/jvillarejo/arbolito.git" 15 | s.license = "MIT" 16 | s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 17 | s.bindir = "exe" 18 | s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) } 19 | s.require_paths = ["lib"] 20 | 21 | s.add_development_dependency "bundler", "~> 1.10" 22 | s.add_development_dependency "rake", "~> 10.0" 23 | s.add_development_dependency "rspec", "~> 3.3" 24 | s.add_development_dependency "pry", "~> 0.10" 25 | end 26 | -------------------------------------------------------------------------------- /lib/arbolito/exchange/yahoo_finance.rb: -------------------------------------------------------------------------------- 1 | require 'net/http' 2 | 3 | module Arbolito 4 | module Exchange 5 | class YahooFinance 6 | class << self 7 | # DEPRECATED Yahoo Finance is not supported anymore by Yahoo so use Alpha Vantage API 8 | def find_current_rate(quote) 9 | warn "[DEPRECATION] Yahoo Finance `find_current_rate` is deprecated. Please use AlphaVantage `find_current_rate` instead." 10 | data = response(build_uri(quote)) 11 | 12 | values = { 13 | quote: quote, 14 | price: data[1], 15 | } 16 | 17 | build_rate(values) 18 | end 19 | 20 | private 21 | def response(uri) 22 | response = Net::HTTP.get(uri) 23 | data = response.gsub(/"|\\n/,'').split(',') 24 | end 25 | 26 | def build_uri(quote) 27 | param = "#{quote.from.upcase}#{quote.to.upcase}" 28 | URI("http://download.finance.yahoo.com/d/quotes.csv?s=#{param}=X&f=nl1d1t1") 29 | end 30 | 31 | def build_rate(values) 32 | Currency::Rate.new( 33 | values[:price], 34 | values[:quote].to_hash 35 | ) 36 | end 37 | end 38 | end 39 | end 40 | end -------------------------------------------------------------------------------- /lib/arbolito/exchange/alpha_vantage.rb: -------------------------------------------------------------------------------- 1 | require 'net/http' 2 | require 'json' 3 | 4 | module Arbolito 5 | module Exchange 6 | class AlphaVantage 7 | BaseURL = 'https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=%s&apikey=%s'.freeze 8 | 9 | attr_reader :api_key 10 | 11 | def initialize(api_key) 12 | @api_key = api_key 13 | end 14 | 15 | def find_current_rate(quote) 16 | data = response(build_uri(quote.from,quote.to)) 17 | rated_at_str = "#{data['6. Last Refreshed']} #{data['7. Time Zone']}" 18 | rated_at = Time.strptime(rated_at_str,'%Y-%m-%d %H:%M:%S %Z') 19 | 20 | values = { 21 | quote: quote.to_hash, 22 | price: data['5. Exchange Rate'], 23 | rated_at: rated_at.localtime 24 | } 25 | 26 | Currency::Rate.new( 27 | values[:price], 28 | values[:quote].to_hash, 29 | values[:rated_at] 30 | ) 31 | end 32 | 33 | def response(uri) 34 | response = Net::HTTP.get(uri) 35 | json = JSON.parse(response) 36 | json['Realtime Currency Exchange Rate'] 37 | end 38 | 39 | def build_uri(from, to) 40 | url = BaseURL % [from.upcase, to.upcase, api_key] 41 | URI(url) 42 | end 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 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, ethnicity, 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/) 14 | -------------------------------------------------------------------------------- /lib/arbolito.rb: -------------------------------------------------------------------------------- 1 | require 'bigdecimal' 2 | require 'time' 3 | require 'arbolito/currency/quote' 4 | require 'arbolito/currency/rate' 5 | require 'arbolito/currency/non_expirable_rate' 6 | require 'arbolito/store/memory' 7 | require 'arbolito/exchange/yahoo_finance' 8 | require 'arbolito/exchange/alpha_vantage' 9 | require "arbolito/version" 10 | 11 | module Arbolito 12 | 13 | class << self 14 | def add_currency_rate(currency_price, from_to_currencies) 15 | rate = Currency::NonExpirableRate.new(currency_price, from_to_currencies) 16 | add_to_store(rate) 17 | end 18 | 19 | def current_rate(from_to_currencies) 20 | fetch(Currency::Quote.new(from_to_currencies)).price 21 | end 22 | 23 | def convert(money, from_to_currencies) 24 | quote = Currency::Quote.new(from_to_currencies) 25 | 26 | rate = fetch(quote) 27 | 28 | rate.convert(money) 29 | end 30 | 31 | def settings 32 | @settings ||= {} 33 | end 34 | 35 | def set(config_key, value) 36 | settings[config_key] = value 37 | end 38 | 39 | private 40 | def add_to_store(rate) 41 | store.add(rate) 42 | store.add(rate.backwards) 43 | end 44 | 45 | def fetch(quote) 46 | rate = store.fetch(quote) 47 | 48 | if(!rate || rate.expired?(expiration_time)) 49 | rate = exchange.find_current_rate(quote) 50 | 51 | store.add(rate) 52 | end 53 | 54 | rate 55 | end 56 | 57 | def store 58 | settings[:store] ||= Store::Memory 59 | end 60 | 61 | def exchange 62 | settings[:exchange] ||= Exchange::YahooFinance 63 | end 64 | 65 | def expiration_time 66 | settings[:expiration_time] ||= 60 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /spec/arbolito_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Arbolito do 4 | it 'has a version number' do 5 | expect(Arbolito::VERSION).not_to be nil 6 | end 7 | 8 | describe 'adding a currency rate manually' do 9 | before { Arbolito.add_currency_rate(BigDecimal.new(15), 'USD' => 'ARS') } 10 | 11 | it 'lets you add fixed currency quotes' do 12 | expect(Arbolito.current_rate('USD' => 'ARS')).to eq(BigDecimal.new(15)) 13 | end 14 | 15 | it 'gives you the backward currency rate' do 16 | expect(Arbolito.current_rate('ARS' => 'USD')).to eq(BigDecimal.new(1) / BigDecimal.new(15)) 17 | end 18 | 19 | it 'can convert the money with the current currency rate' do 20 | expect(Arbolito.convert(BigDecimal.new(100), 'USD' => 'ARS')).to eq(BigDecimal.new(1500)) 21 | end 22 | 23 | it 'can convert the money backwards with the current currency rate' do 24 | expect(Arbolito.convert(BigDecimal.new(1500), 'ARS' => 'USD')).to eq(BigDecimal.new(1500) * (BigDecimal.new(1) / BigDecimal.new(15))) 25 | end 26 | end 27 | 28 | describe 'configuring arbolito' do 29 | it 'can set the expiration time' do 30 | Arbolito.set(:expiration_time, 24*60*60) 31 | 32 | expect(Arbolito.settings[:expiration_time]).to eq(24*60*60) 33 | end 34 | 35 | it 'can set the exchange' do 36 | Arbolito.set(:exchange, Arbolito::Exchange::YahooFinance) 37 | 38 | expect(Arbolito.settings[:exchange]).to eq(Arbolito::Exchange::YahooFinance) 39 | end 40 | 41 | it 'can set the exchange with api key' do 42 | Arbolito.set(:exchange, Arbolito::Exchange::AlphaVantage.new('asfakshfjkashfj')) 43 | 44 | expect(Arbolito.settings[:exchange]).to be_a(Arbolito::Exchange::AlphaVantage) 45 | expect(Arbolito.settings[:exchange].api_key).to eq('asfakshfjkashfj') 46 | end 47 | 48 | it 'can set the store' do 49 | Arbolito.set(:store, Arbolito::Store::Memory) 50 | 51 | expect(Arbolito.settings[:store]).to eq(Arbolito::Store::Memory) 52 | end 53 | end 54 | 55 | describe 'fetching for the currency rate remotely' do 56 | it 'can give you the currency rate using alpha vantage api' do 57 | Arbolito.set(:exchange, Arbolito::Exchange::AlphaVantage.new(ENV['ALPHA_VANTAGE_API_KEY'])) 58 | 59 | price = Arbolito.current_rate('USD' => 'UYU') 60 | 61 | expect(price).to be_instance_of(BigDecimal) 62 | expect(price).to be > 0 63 | end 64 | 65 | context 'when setting an expiration time' do 66 | let(:spy) { Arbolito::Exchange::Spy.new } 67 | 68 | before do 69 | Arbolito.set(:expiration_time,5) 70 | Arbolito.set(:exchange, spy) 71 | end 72 | 73 | it 'retrieves the same rate when time hasn\'t expired' do 74 | Arbolito.current_rate('USD' => 'ARS') 75 | Arbolito.current_rate('USD' => 'ARS') 76 | 77 | expect(spy.times_called).to eq(1) 78 | end 79 | 80 | it 'fetches a new rate when time expired' do 81 | Arbolito.current_rate('USD' => 'ARS') 82 | sleep(6) 83 | 84 | Arbolito.current_rate('USD' => 'ARS') 85 | 86 | expect(spy.times_called).to eq(2) 87 | end 88 | end 89 | end 90 | 91 | 92 | end 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arbolito 2 | 3 | Arbolito is a minimalist Ruby API for currency conversions, it has no dependencies except the Ruby Standard Library. 4 | 5 | It's like your Florida street best companion! 6 | 7 | ![Florida Street](http://i.imgur.com/qupBCJN.jpg) 8 | 9 | ## Features 10 | * Doesn't encapsulates the currencies in any object model, it just use `BigDecimal` class and `Hash` 11 | * You can add manually price rates 12 | * If the rate isn't found it fetches the rate using Yahoo Finance API as exchange or you can implement your own exchange. 13 | * You implement your own exchange and configure it 14 | * It stores in memory the rates fetched with a configurable expiration time 15 | * You can implement your own store and configure it 16 | * All the examples use the ISO 4217 code list for Currencies 17 | 18 | ## Motivation 19 | There were two reason why I've developed this gem. 20 | 21 | First the argetine economy makes difficult to keep the prices updated with official exchanges rates like Yahoo Finance, so we had to manage our own prices rates. But also I wanted to know the rates of other currencies through Yahoo Finance. This gem lets you do both. 22 | 23 | The second reason is that other gems implements their own money or currency model, and I didn't want to update all my models to manage those objects. That's why I tried to be agnostic on how you implement your currencies. 24 | 25 | The API just receives a Big Decimal and a hash describing the conversion 26 | 27 | ## Installation 28 | 29 | Add this line to your application's Gemfile: 30 | 31 | ```ruby 32 | gem 'arbolito' 33 | ``` 34 | And then execute: 35 | 36 | $ bundle 37 | Or install it yourself as: 38 | 39 | $ gem install arbolito 40 | ## Usage 41 | 42 | ``` ruby 43 | require 'arbolito' 44 | 45 | # We can add multiple rates 46 | 47 | Arbolito.add_currency_rate(BigDecimal.new(9), 'USD' => 'ARS') 48 | Arbolito.add_currency_rate(BigDecimal.new(15), 'USD Blue' => 'ARS') 49 | Arbolito.add_currency_rate(BigDecimal.new(12), 'USD Tarjeta' => 'ARS') 50 | Arbolito.add_currency_rate(BigDecimal.new(6.5), 'USD Moreno' => 'ARS') 51 | 52 | # It gives the stored rate 53 | Arbolito.current_rate('USD' => 'ARS') 54 | # => # 55 | 56 | # It stored rate backwards 57 | Arbolito.current_rate('ARS' => 'USD') 58 | # => # 59 | 60 | # It can make the conversion for you 61 | Arbolito.convert(BigDecimal.new(100), 'USD' => 'ARS') 62 | # => # 63 | 64 | Arbolito.convert(BigDecimal.new(100), 'USD Tarjeta' => 'ARS') 65 | => # 66 | 67 | # Now we ask for the Uruguayan pesos to USD rate 68 | Arbolito.current_rate('UYU' => 'USD') 69 | # 70 | 71 | # Now we ask to convert USD to Chilean Pesos 72 | Arbolito.convert(BigDecimal.new(100), 'USD' => 'CLP') 73 | => # 74 | 75 | # We can configure Arbolito expiration in seconds 76 | Arbolito.set(:expiration_time, 5 * 60) 77 | 78 | # We can implement our own Exchange and configure it in Arbolito 79 | Arbolito.set(:exchange, Exchange::FloridaStreet) 80 | 81 | # We can implement our own Store and configure it in Arbolito 82 | Arbolito.set(:store, Store::Mongo) 83 | 84 | ``` 85 | 86 | # Update: 2017-11-03 87 | Yahoo discountinued their Yahoo Finance API so I've implemented another Exchange [Alpha Vantage](https://www.alphavantage.co/). 88 | 89 | To use you need to get an API Key from them and the configure it like this. 90 | 91 | ```ruby 92 | api_key = ENV['API_KEY'] 93 | Arbolito.set(:exchange, Arbolito::Exchange::AlphaVantage.new(api_key)) 94 | ``` 95 | 96 | ## Implementing Store and Exchange 97 | 98 | Please take a look at the code to see how you can implement your own stores and exchanges. 99 | 100 | ## Contributing 101 | 102 | Bug reports and pull requests are welcome on GitHub at https://github.com/jvillarjeo/arbolito. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct. 103 | 104 | 105 | ## License 106 | 107 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 108 | 109 | --------------------------------------------------------------------------------