Skip to content

Commit

Permalink
Support created_at and updated_at attributes (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
blairlunceford authored Aug 13, 2021
1 parent 41dd500 commit 90461a3
Show file tree
Hide file tree
Showing 26 changed files with 399 additions and 217 deletions.
10 changes: 9 additions & 1 deletion lib/workos/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class Connection
extend T::Sig

attr_accessor :id, :name, :connection_type, :domains, :organization_id,
:state, :status
:state, :status, :created_at, :updated_at

# rubocop:disable Metrics/AbcSize
sig { params(json: String).void }
def initialize(json)
raw = parse_json(json)
Expand All @@ -23,7 +24,10 @@ def initialize(json)
@organization_id = T.let(raw.organization_id, String)
@state = T.let(raw.state, String)
@status = T.let(raw.status, String)
@created_at = T.let(raw.created_at, String)
@updated_at = T.let(raw.updated_at, String)
end
# rubocop:enable Metrics/AbcSize

def to_json(*)
{
Expand All @@ -34,6 +38,8 @@ def to_json(*)
organization_id: organization_id,
state: state,
status: status,
created_at: created_at,
updated_at: updated_at,
}
end

Expand All @@ -51,6 +57,8 @@ def parse_json(json_string)
organization_id: hash[:organization_id],
state: hash[:state],
status: hash[:status],
created_at: hash[:created_at],
updated_at: hash[:updated_at],
)
end
end
Expand Down
10 changes: 9 additions & 1 deletion lib/workos/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ module WorkOS
class Directory
extend T::Sig

attr_accessor :id, :domain, :name, :type, :state, :organization_id
attr_accessor :id, :domain, :name, :type, :state, :organization_id, :created_at, :updated_at

# rubocop:disable Metrics/AbcSize
sig { params(json: String).void }
def initialize(json)
raw = parse_json(json)
Expand All @@ -20,7 +21,10 @@ def initialize(json)
@type = T.let(raw.type, String)
@state = T.let(raw.state, String)
@organization_id = T.let(raw.organization_id, String)
@created_at = T.let(raw.created_at, String)
@updated_at = T.let(raw.updated_at, String)
end
# rubocop:enable Metrics/AbcSize

def to_json(*)
{
Expand All @@ -30,6 +34,8 @@ def to_json(*)
type: type,
state: state,
organization_id: organization_id,
created_at: created_at,
updated_at: updated_at,
}
end

Expand All @@ -50,6 +56,8 @@ def parse_json(json_string)
type: hash[:type],
state: hash[:state],
organization_id: hash[:organization_id],
created_at: hash[:created_at],
updated_at: hash[:updated_at],
)
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/workos/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module WorkOS
class Organization
extend T::Sig

attr_accessor :id, :domains, :name
attr_accessor :id, :domains, :name, :created_at, :updated_at

sig { params(json: String).void }
def initialize(json)
Expand All @@ -17,13 +17,17 @@ def initialize(json)
@id = T.let(raw.id, String)
@name = T.let(raw.name, String)
@domains = T.let(raw.domains, Array)
@created_at = T.let(raw.created_at, String)
@updated_at = T.let(raw.updated_at, String)
end

def to_json(*)
{
id: id,
name: name,
domains: domains,
created_at: created_at,
updated_at: updated_at,
}
end

Expand All @@ -41,6 +45,8 @@ def parse_json(json_string)
id: hash[:id],
name: hash[:name],
domains: hash[:domains],
created_at: hash[:created_at],
updated_at: hash[:updated_at],
)
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/workos/types/connection_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ConnectionStruct < T::Struct
const :organization_id, String
const :state, String
const :status, String
const :created_at, String
const :updated_at, String
end
end
end
2 changes: 2 additions & 0 deletions lib/workos/types/directory_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class DirectoryStruct < T::Struct
const :type, String
const :state, String
const :organization_id, String
const :created_at, String
const :updated_at, String
end
end
end
2 changes: 2 additions & 0 deletions lib/workos/types/organization_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class OrganizationStruct < T::Struct
const :id, String
const :name, String
const :domains, T::Array[T.untyped]
const :created_at, String
const :updated_at, String
end
end
end
22 changes: 11 additions & 11 deletions spec/lib/workos/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
it 'creates an organization' do
VCR.use_cassette 'organization/create' do
organization = described_class.create_organization(
domains: ['example.com'],
domains: ['example.io'],
name: 'Test Organization',
)

expect(organization.id).to eq('org_01EHT88Z8J8795GZNQ4ZP1J81T')
expect(organization.id).to eq('org_01FCPEJXEZR4DSBA625YMGQT9N')
expect(organization.name).to eq('Test Organization')
expect(organization.domains.first[:domain]).to eq('example.com')
expect(organization.domains.first[:domain]).to eq('example.io')
end
end
end
Expand Down Expand Up @@ -46,7 +46,7 @@
VCR.use_cassette 'organization/list' do
organizations = described_class.list_organizations

expect(organizations.data.size).to eq(7)
expect(organizations.data.size).to eq(6)
expect(organizations.list_metadata).to eq(expected_metadata)
end
end
Expand All @@ -69,7 +69,7 @@
before: 'before-id',
)

expect(organizations.data.size).to eq(7)
expect(organizations.data.size).to eq(6)
end
end
end
Expand All @@ -89,7 +89,7 @@
VCR.use_cassette 'organization/list', match_requests_on: [:path] do
organizations = described_class.list_organizations(after: 'after-id')

