accessgrid 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3978f3315ab2ae70fbc1739375fdca9b99e9940848d484d6f3c4c4384881bf2f
4
+ data.tar.gz: af94d249034b73242e95036f12465cabb4527f12f49e93b94d22638476ef487b
5
+ SHA512:
6
+ metadata.gz: c6e0a303e6dc0cd163d33aea38273f6daed151f80b2e8fe9aab36c362b1e09e5adb59ada4e82a55831667d8bab3b7596b29cd1413cfc1305528784479fbd51a8
7
+ data.tar.gz: 4bd691713c59e1ce6018eed73eab9f1556be85d4d56616603bcd2732b94460fdc87a36e669cb0f114cb8fda25532f0911cfc8b562ca2561931c52d8e60643f59
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AccessGrid
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # AccessGrid SDK
2
+
3
+ A Ruby SDK for interacting with the [AccessGrid.com](https://www.accessgrid.com) API. This SDK provides a simple interface for managing NFC key cards and enterprise templates. Full docs at https://www.accessgrid.com/docs
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'accessgrid'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install accessgrid
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```ruby
28
+ require 'accessgrid'
29
+
30
+ account_id = ENV['ACCOUNT_ID']
31
+ secret_key = ENV['SECRET_KEY']
32
+
33
+ client = AccessGrid.new(account_id, secret_key)
34
+ ```
35
+
36
+ ## API Reference
37
+
38
+ ### Access Cards
39
+
40
+ #### Provision a new card
41
+
42
+ ```ruby
43
+ card = client.access_cards.provision(
44
+ card_template_id: "0xd3adb00b5",
45
+ employee_id: "123456789",
46
+ tag_id: "DDEADB33FB00B5",
47
+ allow_on_multiple_devices: true,
48
+ full_name: "Employee name",
49
+ email: "employee@yourwebsite.com",
50
+ phone_number: "+19547212241",
51
+ classification: "full_time",
52
+ start_date: "2025-01-31T22:46:25.601Z",
53
+ expiration_date: "2025-04-30T22:46:25.601Z",
54
+ employee_photo: "[image_in_base64_encoded_format]"
55
+ )
56
+
57
+ puts "Install URL: #{card.url}"
58
+ ```
59
+
60
+ #### Update a card
61
+
62
+ ```ruby
63
+ card = client.access_cards.update(
64
+ card_id: "0xc4rd1d",
65
+ employee_id: "987654321",
66
+ full_name: "Updated Employee Name",
67
+ classification: "contractor",
68
+ expiration_date: "2025-02-22T21:04:03.664Z",
69
+ employee_photo: "[image_in_base64_encoded_format]"
70
+ )
71
+ ```
72
+
73
+ #### Manage card states
74
+
75
+ ```ruby
76
+ # Suspend a card
77
+ client.access_cards.suspend(
78
+ card_id: "0xc4rd1d"
79
+ )
80
+
81
+ # Resume a card
82
+ client.access_cards.resume(
83
+ card_id: "0xc4rd1d"
84
+ )
85
+
86
+ # Unlink a card
87
+ client.access_cards.unlink(
88
+ card_id: "0xc4rd1d"
89
+ )
90
+ ```
91
+
92
+ ### Enterprise Console
93
+
94
+ #### Create a template
95
+
96
+ ```ruby
97
+ template = client.console.create_template(
98
+ name: "Employee NFC key",
99
+ platform: "apple",
100
+ use_case: "employee_badge",
101
+ protocol: "desfire",
102
+ allow_on_multiple_devices: true,
103
+ watch_count: 2,
104
+ iphone_count: 3,
105
+ design: {
106
+ background_color: "#FFFFFF",
107
+ label_color: "#000000",
108
+ label_secondary_color: "#333333",
109
+ background_image: "[image_in_base64_encoded_format]",
110
+ logo_image: "[image_in_base64_encoded_format]",
111
+ icon_image: "[image_in_base64_encoded_format]"
112
+ },
113
+ support_info: {
114
+ support_url: "https://help.yourcompany.com",
115
+ support_phone_number: "+1-555-123-4567",
116
+ support_email: "support@yourcompany.com",
117
+ privacy_policy_url: "https://yourcompany.com/privacy",
118
+ terms_and_conditions_url: "https://yourcompany.com/terms"
119
+ }
120
+ )
121
+ ```
122
+
123
+ #### Update a template
124
+
125
+ ```ruby
126
+ template = client.console.update_template(
127
+ card_template_id: "0xd3adb00b5",
128
+ name: "Updated Employee NFC key",
129
+ allow_on_multiple_devices: true,
130
+ watch_count: 2,
131
+ iphone_count: 3,
132
+ support_info: {
133
+ support_url: "https://help.yourcompany.com",
134
+ support_phone_number: "+1-555-123-4567",
135
+ support_email: "support@yourcompany.com",
136
+ privacy_policy_url: "https://yourcompany.com/privacy",
137
+ terms_and_conditions_url: "https://yourcompany.com/terms"
138
+ }
139
+ )
140
+ ```
141
+
142
+ #### Read a template
143
+
144
+ ```ruby
145
+ template = client.console.read_template(
146
+ card_template_id: "0xd3adb00b5"
147
+ )
148
+ ```
149
+
150
+ #### Get event logs
151
+
152
+ ```ruby
153
+ events = client.console.event_log(
154
+ card_template_id: "0xd3adb00b5",
155
+ filters: {
156
+ device: "mobile", # "mobile" or "watch"
157
+ start_date: (Time.now - 30*24*60*60).iso8601,
158
+ end_date: Time.now.iso8601,
159
+ event_type: "install"
160
+ }
161
+ )
162
+ ```
163
+
164
+ ## Configuration
165
+
166
+ The SDK can be configured with a custom API endpoint:
167
+
168
+ ```ruby
169
+ client = AccessGrid.new(
170
+ account_id,
171
+ secret_key,
172
+ 'https://api.staging.accessgrid.com' # Use a different API endpoint
173
+ )
174
+ ```
175
+
176
+ ## Error Handling
177
+
178
+ The SDK throws specific errors for various scenarios:
179
+ - `AccessGrid::AuthenticationError` - Invalid credentials
180
+ - `AccessGrid::ResourceNotFoundError` - Requested resource not found
181
+ - `AccessGrid::ValidationError` - Invalid parameters
182
+ - `AccessGrid::Error` - Generic API errors
183
+
184
+ Example error handling:
185
+
186
+ ```ruby
187
+ begin
188
+ card = client.access_cards.provision(
189
+ # ... parameters
190
+ )
191
+ rescue AccessGrid::ValidationError => e
192
+ puts "Invalid parameters: #{e.message}"
193
+ rescue AccessGrid::Error => e
194
+ puts "API error: #{e.message}"
195
+ end
196
+ ```
197
+
198
+ ## Requirements
199
+
200
+ - Ruby 2.6 or higher
201
+
202
+ ## Security
203
+
204
+ The SDK automatically handles:
205
+ - Request signing using HMAC-SHA256
206
+ - Secure payload encoding
207
+ - Authentication headers
208
+ - HTTPS communication
209
+
210
+ Never expose your `secret_key` in client-side code. Always use environment variables or a secure configuration management system.
211
+
212
+ ## Development
213
+
214
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
215
+
216
+ ## Contributing
217
+
218
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/accessgrid-ruby.
219
+
220
+ ## License
221
+
222
+ The gem is available as open source under the terms of the MIT License.
@@ -0,0 +1,52 @@
1
+ # lib/accessgrid/access_cards.rb
2
+ module AccessGrid
3
+ class AccessCards
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def provision(params)
9
+ response = @client.make_request(:post, '/api/v1/nfc_keys/issue', params)
10
+ Card.new(response)
11
+ end
12
+
13
+ def update(params)
14
+ card_id = params.delete(:card_id)
15
+ response = @client.make_request(:put, "/api/v1/nfc_keys/#{card_id}", params)
16
+ Card.new(response)
17
+ end
18
+
19
+ private def manage_state(card_id, action)
20
+ response = @client.make_request(
21
+ :post,
22
+ "/api/v1/nfc_keys/#{card_id}/manage",
23
+ { manage_action: action }
24
+ )
25
+ Card.new(response)
26
+ end
27
+
28
+ def suspend(params)
29
+ manage_state(params[:card_id], 'suspend')
30
+ end
31
+
32
+ def resume(params)
33
+ manage_state(params[:card_id], 'resume')
34
+ end
35
+
36
+ def unlink(params)
37
+ manage_state(params[:card_id], 'unlink')
38
+ end
39
+ end
40
+
41
+ class Card
42
+ attr_reader :id, :state, :url, :full_name, :expiration_date
43
+
44
+ def initialize(data)
45
+ @id = data['id']
46
+ @state = data['state']
47
+ @url = data['install_url']
48
+ @full_name = data['full_name']
49
+ @expiration_date = data['expiration_date']
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,80 @@
1
+ # lib/accessgrid/console.rb
2
+ module AccessGrid
3
+ class Console
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def create_template(params)
9
+ transformed_params = transform_template_params(params)
10
+ response = @client.make_request(:post, '/api/v1/enterprise/templates', transformed_params)
11
+ Template.new(response)
12
+ end
13
+
14
+ def update_template(params)
15
+ card_template_id = params.delete(:card_template_id)
16
+ transformed_params = transform_template_params(params)
17
+ response = @client.make_request(:put, "/api/v1/enterprise/templates/#{card_template_id}", transformed_params)
18
+ Template.new(response)
19
+ end
20
+
21
+ def read_template(params)
22
+ response = @client.make_request(:get, "/api/v1/enterprise/templates/#{params[:card_template_id]}")
23
+ Template.new(response)
24
+ end
25
+
26
+ def event_log(params)
27
+ card_template_id = params.delete(:card_template_id)
28
+ response = @client.make_request(:get, "/api/v1/enterprise/templates/#{card_template_id}/logs", params)
29
+ response['logs'].map { |log| Event.new(log) }
30
+ end
31
+
32
+ private
33
+
34
+ def transform_template_params(params)
35
+ design = params.delete(:design) || {}
36
+ support_info = params.delete(:support_info) || {}
37
+
38
+ params.merge(
39
+ background_color: design[:background_color],
40
+ label_color: design[:label_color],
41
+ label_secondary_color: design[:label_secondary_color],
42
+ support_url: support_info[:support_url],
43
+ support_phone_number: support_info[:support_phone_number],
44
+ support_email: support_info[:support_email],
45
+ privacy_policy_url: support_info[:privacy_policy_url],
46
+ terms_and_conditions_url: support_info[:terms_and_conditions_url]
47
+ )
48
+ end
49
+ end
50
+
51
+ class Template
52
+ attr_reader :id, :name, :platform, :protocol, :allow_on_multiple_devices,
53
+ :watch_count, :iphone_count, :support_info, :style_settings
54
+
55
+ def initialize(data)
56
+ @id = data['id']
57
+ @name = data['name']
58
+ @platform = data['platform']
59
+ @protocol = data['protocol']
60
+ @allow_on_multiple_devices = data['allowed_device_counts']['allow_on_multiple_devices']
61
+ @watch_count = data['allowed_device_counts']['watch']
62
+ @iphone_count = data['allowed_device_counts']['iphone']
63
+ @support_info = data['support_settings']
64
+ @style_settings = data['style_settings']
65
+ end
66
+ end
67
+
68
+ class Event
69
+ attr_reader :type, :timestamp, :user_id, :ip_address, :user_agent, :metadata
70
+
71
+ def initialize(data)
72
+ @type = data['event']
73
+ @timestamp = data['created_at']
74
+ @user_id = data['metadata']['user_id']
75
+ @ip_address = data['ip_address']
76
+ @user_agent = data['user_agent']
77
+ @metadata = data['metadata']
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,4 @@
1
+ # lib/accessgrid/version.rb
2
+ module AccessGrid
3
+ VERSION = '0.1.0'
4
+ end
data/lib/accessgrid.rb ADDED
@@ -0,0 +1,103 @@
1
+ # lib/accessgrid.rb
2
+ require 'base64'
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'openssl'
6
+ require 'uri'
7
+
8
+ require_relative 'accessgrid/version'
9
+ require_relative 'accessgrid/access_cards'
10
+ require_relative 'accessgrid/console'
11
+
12
+ module AccessGrid
13
+ class Error < StandardError; end
14
+ class AuthenticationError < Error; end
15
+ class ResourceNotFoundError < Error; end
16
+ class ValidationError < Error; end
17
+
18
+ class Client
19
+ attr_reader :account_id, :api_secret, :api_host
20
+
21
+ def initialize(account_id, api_secret, api_host = 'https://api.accessgrid.com')
22
+ @account_id = account_id
23
+ @api_secret = api_secret
24
+ @api_host = api_host
25
+ end
26
+
27
+ def access_cards
28
+ @access_cards ||= AccessCards.new(self)
29
+ end
30
+
31
+ def console
32
+ @console ||= Console.new(self)
33
+ end
34
+
35
+ def make_request(method, path, body = nil)
36
+ uri = URI.parse("#{api_host}#{path}")
37
+ http = Net::HTTP.new(uri.host, uri.port)
38
+ http.use_ssl = uri.scheme == 'https'
39
+
40
+ # Create request object based on method
41
+ request = case method
42
+ when :get
43
+ Net::HTTP::Get.new(uri.request_uri)
44
+ when :post
45
+ Net::HTTP::Post.new(uri.request_uri)
46
+ when :put
47
+ Net::HTTP::Put.new(uri.request_uri)
48
+ else
49
+ raise ArgumentError, "Unsupported HTTP method: #{method}"
50
+ end
51
+
52
+ # Set headers
53
+ request['Content-Type'] = 'application/json'
54
+ request['X-ACCT-ID'] = account_id
55
+
56
+ # Generate signature if body present
57
+ if body
58
+ json_body = body.to_json
59
+ request['X-PAYLOAD-SIG'] = generate_signature(json_body)
60
+ request.body = json_body
61
+ end
62
+
63
+ # Make request
64
+ response = http.request(request)
65
+
66
+ # Parse response
67
+ handle_response(response)
68
+ end
69
+
70
+ private
71
+
72
+ def generate_signature(payload)
73
+ # Base64 encode the payload
74
+ encoded_payload = Base64.strict_encode64(payload)
75
+
76
+ # Generate SHA256 hash
77
+ OpenSSL::HMAC.hexdigest(
78
+ OpenSSL::Digest.new('sha256'),
79
+ api_secret,
80
+ encoded_payload
81
+ )
82
+ end
83
+
84
+ def handle_response(response)
85
+ case response.code.to_i
86
+ when 200, 201, 202
87
+ JSON.parse(response.body)
88
+ when 401
89
+ raise AuthenticationError, 'Invalid credentials'
90
+ when 404
91
+ raise ResourceNotFoundError, 'Resource not found'
92
+ when 422
93
+ raise ValidationError, JSON.parse(response.body)['message']
94
+ else
95
+ raise Error, "API request failed with status #{response.code}: #{response.body}"
96
+ end
97
+ end
98
+ end
99
+
100
+ def self.new(account_id, api_secret, api_host = 'https://api.accessgrid.com')
101
+ Client.new(account_id, api_secret, api_host)
102
+ end
103
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: accessgrid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Auston Bunsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: A Ruby client for the AccessGrid API
70
+ email:
71
+ - ab@accessgrid.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE
77
+ - README.md
78
+ - lib/accessgrid.rb
79
+ - lib/accessgrid/access_cards.rb
80
+ - lib/accessgrid/console.rb
81
+ - lib/accessgrid/version.rb
82
+ homepage: https://github.com/access-grid/accessgrid-rb
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.6.0
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.4.19
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: AccessGrid API Client
105
+ test_files: []