Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,45 @@ end
client.console.webhooks.delete('abc123')
```

### HID Organizations

#### Create an HID org

```ruby
org = client.console.hid.orgs.create(
name: 'My Org',
full_address: '1 Main St, NY NY',
phone: '+1-555-0000',
first_name: 'Ada',
last_name: 'Lovelace'
)

puts "Created org: #{org.name} (ID: #{org.id})"
puts "Slug: #{org.slug}"
```

#### List HID orgs

```ruby
orgs = client.console.hid.orgs.list

orgs.each do |org|
puts "Org ID: #{org.id}, Name: #{org.name}, Slug: #{org.slug}"
end
```

#### Activate an HID org

```ruby
result = client.console.hid.orgs.activate(
email: 'admin@example.com',
password: 'hid-password-123'
)

puts "Completed registration for org: #{result.name}"
puts "Status: #{result.status}"
```

## Configuration

The SDK can be configured with a custom API endpoint:
Expand Down Expand Up @@ -363,9 +402,9 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/access
| GET /v1/console/webhooks | `console.webhooks.list()` | Y |
| POST /v1/console/webhooks | `console.webhooks.create()` | Y |
| DELETE /v1/console/webhooks/{id} | `console.webhooks.delete()` | Y |
| POST /v1/console/hid/orgs | `console.hid.orgs.create()` | - |
| POST /v1/console/hid/orgs/activate | `console.hid.orgs.activate()` | - |
| GET /v1/console/hid/orgs | `console.hid.orgs.list()` | - |
| POST /v1/console/hid/orgs | `console.hid.orgs.create()` | Y |
| POST /v1/console/hid/orgs/activate | `console.hid.orgs.activate()` | Y |
| GET /v1/console/hid/orgs | `console.hid.orgs.list()` | Y |

## License

Expand Down
59 changes: 58 additions & 1 deletion lib/accessgrid/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
module AccessGrid
# Manages enterprise template and logging operations.
class Console
attr_reader :webhooks
attr_reader :webhooks, :hid

def initialize(client)
@client = client
@webhooks = Webhooks.new(client)
@hid = HID.new(client)
end

def create_template(params)
Expand Down Expand Up @@ -248,4 +249,60 @@ def initialize(data)
@cert_expires_at = data['cert_expires_at']
end
end

# Provides access to HID-related services.
class HID
attr_reader :orgs

def initialize(client)
@orgs = HIDOrgs.new(client)
end
end

# Manages HID organization operations.
class HIDOrgs
def initialize(client)
@client = client
end

def create(name:, full_address:, phone:, first_name:, last_name:)
data = {
name: name,
full_address: full_address,
phone: phone,
first_name: first_name,
last_name: last_name
}
response = @client.make_request(:post, '/v1/console/hid/orgs', data)
HidOrg.new(response)
end

def list
response = @client.make_request(:get, '/v1/console/hid/orgs')
response.map { |org| HidOrg.new(org) }
end

def activate(email:, password:)
data = { email: email, password: password }
response = @client.make_request(:post, '/v1/console/hid/orgs/activate', data)
HidOrg.new(response)
end
end

# Represents an HID organization.
class HidOrg
attr_reader :id, :name, :slug, :first_name, :last_name, :phone, :full_address, :status, :created_at

def initialize(data)
@id = data['id']
@name = data['name']
@slug = data['slug']
@first_name = data['first_name']
@last_name = data['last_name']
@phone = data['phone']
@full_address = data['full_address']
@status = data['status']
@created_at = data['created_at']
end
end
end
101 changes: 101 additions & 0 deletions spec/console_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -744,4 +744,105 @@
end
end
end

describe 'HID orgs' do
let(:org_response) do
{
id: 'org_123',
name: 'My Org',
slug: 'my-org',
first_name: 'Ada',
last_name: 'Lovelace',
phone: '+1-555-0000',
full_address: '1 Main St, NY NY',
status: 'pending',
created_at: '2025-01-01T00:00:00Z'
}
end

describe '#hid.orgs.create' do
it 'creates a new HID org' do
request_body = {
name: 'My Org',
full_address: '1 Main St, NY NY',
phone: '+1-555-0000',
first_name: 'Ada',
last_name: 'Lovelace'
}

stub_api_request(:post, '/v1/console/hid/orgs', body: org_response, request_body: request_body)

org = console.hid.orgs.create(
name: 'My Org',
full_address: '1 Main St, NY NY',
phone: '+1-555-0000',
first_name: 'Ada',
last_name: 'Lovelace'
)

expect(org).to be_a(AccessGrid::HidOrg)
expect(org.id).to eq('org_123')
expect(org.name).to eq('My Org')
expect(org.slug).to eq('my-org')
expect(org.first_name).to eq('Ada')
expect(org.last_name).to eq('Lovelace')
expect(org.phone).to eq('+1-555-0000')
expect(org.full_address).to eq('1 Main St, NY NY')
expect(org.status).to eq('pending')
expect(org.created_at).to eq('2025-01-01T00:00:00Z')
end
end

describe '#hid.orgs.list' do
it 'returns a list of HID orgs' do
list_response = [org_response, org_response.merge(id: 'org_456', name: 'Other Org', slug: 'other-org')]

stub_api_request(
:get,
'/v1/console/hid/orgs',
body: list_response,
query: generate_sig_payload(id: :orgs)
)

orgs = console.hid.orgs.list

expect(orgs).to be_an(Array)
expect(orgs.length).to eq(2)
expect(orgs.first).to be_a(AccessGrid::HidOrg)
expect(orgs.first.id).to eq('org_123')
expect(orgs.last.id).to eq('org_456')
end

it 'returns empty array when no orgs' do
stub_api_request(
:get,
'/v1/console/hid/orgs',
body: [],
query: generate_sig_payload(id: :orgs)
)

orgs = console.hid.orgs.list

expect(orgs).to eq([])
end
end

describe '#hid.orgs.activate' do
it 'activates an HID org with credentials' do
activated_response = org_response.merge(status: 'active')
request_body = { email: 'admin@example.com', password: 'hid-password-123' }

stub_api_request(:post, '/v1/console/hid/orgs/activate', body: activated_response, request_body: request_body)

org = console.hid.orgs.activate(
email: 'admin@example.com',
password: 'hid-password-123'
)

expect(org).to be_a(AccessGrid::HidOrg)
expect(org.status).to eq('active')
expect(org.name).to eq('My Org')
end
end
end
end