-
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.
Merge pull request #46 from sul-dlss/43-org-endpoint
add organization and storage endpoints (read only)
- Loading branch information
Showing
5 changed files
with
306 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
class FolioClient | ||
# Query organization records in Folio; see | ||
# https://s3.amazonaws.com/foliodocs/api/mod-organizations/p/organizations.html | ||
# https://s3.amazonaws.com/foliodocs/api/mod-organizations-storage/p/interface.html | ||
class Organizations | ||
attr_accessor :client | ||
|
||
# @param client [FolioClient] the configured client | ||
def initialize(client) | ||
@client = client | ||
end | ||
|
||
# @param query [String] an optional query to limit the number of organizations returned | ||
# @param limit [Integer] the number of results to return (defaults to 10,000) | ||
# @param offset [Integer] the offset for results returned (defaults to 0) | ||
# @param lang [String] language code for returned results (defaults to 'en') | ||
def fetch_list(query: nil, limit: 10000, offset: 0, lang: "en") | ||
params = {limit: limit, offset: offset, lang: lang} | ||
params[:query] = query if query | ||
client.get("/organizations/organizations", params) | ||
end | ||
|
||
# @param query [String] an optional query to limit the number of organization interfaces returned | ||
# @param limit [Integer] the number of results to return (defaults to 10,000) | ||
# @param offset [Integer] the offset for results returned (defaults to 0) | ||
# @param lang [String] language code for returned results (defaults to 'en') | ||
def fetch_interface_list(query: nil, limit: 10000, offset: 0, lang: "en") | ||
params = {limit: limit, offset: offset, lang: lang} | ||
params[:query] = query if query | ||
client.get("/organizations-storage/interfaces", params) | ||
end | ||
|
||
# @param id [String] id for requested storage interface | ||
# @param lang [String] language code for returned result (defaults to 'en') | ||
def fetch_interface_details(id:, lang: "en") | ||
client.get("/organizations-storage/interfaces/#{id}", { | ||
lang: lang | ||
}) | ||
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,123 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe FolioClient::Organizations do | ||
subject(:organizations) do | ||
described_class.new(client) | ||
end | ||
|
||
let(:args) { {url: url, login_params: login_params, okapi_headers: okapi_headers} } | ||
let(:url) { "https://folio.example.org" } | ||
let(:login_params) { {username: "username", password: "password"} } | ||
let(:okapi_headers) { {some_bogus_headers: "here"} } | ||
let(:token) { "a_long_silly_token" } | ||
let(:client) { FolioClient.configure(**args) } | ||
let(:id) { "some_long_id_that_is_long" } | ||
let(:query) { '"active=="true"' } | ||
|
||
before do | ||
stub_request(:post, "#{url}/authn/login") | ||
.to_return(status: 200, body: "{\"okapiToken\" : \"#{token}\"}") | ||
end | ||
|
||
context "when looking up a list of organizations" do | ||
context "when a query is specified" do | ||
before do | ||
stub_request(:get, "#{url}/organizations/organizations?lang=en&limit=10000&offset=0&query=#{query}") | ||
.to_return(status: 200, body: organization_response.to_json) | ||
end | ||
|
||
let(:organization_response) { | ||
{"totalRecords" => 1, | ||
"organizations" => [ | ||
{"id" => "12345", | ||
"name" => "Training videos"} | ||
]} | ||
} | ||
|
||
it "returns the organization list" do | ||
expect(organizations.fetch_list(query: query)).to eq(organization_response) | ||
end | ||
end | ||
|
||
context "when a query is not specified" do | ||
before do | ||
stub_request(:get, "#{url}/organizations/organizations?lang=en&limit=10000&offset=0") | ||
.to_return(status: 200, body: organization_response.to_json) | ||
end | ||
|
||
let(:organization_response) { | ||
{"totalRecords" => 1, | ||
"organizations" => [ | ||
{"id" => "12345", | ||
"name" => "Training videos"} | ||
]} | ||
} | ||
|
||
it "returns the organization list" do | ||
expect(organizations.fetch_list).to eq(organization_response) | ||
end | ||
end | ||
end | ||
|
||
context "when looking up a list of organization interfaces" do | ||
context "when a query is specified" do | ||
before do | ||
stub_request(:get, "#{url}/organizations-storage/interfaces?lang=en&limit=10000&offset=0&query=#{query}") | ||
.to_return(status: 200, body: organization_interface_response.to_json) | ||
end | ||
|
||
let(:organization_interface_response) { | ||
{"totalRecords" => 1, | ||
"interfaces" => [ | ||
{"id" => "12345", | ||
"description" => "Training videos"} | ||
]} | ||
} | ||
|
||
it "returns the organization list" do | ||
expect(organizations.fetch_interface_list(query: query)).to eq(organization_interface_response) | ||
end | ||
end | ||
|
||
context "when a query is not specified" do | ||
before do | ||
stub_request(:get, "#{url}/organizations-storage/interfaces?lang=en&limit=10000&offset=0") | ||
.to_return(status: 200, body: organization_interface_response.to_json) | ||
end | ||
|
||
let(:organization_interface_response) { | ||
{"totalRecords" => 1, | ||
"interfaces" => [ | ||
{"id" => "12345", | ||
"description" => "Training videos"} | ||
]} | ||
} | ||
|
||
it "returns the organization list" do | ||
expect(organizations.fetch_interface_list).to eq(organization_interface_response) | ||
end | ||
end | ||
end | ||
|
||
context "when looking up details of a specific organization interfaces" do | ||
before do | ||
stub_request(:get, "#{url}/organizations-storage/interfaces/#{id}?lang=en") | ||
.to_return(status: 200, body: organization_interface_detail_response.to_json) | ||
end | ||
|
||
let(:organization_interface_detail_response) { | ||
{"id" => id, | ||
"name" => "tes", | ||
"type" => ["Invoices"], | ||
"metadata" => | ||
{"createdDate" => "2023-02-16T22:27:51.515+00:00", | ||
"createdByUserId" => "38524916-598d-4edf-a2ef-04bba7e78ad6", | ||
"updatedDate" => "2023-02-16T22:27:51.515+00:00", | ||
"updatedByUserId" => "38524916-598d-4edf-a2ef-04bba7e78ad6"}} | ||
} | ||
|
||
it "returns the organization list" do | ||
expect(organizations.fetch_interface_details(id: id)).to eq(organization_interface_detail_response) | ||
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