-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from ResultadosDigitais/add-rdsm-account-info-…
…endpoint Add the RDSM Account info endpoint
- Loading branch information
Showing
8 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module RDStation | ||
class Account | ||
include HTTParty | ||
include ::RDStation::RetryableRequest | ||
|
||
def initialize(authorization:) | ||
@authorization = authorization | ||
end | ||
|
||
def info | ||
retryable_request(@authorization) do |authorization| | ||
response = self.class.get(base_url, headers: authorization.headers) | ||
ApiResponse.build(response) | ||
end | ||
end | ||
|
||
private | ||
|
||
def base_url(_path = '') | ||
"#{RDStation.host}/marketing/account_info" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module RDStation | ||
VERSION = '2.8.2' | ||
VERSION = '2.9.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe RDStation::Account do | ||
let(:client) do | ||
described_class.new(authorization: RDStation::Authorization.new(access_token: 'access_token')) | ||
end | ||
|
||
let(:endpoint) { 'https://api.rd.services/marketing/account_info' } | ||
|
||
let(:headers) do | ||
{ | ||
'Authorization' => 'Bearer access_token', | ||
'Content-Type' => 'application/json' | ||
} | ||
end | ||
|
||
let(:error_handler) do | ||
instance_double(RDStation::ErrorHandler, raise_error: 'mock raised errors') | ||
end | ||
|
||
before do | ||
allow(RDStation::ErrorHandler).to receive(:new).and_return(error_handler) | ||
end | ||
|
||
describe '#info' do | ||
it 'calls retryable_request' do | ||
expect(client).to receive(:retryable_request) | ||
client.info | ||
end | ||
|
||
context 'when the request is successful' do | ||
before do | ||
stub_request(:get, endpoint) | ||
.with(headers: headers) | ||
.to_return(status: 200, body: {name: 'www.rdstation.com'}.to_json) | ||
end | ||
|
||
it 'return RDSM account information' do | ||
response = client.info | ||
expect(response).to eq({ 'name' => 'www.rdstation.com'}) | ||
end | ||
end | ||
|
||
context 'when the response contains errors' do | ||
before do | ||
stub_request(:get, endpoint) | ||
.with(headers: headers) | ||
.to_return(status: 404, body: { 'errors' => ['not found'] }.to_json) | ||
end | ||
|
||
it 'calls raise_error on error handler' do | ||
client.info | ||
expect(error_handler).to have_received(:raise_error) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters