-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[69628] Component CRUD support (#330)
This PR enables SDK support for the Nylas /component endpoints.
- Loading branch information
1 parent
6037211
commit 4ca4475
Showing
7 changed files
with
211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require_relative '../helpers' | ||
|
||
# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It | ||
# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). | ||
api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET']) | ||
|
||
# Create a component | ||
# NOTE: you will need to fill in the account_id and, if not set, the access_token | ||
demonstrate { api.components.create(name: "Ruby Component Test", type: "agenda", public_account_id: "ACCOUNT_ID", access_token: ENV['NYLAS_ACCESS_TOKEN']) } | ||
|
||
# Get all components | ||
demonstrate { api.components } | ||
|
||
# Retrieving a particular component | ||
example_component = api.components.last | ||
demonstrate { api.components.find(example_component.id).to_h } | ||
|
||
# Editing a particular component | ||
demonstrate do example_component.update( | ||
name: "New Updated Ruby Name" | ||
) | ||
end | ||
demonstrate { example_component.name } | ||
|
||
# Delete a component | ||
demonstrate { example_component.destroy } |
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Nylas | ||
# Structure to represent a the Component Schema. | ||
class Component | ||
include Model | ||
allows_operations(creatable: true, listable: true, filterable: true, showable: true, updatable: true, | ||
destroyable: true) | ||
|
||
attribute :id, :string, read_only: true | ||
attribute :account_id, :string | ||
attribute :name, :string | ||
attribute :type, :string | ||
attribute :action, :integer | ||
attribute :active, :boolean | ||
attribute :settings, :hash | ||
attribute :public_account_id, :string | ||
attribute :public_token_id, :string | ||
attribute :public_application_id, :string, read_only: true | ||
attribute :access_token, :string | ||
attribute :created_at, :date, read_only: true | ||
attribute :updated_at, :date, read_only: true | ||
|
||
has_n_of_attribute :allowed_domains, :string | ||
|
||
def resources_path(*) | ||
"/component/#{api.client.app_id}" | ||
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module Nylas | ||
# Additional configuration for the Component CRUD API | ||
class ComponentCollection < Collection | ||
def resources_path | ||
"/component/#{api.client.app_id}" | ||
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,136 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Nylas::Component do | ||
describe ".from_json" do | ||
it "Deserializes all the attributes into Ruby objects" do | ||
client = Nylas::HttpClient.new( | ||
app_id: "not-real", | ||
app_secret: "also-not-real", | ||
access_token: "seriously-unreal" | ||
) | ||
api = Nylas::API.new(client: client) | ||
data = { | ||
id: "abc-123", | ||
account_id: "account-123", | ||
name: "test-component", | ||
type: "agenda", | ||
action: 0, | ||
active: true, | ||
settings: {}, | ||
allowed_domains: [], | ||
public_account_id: "account-123", | ||
public_token_id: "token-123", | ||
public_application_id: "application-123", | ||
created_at: "2021-08-24T15:05:48.000Z", | ||
updated_at: "2021-08-24T15:05:48.000Z" | ||
} | ||
|
||
component = described_class.from_json(JSON.dump(data), api: api) | ||
|
||
expect(component.id).to eql "abc-123" | ||
expect(component.account_id).to eql "account-123" | ||
expect(component.name).to eql "test-component" | ||
expect(component.type).to eql "agenda" | ||
expect(component.action).to be 0 | ||
expect(component.active).to be true | ||
expect(component.settings).to eql({}) | ||
expect(component.allowed_domains).to eql([]) | ||
expect(component.public_account_id).to eql "account-123" | ||
expect(component.public_token_id).to eql "token-123" | ||
expect(component.public_application_id).to eql "application-123" | ||
expect(component.created_at).to eql Date.parse("2021-08-24") | ||
expect(component.updated_at).to eql Date.parse("2021-08-24") | ||
end | ||
end | ||
|
||
describe "saving" do | ||
it "POST with no ID set" do | ||
client = Nylas::HttpClient.new( | ||
app_id: "not-real", | ||
app_secret: "also-not-real", | ||
access_token: "seriously-unreal" | ||
) | ||
api = Nylas::API.new(client: client) | ||
data = { | ||
account_id: "account-123", | ||
name: "test-component", | ||
type: "agenda", | ||
action: 0, | ||
active: true, | ||
settings: { foo: "bar" }, | ||
allowed_domains: ["www.nylas.com"], | ||
public_account_id: "account-123", | ||
public_token_id: "token-123", | ||
public_application_id: "application-123", | ||
created_at: "2021-08-24T15:05:48.000Z", | ||
updated_at: "2021-08-24T15:05:48.000Z" | ||
} | ||
component = described_class.from_json(JSON.dump(data), api: api) | ||
allow(api).to receive(:execute).and_return({}) | ||
|
||
component.save | ||
|
||
expect(api).to have_received(:execute).with( | ||
method: :post, | ||
path: "/component/not-real", | ||
payload: JSON.dump( | ||
account_id: "account-123", | ||
name: "test-component", | ||
type: "agenda", | ||
action: 0, | ||
active: true, | ||
settings: { foo: "bar" }, | ||
public_account_id: "account-123", | ||
public_token_id: "token-123", | ||
allowed_domains: ["www.nylas.com"] | ||
), | ||
query: {} | ||
) | ||
end | ||
|
||
it "PUT with ID set" do | ||
client = Nylas::HttpClient.new( | ||
app_id: "not-real", | ||
app_secret: "also-not-real", | ||
access_token: "seriously-unreal" | ||
) | ||
api = Nylas::API.new(client: client) | ||
data = { | ||
id: "abc-123", | ||
account_id: "account-123", | ||
name: "test-component", | ||
type: "agenda", | ||
action: 0, | ||
active: true, | ||
settings: { foo: "bar" }, | ||
allowed_domains: ["www.nylas.com"], | ||
public_account_id: "account-123", | ||
public_token_id: "token-123", | ||
public_application_id: "application-123", | ||
created_at: "2021-08-24T15:05:48.000Z", | ||
updated_at: "2021-08-24T15:05:48.000Z" | ||
} | ||
scheduler = described_class.from_json(JSON.dump(data), api: api) | ||
allow(api).to receive(:execute).and_return({}) | ||
|
||
scheduler.save | ||
|
||
expect(api).to have_received(:execute).with( | ||
method: :put, | ||
path: "/component/not-real/abc-123", | ||
payload: JSON.dump( | ||
account_id: "account-123", | ||
name: "test-component", | ||
type: "agenda", | ||
action: 0, | ||
active: true, | ||
settings: { foo: "bar" }, | ||
public_account_id: "account-123", | ||
public_token_id: "token-123", | ||
allowed_domains: ["www.nylas.com"] | ||
), | ||
query: {} | ||
) | ||
end | ||
end | ||
end |