Skip to content

Commit

Permalink
Insere explicação para conectar-se usando o ambiente Sandbox (#11)
Browse files Browse the repository at this point in the history
* Texto explicando como conectar-se usando o sandbox.

* Insere testes para endpoint Sandbox
  • Loading branch information
laerte-guimaraes authored Apr 24, 2019
1 parent a12345e commit 8a4f32b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<sua_vindi_api_key>')
```

Para testar no ambiente Sandbox, use o endpoint da API para efetuar requisições:

```ruby
client = Vindi::Client.new(key: '<sua_vindi_api_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="<sua_vindi_api_key>"
export VINDI_API_ENDPOINT="https://sandbox-app.vindi.com.br/api/v1"
```

### Consumindo recursos
Expand Down
2 changes: 1 addition & 1 deletion lib/vindi/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Vindi
VERSION = '0.0.2'
VERSION = '0.0.4'
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
28 changes: 24 additions & 4 deletions spec/vindi/client_spec.rb
Original file line number Diff line number Diff line change
@@ -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])
Expand All @@ -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
Expand Down

0 comments on commit 8a4f32b

Please sign in to comment.