This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1 from Fretadao/bv-add-contact-list-service
Add contact list service
- Loading branch information
Showing
9 changed files
with
159 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
## [0.1.0] - 2023-03-02 | ||
|
||
- Initial release | ||
- Add base gem; | ||
- Add Contact list service (filtering by id); |
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,8 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'f_http_client' | ||
require_relative 'ploomes_client/version' | ||
|
||
require_relative 'ploomes_client/configuration' | ||
require_relative 'ploomes_client/base' | ||
require_relative 'ploomes_client/contact/list' | ||
|
||
module PloomesClient | ||
class Error < StandardError; end | ||
# Your code goes here... | ||
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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module PloomesClient | ||
class Base < FHTTPClient::Base | ||
def self.config | ||
@config ||= PloomesClient::Configuration.config | ||
end | ||
|
||
private | ||
|
||
def headers | ||
{ | ||
'User-Key' => config.user_key, | ||
'Content-Type' => 'application/json', | ||
'odata.metadata' => 'minimal' | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module PloomesClient | ||
class Configuration < FHTTPClient::Configuration | ||
setting :user_key | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module PloomesClient | ||
module Contact | ||
class List < PloomesClient::Base | ||
option :id, default: -> {} | ||
|
||
private | ||
|
||
def make_request | ||
self.class.get(formatted_path, headers: headers) | ||
end | ||
|
||
def path_template | ||
'/Contacts?$filter=Id+eq+%<id>s' | ||
end | ||
|
||
def path_params | ||
id.present? ? { id: id } : super | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe PloomesClient::Base do | ||
describe '.config' do | ||
it { expect(described_class.config).to eq(PloomesClient::Configuration.config) } | ||
end | ||
|
||
describe 'headers' do | ||
subject(:client) do | ||
Class.new(described_class) do | ||
base_uri 'localhost:3000' | ||
|
||
private | ||
|
||
def make_request | ||
self.class.get(formatted_path, headers: headers) | ||
end | ||
|
||
def path_template | ||
'/test' | ||
end | ||
end | ||
end | ||
|
||
before do | ||
PloomesClient::Configuration.configure do |config| | ||
config.user_key = 'user-key-123' | ||
end | ||
|
||
stub_get( | ||
{ | ||
headers: { | ||
'User-Key' => 'user-key-123', | ||
'Content-Type' => 'application/json', | ||
'odata.metadata' => 'minimal' | ||
} | ||
}, | ||
to: 'localhost:3000/test' | ||
) | ||
end | ||
|
||
it { expect(client.()).to have_succeed_with(:ok, :successful) } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe PloomesClient::Contact::List do | ||
describe 'run' do | ||
let(:ploomes_response) { load_fixture_json_symbolized('contact/list/response_with_result.json') } | ||
let(:id) { 123 } | ||
|
||
before do | ||
PloomesClient::Configuration.configure do |config| | ||
config.base_uri = 'localhost:3000' | ||
config.user_key = 'user-key-123' | ||
end | ||
|
||
stub_get( | ||
{ | ||
headers: { | ||
'User-Key' => 'user-key-123', | ||
'Content-Type' => 'application/json', | ||
'odata.metadata' => 'minimal' | ||
} | ||
}, | ||
to: "localhost:3000/Contacts?$filter=Id+eq+#{id}", | ||
response_body: ploomes_response | ||
) | ||
end | ||
|
||
describe 'filtering by path_params explicity' do | ||
it 'filters by path params id', :aggregate_failures do | ||
result = described_class.(path_params: { id: id }) | ||
|
||
expect(result).to have_succeed_with(:ok, :successful) | ||
|
||
first_contact = result.value[:value].first | ||
|
||
expect(first_contact[:Name]).to eq('Contact 1') | ||
expect(first_contact[:Email]).to eq('[email protected]') | ||
end | ||
end | ||
|
||
describe 'filtering by id directly' do | ||
it 'filters id', :aggregate_failures do | ||
result = described_class.(id: id) | ||
|
||
expect(result).to have_succeed_with(:ok, :successful) | ||
|
||
first_contact = result.value[:value].first | ||
|
||
expect(first_contact[:Name]).to eq('Contact 1') | ||
expect(first_contact[:Email]).to eq('[email protected]') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'simplecov' | ||
require 'pry-nav' | ||
|
||
SimpleCov.start do | ||
add_filter 'spec' | ||
|
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