-
Notifications
You must be signed in to change notification settings - Fork 5
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 #2 from rafasimao/master
Add campaigns method to client and refactors connection requests.
- Loading branch information
Showing
5 changed files
with
126 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module GetResponseApi | ||
VERSION = '0.1.0' | ||
VERSION = '0.2.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 |
---|---|---|
|
@@ -2,43 +2,85 @@ | |
require 'webmock/rspec' | ||
|
||
RSpec.describe GetResponseApi::Client do | ||
let(:header) { {'Content-Type': 'application/json'} } | ||
let(:header) { {'Content-Type' => 'application/json'} } | ||
let(:url) { 'https://api.getresponse.com/v3' } | ||
let(:client) { described_class.new('1236547hjuh') } | ||
|
||
describe '#account' do | ||
before do | ||
WebMock.stub_request(:get, "#{url}/accounts") | ||
.to_return(body: response, headers: header) | ||
.to_return(body: response, headers: header) | ||
end | ||
|
||
context 'when the request is valid' do | ||
let(:response) { result.to_json } | ||
let(:result) do | ||
{ | ||
"accountId"=>"pdIhh", | ||
"firstName"=>"Jane", | ||
"lastName"=>"Doe", | ||
"email"=>"[email protected]" | ||
} | ||
'accountId' => 'pdIhh', | ||
'firstName' => 'Jane', | ||
'lastName' => 'Doe', | ||
'email' => '[email protected]' | ||
} | ||
end | ||
let(:response) { result.to_json } | ||
|
||
subject { client.account } | ||
|
||
it { is_expected.to eq(result) } | ||
end | ||
|
||
context 'when the request is invalid' do | ||
let(:error_message) do | ||
'Unable to authenticate request. ' \ | ||
'Check credentials or authentication method details' | ||
end | ||
let(:response) do | ||
{ | ||
'httpStatus' => 401, | ||
'message' => error_message | ||
}.to_json | ||
end | ||
|
||
subject { client.account } | ||
|
||
it { is_expected.to eq(error_message) } | ||
end | ||
end | ||
|
||
describe '#campaigns' do | ||
before do | ||
WebMock.stub_request(:get, "#{url}/campaigns") | ||
.to_return(body: response, headers: header) | ||
end | ||
|
||
context 'when the request is valid' do | ||
let(:result) do | ||
[{ | ||
"campaignId" => "B", | ||
"name" => "TestCampaigns", | ||
"description" => "New test campaign", | ||
"isDefault" => "true", | ||
}] | ||
end | ||
let(:response) { result.to_json } | ||
|
||
subject{ client.account() } | ||
subject { client.campaigns } | ||
|
||
it { is_expected.to eq(result) } | ||
end | ||
|
||
context 'when the request is invalid' do | ||
let(:error_message) do | ||
'Unable to authenticate request. Check credentials or authentication method details' | ||
'Unable to authenticate request. ' \ | ||
'Check credentials or authentication method details' | ||
end | ||
let(:response) do | ||
{ | ||
"httpStatus"=>401, | ||
"message"=>error_message | ||
'httpStatus' => 401, | ||
'message' => error_message | ||
}.to_json | ||
end | ||
|
||
subject{ client.account() } | ||
subject { client.campaigns } | ||
|
||
it { is_expected.to eq(error_message) } | ||
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