expect(organizations.data.size).to eq(7)
expect(organizations.data.size).to eq(6)
end
end
end
Expand All @@ -109,7 +109,7 @@
VCR.use_cassette 'organization/list', match_requests_on: [:path] do
organizations = described_class.list_organizations(limit: 10)

expect(organizations.data.size).to eq(7)
expect(organizations.data.size).to eq(6)
end
end
end
Expand All @@ -120,10 +120,10 @@
it 'gets the organization details' do
VCR.use_cassette('organization/get') do
organization = described_class.get_organization(
id: 'org_01EZDF20TZEJXKPSX2BJRN6TV6',
id: 'org_01F9293WD2PDEEV4Y625XPZVG7',
)

expect(organization.id).to eq('org_01EZDF20TZEJXKPSX2BJRN6TV6')
expect(organization.id).to eq('org_01F9293WD2PDEEV4Y625XPZVG7')
expect(organization.name).to eq('Foo Corp')
expect(organization.domains.first[:domain]).to eq('foo-corp.com')
end
Expand All @@ -149,12 +149,12 @@
it 'creates an organization' do
VCR.use_cassette 'organization/update' do
organization = described_class.update_organization(
organization: 'org_01F29YJ068E52HGEB8ZQGC9MJG',
organization: 'org_01F6Q6TFP7RD2PF6J03ANNWDKV',
domains: ['example.me'],
name: 'Test Organization',
)

expect(organization.id).to eq('org_01F29YJ068E52HGEB8ZQGC9MJG')
expect(organization.id).to eq('org_01F6Q6TFP7RD2PF6J03ANNWDKV')
expect(organization.name).to eq('Test Organization')
expect(organization.domains.first[:domain]).to eq('example.me')
end
Expand Down
24 changes: 12 additions & 12 deletions spec/lib/workos/sso_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
VCR.use_cassette 'sso/list_connections/with_no_options' do
connections = described_class.list_connections

expect(connections.data.size).to eq(3)
expect(connections.data.size).to eq(6)
expect(connections.list_metadata).to eq(expected_metadata)
end
end
Expand All @@ -326,7 +326,7 @@
connection_type: 'OktaSAML',
)

expect(connections.data.size).to eq(3)
expect(connections.data.size).to eq(10)
expect(connections.data.first.connection_type).to eq('OktaSAML')
end
end
Expand Down Expand Up @@ -357,7 +357,7 @@
context 'with organization_id option' do
it 'forms the proper request to the API' do
request_args = [
'/connections?organization_id=org_01EGS4P7QR31EZ4YWD1Z1XA176',
'/connections?organization_id=org_01F9293WD2PDEEV4Y625XPZVG7',
'Content-Type' => 'application/json'
]

Expand All @@ -368,12 +368,12 @@

VCR.use_cassette 'sso/list_connections/with_organization_id' do
connections = described_class.list_connections(
organization_id: 'org_01EGS4P7QR31EZ4YWD1Z1XA176',
organization_id: 'org_01F9293WD2PDEEV4Y625XPZVG7',
)

expect(connections.data.size).to eq(1)
expect(connections.data.first.organization_id).to eq(
'org_01EGS4P7QR31EZ4YWD1Z1XA176',
'org_01F9293WD2PDEEV4Y625XPZVG7',
)
end
end
Expand Down Expand Up @@ -404,7 +404,7 @@
context 'with before option' do
it 'forms the proper request to the API' do
request_args = [
'/connections?before=conn_01EQKPMQAPV02H270HKVNS4CTA',
'/connections?before=conn_01FA3WGCWPCCY1V2FGES2FDNP7',
'Content-Type' => 'application/json'
]

Expand All @@ -415,7 +415,7 @@

VCR.use_cassette 'sso/list_connections/with_before' do
connections = described_class.list_connections(
before: 'conn_01EQKPMQAPV02H270HKVNS4CTA',
before: 'conn_01FA3WGCWPCCY1V2FGES2FDNP7',
)

expect(connections.data.size).to eq(3)
Expand All @@ -426,7 +426,7 @@
context 'with after option' do
it 'forms the proper request to the API' do
request_args = [
'/connections?after=conn_01EQKPMQAPV02H270HKVNS4CTA',
'/connections?after=conn_01FA3WGCWPCCY1V2FGES2FDNP7',
'Content-Type' => 'application/json'
]

Expand All @@ -437,10 +437,10 @@

VCR.use_cassette 'sso/list_connections/with_after' do
connections = described_class.list_connections(
after: 'conn_01EQKPMQAPV02H270HKVNS4CTA',
after: 'conn_01FA3WGCWPCCY1V2FGES2FDNP7',
)

expect(connections.data.size).to eq(3)
expect(connections.data.size).to eq(2)
end
end
end
Expand All @@ -451,10 +451,10 @@
it 'gets the connection details' do
VCR.use_cassette('sso/get_connection_with_valid_id') do
connection = WorkOS::SSO.get_connection(
id: 'conn_01EX00NB050H354WKGC7990AR2',
id: 'conn_01FA3WGCWPCCY1V2FGES2FDNP7',
)

expect(connection.id).to eq('conn_01EX00NB050H354WKGC7990AR2')
expect(connection.id).to eq('conn_01FA3WGCWPCCY1V2FGES2FDNP7')
expect(connection.connection_type).to eq('OktaSAML')
expect(connection.name).to eq('Foo Corp')
expect(connection.domains.first[:domain]).to eq('foo-corp.com')
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 90461a3

Please sign in to comment.