-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add http client, support company/get and unit/lists requests
- Loading branch information
1 parent
c76bddf
commit 236c04a
Showing
10 changed files
with
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,7 @@ | |
/spec/reports/ | ||
/tmp/ | ||
|
||
.env | ||
|
||
# rspec failure tracking | ||
.rspec_status | ||
.rspec_status |
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
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,4 +1,8 @@ | ||
require "mapon_client/version" | ||
|
||
module MaponClient | ||
DEFAULT_BASE_URL = 'https://mapon.com/api/v1/'.freeze | ||
DEFAULT_FORMAT = 'json'.freeze | ||
|
||
autoload :Client, 'mapon_client/client' | ||
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,43 @@ | ||
require 'rest-client' | ||
|
||
module MaponClient | ||
class Client | ||
attr_reader :api_key, :base_url, :resource_base, :format | ||
|
||
def initialize(api_key: nil, base_url: nil, format: nil) | ||
@api_key = ( | ||
api_key || ENV['MAPON_CLIENT_API_KEY'] | ||
) | ||
|
||
@base_url = ( | ||
base_url || MaponClient::DEFAULT_BASE_URL | ||
) | ||
|
||
@format = ( | ||
format || MaponClient::DEFAULT_FORMAT | ||
) | ||
|
||
@resource_base ||= RestClient::Resource.new( | ||
@base_url, headers: { params: { key: @api_key } } | ||
) | ||
end | ||
|
||
def [](*args) | ||
@resource_base.public_send(:[], *args) | ||
end | ||
|
||
def company | ||
self[with_format("company/get")].get | ||
end | ||
|
||
def unit_list | ||
self[with_format("unit/list")].get | ||
end | ||
|
||
private | ||
|
||
def with_format(suburl) | ||
"#{suburl}.#{@format}" | ||
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
RSpec.describe MaponClient::Client do | ||
|
||
let(:mapon_client) { | ||
MaponClient::Client.new( | ||
api_key: 'fake_key_123', | ||
base_url: 'https://mapon.com/api/v1', | ||
format: 'json' | ||
) | ||
} | ||
|
||
it "#[] should delegate calls to #resource_base" do | ||
block_to_pass = Proc.new { } | ||
expect(mapon_client.resource_base).to receive(:[]).with('company/get', &block_to_pass) | ||
mapon_client.public_send(:[], 'company/get', &block_to_pass) | ||
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