diff --git a/README.md b/README.md index e90f17d..29fe5f7 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,20 @@ Ou instale você mesmo: Os métodos da API estão disponíveis atraves dos métodos da instancia de um cliente ```ruby - client = Vindi::Client.new(key: 'VINDI_KEY') + client = Vindi::Client.new(key: '') +``` + +Para testar no ambiente Sandbox, use o endpoint da API para efetuar requisições: + +```ruby + client = Vindi::Client.new(key: '', api_endpoint: 'https://sandbox-app.vindi.com.br/api/v1') +``` + +Caso prefira utilizar variáveis de ambiente para prover credenciais de acesso: + +``` +export VINDI_KEY="" +export VINDI_API_ENDPOINT="https://sandbox-app.vindi.com.br/api/v1" ``` ### Consumindo recursos diff --git a/lib/vindi/version.rb b/lib/vindi/version.rb index 6e61e12..89e0f63 100644 --- a/lib/vindi/version.rb +++ b/lib/vindi/version.rb @@ -1,3 +1,3 @@ module Vindi - VERSION = '0.0.2' + VERSION = '0.0.4' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ef092d3..561e971 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ SimpleCov.start VINDI_STAGING_ENDPOINT = "https://staging-app.vindi.com.br/api/v1/".freeze +VINDI_SANDBOX_ENDPOINT = "https://sandbox-app.vindi.com.br/api/v1/".freeze require 'vindi' require 'rspec' diff --git a/spec/vindi/client_spec.rb b/spec/vindi/client_spec.rb index 0952139..4e1da96 100644 --- a/spec/vindi/client_spec.rb +++ b/spec/vindi/client_spec.rb @@ -1,13 +1,14 @@ require 'spec_helper' RSpec.describe Vindi::Client do - let(:options) { { key: 'xDw3elPwddlzqgFzJqZXkiy-jZlzVvY7L1aVdcDbMHg', - default_media_type: 'application/vnd.api+json' } } - + let(:options) do + { key: key, default_media_type: 'application/vnd.api+json' } + end + let(:key) { 'xDw3elPwddlzqgFzJqZXkiy-jZlzVvY7L1aVdcDbMHg' } let(:client) { basic_auth_client } context 'initialization' do - describe 'when initialize a new client' do + describe 'when initialize a new client with default settings' do it 'overrides default settings' do expect(client.key).to eq(options[:key]) expect(client.default_media_type).to eq(options[:default_media_type]) @@ -22,6 +23,25 @@ expect(client.default_media_type).to eq(options[:default_media_type]) end end + + describe 'when initializing a client with custom settings' do + it 'use sandbox endpoint via class parameters' do + api_endpoint = VINDI_SANDBOX_ENDPOINT + sandbox_client = Vindi::Client.new(key: key, api_endpoint: api_endpoint) + + expect(sandbox_client.api_endpoint).to eq(api_endpoint) + end + + it 'use sandbox endpoint via system variables' do + api_endpoint = VINDI_SANDBOX_ENDPOINT + ENV['VINDI_API_ENDPOINT'] = api_endpoint + ENV['VINDI_KEY'] = key + sandbox_client = Vindi::Client.new + + expect(sandbox_client.api_endpoint).to eq(api_endpoint) + expect(sandbox_client.key).to eq(key) + end + end end context 'requests' do