vortex-ruby-sdk 1.0.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 +7 -0
- data/LICENSE +21 -0
- data/PUBLISHING.md +474 -0
- data/README.md +204 -0
- data/Rakefile +40 -0
- data/examples/basic_usage.rb +72 -0
- data/examples/rails_app.rb +129 -0
- data/examples/sinatra_app.rb +119 -0
- data/lib/vortex/client.rb +229 -0
- data/lib/vortex/error.rb +19 -0
- data/lib/vortex/rails.rb +257 -0
- data/lib/vortex/sinatra.rb +276 -0
- data/lib/vortex/version.rb +5 -0
- data/lib/vortex.rb +55 -0
- data/vortex-ruby-sdk.gemspec +47 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 18819ec338fa097c24046e0a535a98483acbe55e0163fe6e6db86d0160334a1b
|
4
|
+
data.tar.gz: 1cdbc41d41372b4658ef5a38db7ee6cbda22f5c63227738bd8ac79140215af43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 950cf7e0435224d9e7aa534d94b3999ed72f823b2211eb368a332de4fe683f8c0998bbde59a445571b5b7fb81cc5de60036944c7944a124f4933ea0aae41a698
|
7
|
+
data.tar.gz: 561c091c7232a282cbe854dacdc3d2e3eaac70fb28a7b6c08dee852d4b7466d56f2fe4c07e7834cfe1e23c2802786c5019d6cf514f720ac3341fa5827085fa92
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 TeamVortexSoftware
|
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/PUBLISHING.md
ADDED
@@ -0,0 +1,474 @@
|
|
1
|
+
# Publishing the Vortex Ruby SDK to RubyGems
|
2
|
+
|
3
|
+
This guide walks you through publishing the Vortex Ruby SDK to RubyGems so users can install it with `gem install vortex-ruby-sdk`.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
RubyGems.org is the primary package repository for Ruby. Publishing is straightforward and requires:
|
8
|
+
- A RubyGems account
|
9
|
+
- A properly configured `.gemspec` file
|
10
|
+
- The `gem` command-line tool
|
11
|
+
|
12
|
+
## Prerequisites
|
13
|
+
|
14
|
+
### 1. RubyGems Account
|
15
|
+
|
16
|
+
1. Create an account at [RubyGems.org](https://rubygems.org/sign_up)
|
17
|
+
2. Verify your email address
|
18
|
+
|
19
|
+
### 2. Configure RubyGems Credentials
|
20
|
+
|
21
|
+
```bash
|
22
|
+
# The first time you push a gem, you'll be prompted for credentials
|
23
|
+
# Or configure manually:
|
24
|
+
gem signin
|
25
|
+
```
|
26
|
+
|
27
|
+
This creates `~/.gem/credentials` with your API key.
|
28
|
+
|
29
|
+
### 3. Verify Ruby and Bundler
|
30
|
+
|
31
|
+
```bash
|
32
|
+
ruby --version # Should be >= 3.0.0
|
33
|
+
bundler --version
|
34
|
+
gem --version
|
35
|
+
```
|
36
|
+
|
37
|
+
## Publishing Process
|
38
|
+
|
39
|
+
### Step 1: Verify Gemspec Configuration
|
40
|
+
|
41
|
+
The `.gemspec` file has been configured with:
|
42
|
+
- ✅ Name, version, authors, email
|
43
|
+
- ✅ Summary and description
|
44
|
+
- ✅ Homepage and source URLs
|
45
|
+
- ✅ License (MIT)
|
46
|
+
- ✅ Ruby version requirement (>= 3.0.0)
|
47
|
+
- ✅ Dependencies
|
48
|
+
- ✅ Metadata for RubyGems.org
|
49
|
+
|
50
|
+
Current gemspec: [vortex-ruby-sdk.gemspec](vortex-ruby-sdk.gemspec)
|
51
|
+
|
52
|
+
### Step 2: Update Version
|
53
|
+
|
54
|
+
Edit [lib/vortex/version.rb](lib/vortex/version.rb:4):
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
module Vortex
|
58
|
+
VERSION = '1.0.0'
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
### Step 3: Update CHANGELOG
|
63
|
+
|
64
|
+
Create or update `CHANGELOG.md` with release notes:
|
65
|
+
|
66
|
+
```markdown
|
67
|
+
## [1.0.0] - 2025-01-15
|
68
|
+
|
69
|
+
### Added
|
70
|
+
- Initial release
|
71
|
+
- JWT generation
|
72
|
+
- Invitation management
|
73
|
+
- Group operations
|
74
|
+
```
|
75
|
+
|
76
|
+
### Step 4: Install Dependencies and Test
|
77
|
+
|
78
|
+
```bash
|
79
|
+
cd packages/vortex-ruby-sdk
|
80
|
+
|
81
|
+
# Install dependencies
|
82
|
+
bundle install
|
83
|
+
|
84
|
+
# Run tests
|
85
|
+
bundle exec rspec
|
86
|
+
|
87
|
+
# Run RuboCop for code quality
|
88
|
+
bundle exec rubocop
|
89
|
+
|
90
|
+
# Generate documentation
|
91
|
+
bundle exec yard doc
|
92
|
+
```
|
93
|
+
|
94
|
+
### Step 5: Build the Gem
|
95
|
+
|
96
|
+
```bash
|
97
|
+
# Build the gem
|
98
|
+
gem build vortex-ruby-sdk.gemspec
|
99
|
+
```
|
100
|
+
|
101
|
+
This creates a `.gem` file:
|
102
|
+
```
|
103
|
+
vortex-ruby-sdk-1.0.0.gem
|
104
|
+
```
|
105
|
+
|
106
|
+
### Step 6: Test the Gem Locally
|
107
|
+
|
108
|
+
```bash
|
109
|
+
# Install locally to test
|
110
|
+
gem install ./vortex-ruby-sdk-1.0.0.gem
|
111
|
+
|
112
|
+
# Test in IRB
|
113
|
+
irb
|
114
|
+
> require 'vortex'
|
115
|
+
> client = Vortex::Client.new('test-key')
|
116
|
+
> # Test basic functionality
|
117
|
+
```
|
118
|
+
|
119
|
+
### Step 7: Publish to RubyGems
|
120
|
+
|
121
|
+
```bash
|
122
|
+
# Push to RubyGems.org
|
123
|
+
gem push vortex-ruby-sdk-1.0.0.gem
|
124
|
+
```
|
125
|
+
|
126
|
+
You'll be prompted for credentials if not already signed in.
|
127
|
+
|
128
|
+
### Step 8: Verify Publication
|
129
|
+
|
130
|
+
After publishing:
|
131
|
+
|
132
|
+
1. Check [RubyGems.org](https://rubygems.org/gems/vortex-ruby-sdk)
|
133
|
+
2. Test installation:
|
134
|
+
```bash
|
135
|
+
gem install vortex-ruby-sdk
|
136
|
+
```
|
137
|
+
|
138
|
+
## Installation for Users
|
139
|
+
|
140
|
+
Once published, users can install with:
|
141
|
+
|
142
|
+
```bash
|
143
|
+
gem install vortex-ruby-sdk
|
144
|
+
```
|
145
|
+
|
146
|
+
Or in a Gemfile:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
gem 'vortex-ruby-sdk', '~> 1.0'
|
150
|
+
```
|
151
|
+
|
152
|
+
Then:
|
153
|
+
|
154
|
+
```bash
|
155
|
+
bundle install
|
156
|
+
```
|
157
|
+
|
158
|
+
## Automated Publishing with GitHub Actions
|
159
|
+
|
160
|
+
Create `.github/workflows/publish-ruby.yml`:
|
161
|
+
|
162
|
+
```yaml
|
163
|
+
name: Publish Ruby Gem
|
164
|
+
|
165
|
+
on:
|
166
|
+
release:
|
167
|
+
types: [published]
|
168
|
+
workflow_dispatch:
|
169
|
+
|
170
|
+
jobs:
|
171
|
+
publish:
|
172
|
+
runs-on: ubuntu-latest
|
173
|
+
|
174
|
+
steps:
|
175
|
+
- uses: actions/checkout@v4
|
176
|
+
|
177
|
+
- name: Set up Ruby
|
178
|
+
uses: ruby/setup-ruby@v1
|
179
|
+
with:
|
180
|
+
ruby-version: '3.0'
|
181
|
+
bundler-cache: true
|
182
|
+
|
183
|
+
- name: Install dependencies
|
184
|
+
run: |
|
185
|
+
cd packages/vortex-ruby-sdk
|
186
|
+
bundle install
|
187
|
+
|
188
|
+
- name: Run tests
|
189
|
+
run: |
|
190
|
+
cd packages/vortex-ruby-sdk
|
191
|
+
bundle exec rspec
|
192
|
+
|
193
|
+
- name: Run RuboCop
|
194
|
+
run: |
|
195
|
+
cd packages/vortex-ruby-sdk
|
196
|
+
bundle exec rubocop
|
197
|
+
|
198
|
+
- name: Build gem
|
199
|
+
run: |
|
200
|
+
cd packages/vortex-ruby-sdk
|
201
|
+
gem build vortex-ruby-sdk.gemspec
|
202
|
+
|
203
|
+
- name: Publish to RubyGems
|
204
|
+
env:
|
205
|
+
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
206
|
+
run: |
|
207
|
+
cd packages/vortex-ruby-sdk
|
208
|
+
gem push *.gem
|
209
|
+
```
|
210
|
+
|
211
|
+
### GitHub Secrets Setup
|
212
|
+
|
213
|
+
Add this secret to your repository:
|
214
|
+
- `RUBYGEMS_API_KEY` - Your RubyGems API key
|
215
|
+
|
216
|
+
To get your API key:
|
217
|
+
1. Go to [RubyGems.org Profile](https://rubygems.org/profile/edit)
|
218
|
+
2. Click "API Keys"
|
219
|
+
3. Create a new key with "Push rubygems" scope
|
220
|
+
|
221
|
+
## Version Management
|
222
|
+
|
223
|
+
Follow [Semantic Versioning](https://semver.org/):
|
224
|
+
|
225
|
+
- **MAJOR** (1.0.0 → 2.0.0): Breaking API changes
|
226
|
+
- **MINOR** (1.0.0 → 1.1.0): New features, backward compatible
|
227
|
+
- **PATCH** (1.0.0 → 1.0.1): Bug fixes, backward compatible
|
228
|
+
|
229
|
+
### Pre-release Versions
|
230
|
+
|
231
|
+
For beta or RC releases:
|
232
|
+
|
233
|
+
```ruby
|
234
|
+
VERSION = '1.0.0.beta1'
|
235
|
+
VERSION = '1.0.0.rc1'
|
236
|
+
```
|
237
|
+
|
238
|
+
Users install with:
|
239
|
+
```bash
|
240
|
+
gem install vortex-ruby-sdk --pre
|
241
|
+
```
|
242
|
+
|
243
|
+
## Gemspec Best Practices
|
244
|
+
|
245
|
+
### Required Fields
|
246
|
+
|
247
|
+
- ✅ `name` - Gem name (must be unique on RubyGems.org)
|
248
|
+
- ✅ `version` - Current version
|
249
|
+
- ✅ `authors` - Author names
|
250
|
+
- ✅ `email` - Contact email
|
251
|
+
- ✅ `summary` - Short description
|
252
|
+
- ✅ `description` - Longer description
|
253
|
+
- ✅ `homepage` - Project homepage
|
254
|
+
- ✅ `license` - License identifier
|
255
|
+
- ✅ `files` - Files to include in gem
|
256
|
+
|
257
|
+
### Metadata
|
258
|
+
|
259
|
+
The gemspec includes metadata for better discoverability:
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
spec.metadata = {
|
263
|
+
'homepage_uri' => spec.homepage,
|
264
|
+
'source_code_uri' => spec.homepage,
|
265
|
+
'changelog_uri' => "#{spec.homepage}/blob/main/CHANGELOG.md",
|
266
|
+
'bug_tracker_uri' => "#{spec.homepage}/issues",
|
267
|
+
'documentation_uri' => "https://www.rubydoc.info/gems/vortex-ruby-sdk"
|
268
|
+
}
|
269
|
+
```
|
270
|
+
|
271
|
+
### Dependencies
|
272
|
+
|
273
|
+
Runtime dependencies:
|
274
|
+
```ruby
|
275
|
+
spec.add_dependency 'faraday', '~> 2.0'
|
276
|
+
spec.add_dependency 'rack', '>= 2.0'
|
277
|
+
```
|
278
|
+
|
279
|
+
Development dependencies:
|
280
|
+
```ruby
|
281
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
282
|
+
spec.add_development_dependency 'rubocop', '~> 1.0'
|
283
|
+
```
|
284
|
+
|
285
|
+
## Managing Gem Ownership
|
286
|
+
|
287
|
+
### Add Collaborators
|
288
|
+
|
289
|
+
```bash
|
290
|
+
gem owner vortex-ruby-sdk --add email@example.com
|
291
|
+
```
|
292
|
+
|
293
|
+
### Remove Collaborators
|
294
|
+
|
295
|
+
```bash
|
296
|
+
gem owner vortex-ruby-sdk --remove email@example.com
|
297
|
+
```
|
298
|
+
|
299
|
+
## Yanking a Release
|
300
|
+
|
301
|
+
If you need to remove a published version:
|
302
|
+
|
303
|
+
```bash
|
304
|
+
gem yank vortex-ruby-sdk -v 1.0.0
|
305
|
+
```
|
306
|
+
|
307
|
+
**Note**: Yanking doesn't delete the gem, it just prevents new installations. Existing users can still use it.
|
308
|
+
|
309
|
+
## Documentation
|
310
|
+
|
311
|
+
### YARD Documentation
|
312
|
+
|
313
|
+
The SDK uses YARD for documentation:
|
314
|
+
|
315
|
+
```bash
|
316
|
+
# Generate docs
|
317
|
+
bundle exec yard doc
|
318
|
+
|
319
|
+
# Serve locally
|
320
|
+
bundle exec yard server
|
321
|
+
```
|
322
|
+
|
323
|
+
Published gems automatically get documentation at [RubyDoc.info](https://www.rubydoc.info/).
|
324
|
+
|
325
|
+
### README
|
326
|
+
|
327
|
+
Ensure [README.md](README.md) includes:
|
328
|
+
- Installation instructions
|
329
|
+
- Quick start guide
|
330
|
+
- API examples
|
331
|
+
- Configuration options
|
332
|
+
- License information
|
333
|
+
|
334
|
+
## Testing Before Release
|
335
|
+
|
336
|
+
### Local Testing Workflow
|
337
|
+
|
338
|
+
```bash
|
339
|
+
# 1. Build gem
|
340
|
+
gem build vortex-ruby-sdk.gemspec
|
341
|
+
|
342
|
+
# 2. Install locally
|
343
|
+
gem install ./vortex-ruby-sdk-1.0.0.gem --local
|
344
|
+
|
345
|
+
# 3. Test in a new directory
|
346
|
+
mkdir /tmp/test-vortex
|
347
|
+
cd /tmp/test-vortex
|
348
|
+
|
349
|
+
# 4. Create test script
|
350
|
+
cat > test.rb << 'EOF'
|
351
|
+
require 'vortex'
|
352
|
+
client = Vortex::Client.new('test-key')
|
353
|
+
puts "SDK loaded successfully!"
|
354
|
+
EOF
|
355
|
+
|
356
|
+
# 5. Run test
|
357
|
+
ruby test.rb
|
358
|
+
|
359
|
+
# 6. Uninstall
|
360
|
+
gem uninstall vortex-ruby-sdk
|
361
|
+
```
|
362
|
+
|
363
|
+
## Troubleshooting
|
364
|
+
|
365
|
+
### Common Issues
|
366
|
+
|
367
|
+
#### 1. Name Already Taken
|
368
|
+
|
369
|
+
If the gem name is taken, you'll need to choose a different name. Check availability:
|
370
|
+
|
371
|
+
```bash
|
372
|
+
gem search ^vortex-ruby-sdk$ --remote
|
373
|
+
```
|
374
|
+
|
375
|
+
#### 2. Authentication Errors
|
376
|
+
|
377
|
+
```bash
|
378
|
+
# Re-authenticate
|
379
|
+
gem signin
|
380
|
+
|
381
|
+
# Or set credentials manually
|
382
|
+
mkdir -p ~/.gem
|
383
|
+
echo "---
|
384
|
+
:rubygems_api_key: YOUR_API_KEY" > ~/.gem/credentials
|
385
|
+
chmod 0600 ~/.gem/credentials
|
386
|
+
```
|
387
|
+
|
388
|
+
#### 3. Version Conflicts
|
389
|
+
|
390
|
+
You cannot push the same version twice. Increment the version and rebuild:
|
391
|
+
|
392
|
+
```ruby
|
393
|
+
# lib/vortex/version.rb
|
394
|
+
VERSION = '1.0.1'
|
395
|
+
```
|
396
|
+
|
397
|
+
#### 4. Missing Files
|
398
|
+
|
399
|
+
If files are missing from the gem:
|
400
|
+
|
401
|
+
```bash
|
402
|
+
# List files in built gem
|
403
|
+
gem unpack vortex-ruby-sdk-1.0.0.gem
|
404
|
+
ls -la vortex-ruby-sdk-1.0.0/
|
405
|
+
```
|
406
|
+
|
407
|
+
Adjust the `files` specification in the gemspec.
|
408
|
+
|
409
|
+
## Release Checklist
|
410
|
+
|
411
|
+
- [ ] Update version in `lib/vortex/version.rb`
|
412
|
+
- [ ] Update `CHANGELOG.md` with release notes
|
413
|
+
- [ ] Update `README.md` if needed
|
414
|
+
- [ ] Run all tests: `bundle exec rspec`
|
415
|
+
- [ ] Run RuboCop: `bundle exec rubocop`
|
416
|
+
- [ ] Generate and review docs: `bundle exec yard doc`
|
417
|
+
- [ ] Build gem: `gem build vortex-ruby-sdk.gemspec`
|
418
|
+
- [ ] Test locally: `gem install ./vortex-ruby-sdk-X.Y.Z.gem`
|
419
|
+
- [ ] Commit version bump: `git commit -am "Bump version to X.Y.Z"`
|
420
|
+
- [ ] Create Git tag: `git tag vX.Y.Z`
|
421
|
+
- [ ] Push changes: `git push && git push --tags`
|
422
|
+
- [ ] Publish gem: `gem push vortex-ruby-sdk-X.Y.Z.gem`
|
423
|
+
- [ ] Verify on RubyGems.org
|
424
|
+
- [ ] Create GitHub release with changelog
|
425
|
+
- [ ] Announce release
|
426
|
+
|
427
|
+
## Security Best Practices
|
428
|
+
|
429
|
+
1. **Protect API keys**: Never commit `~/.gem/credentials` to Git
|
430
|
+
2. **Use GitHub Secrets**: For automated publishing
|
431
|
+
3. **Scope API keys**: Use minimal permissions
|
432
|
+
4. **MFA**: Enable on RubyGems.org account
|
433
|
+
5. **Code signing**: Consider signing gems with GPG
|
434
|
+
|
435
|
+
## Post-Publication
|
436
|
+
|
437
|
+
After publishing:
|
438
|
+
|
439
|
+
1. **Monitor downloads**: Check stats on RubyGems.org
|
440
|
+
2. **Watch for issues**: Monitor GitHub issues
|
441
|
+
3. **Update documentation**: Ensure all docs reference correct version
|
442
|
+
4. **Announce**: Share release on relevant channels
|
443
|
+
5. **Monitor dependencies**: Keep dependencies updated
|
444
|
+
|
445
|
+
## Resources
|
446
|
+
|
447
|
+
- [RubyGems.org Guides](https://guides.rubygems.org/)
|
448
|
+
- [Publishing Your Gem](https://guides.rubygems.org/publishing/)
|
449
|
+
- [Patterns and Best Practices](https://guides.rubygems.org/patterns/)
|
450
|
+
- [Gem Specification Reference](https://guides.rubygems.org/specification-reference/)
|
451
|
+
- [Semantic Versioning](https://semver.org/)
|
452
|
+
- [YARD Documentation](https://yardoc.org/)
|
453
|
+
- [RuboCop](https://rubocop.org/)
|
454
|
+
|
455
|
+
## Alternative: Using gem-release
|
456
|
+
|
457
|
+
For automated versioning and releasing:
|
458
|
+
|
459
|
+
```bash
|
460
|
+
gem install gem-release
|
461
|
+
|
462
|
+
# Bump version and publish in one command
|
463
|
+
gem bump --version minor --push --release
|
464
|
+
```
|
465
|
+
|
466
|
+
## Support
|
467
|
+
|
468
|
+
For publishing issues:
|
469
|
+
- [RubyGems Help](https://guides.rubygems.org/rubygems-org-api/)
|
470
|
+
- [RubyGems Support](https://help.rubygems.org/)
|
471
|
+
|
472
|
+
For SDK issues:
|
473
|
+
- Create an issue on GitHub
|
474
|
+
- Contact support@vortexsoftware.com
|
data/README.md
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
# Vortex Ruby SDK
|
2
|
+
|
3
|
+
A Ruby SDK for the Vortex invitation system, providing seamless integration with the same functionality and API compatibility as other Vortex SDKs (Node.js, Python, Java, Go).
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **JWT Generation**: Identical algorithm to other SDKs for complete compatibility
|
8
|
+
- **Complete API Coverage**: All invitation management operations
|
9
|
+
- **Framework Integration**: Built-in Rails and Sinatra helpers
|
10
|
+
- **Same Route Structure**: Ensures React provider compatibility
|
11
|
+
- **Comprehensive Testing**: Full test coverage with RSpec
|
12
|
+
- **Type Safety**: Clear method signatures and documentation
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'vortex-ruby-sdk'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
```bash
|
31
|
+
gem install vortex-ruby-sdk
|
32
|
+
```
|
33
|
+
|
34
|
+
## Basic Usage
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'vortex'
|
38
|
+
|
39
|
+
# Initialize the client
|
40
|
+
client = Vortex::Client.new(ENV['VORTEX_API_KEY'])
|
41
|
+
|
42
|
+
# Generate JWT for a user
|
43
|
+
jwt = client.generate_jwt(
|
44
|
+
user_id: 'user123',
|
45
|
+
identifiers: [{ type: 'email', value: 'user@example.com' }],
|
46
|
+
groups: [{ id: 'team1', type: 'team', name: 'Engineering' }],
|
47
|
+
role: 'admin'
|
48
|
+
)
|
49
|
+
|
50
|
+
# Get invitations by target
|
51
|
+
invitations = client.get_invitations_by_target('email', 'user@example.com')
|
52
|
+
|
53
|
+
# Accept invitations
|
54
|
+
client.accept_invitations(['inv1', 'inv2'], { type: 'email', value: 'user@example.com' })
|
55
|
+
|
56
|
+
# Get invitations by group
|
57
|
+
group_invitations = client.get_invitations_by_group('team', 'team1')
|
58
|
+
```
|
59
|
+
|
60
|
+
## Rails Integration
|
61
|
+
|
62
|
+
Create a controller with Vortex routes:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# app/controllers/vortex_controller.rb
|
66
|
+
class VortexController < ApplicationController
|
67
|
+
include Vortex::Rails::Controller
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def authenticate_vortex_user
|
72
|
+
# Return user data hash or nil
|
73
|
+
{
|
74
|
+
user_id: current_user.id,
|
75
|
+
identifiers: [{ type: 'email', value: current_user.email }],
|
76
|
+
groups: current_user.teams.map { |team|
|
77
|
+
{ id: team.id, type: 'team', name: team.name }
|
78
|
+
},
|
79
|
+
role: current_user.role
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def authorize_vortex_operation(operation, user)
|
84
|
+
# Implement your authorization logic
|
85
|
+
case operation
|
86
|
+
when 'JWT', 'GET_INVITATIONS'
|
87
|
+
true
|
88
|
+
when 'REVOKE_INVITATION'
|
89
|
+
user[:role] == 'admin'
|
90
|
+
else
|
91
|
+
false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def vortex_client
|
96
|
+
@vortex_client ||= Vortex::Client.new(Rails.application.credentials.vortex_api_key)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
Add routes to `config/routes.rb`:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
Rails.application.routes.draw do
|
105
|
+
scope '/api/vortex', controller: 'vortex' do
|
106
|
+
post 'jwt', action: 'generate_jwt'
|
107
|
+
get 'invitations', action: 'get_invitations_by_target'
|
108
|
+
get 'invitations/:invitation_id', action: 'get_invitation'
|
109
|
+
delete 'invitations/:invitation_id', action: 'revoke_invitation'
|
110
|
+
post 'invitations/accept', action: 'accept_invitations'
|
111
|
+
get 'invitations/by-group/:group_type/:group_id', action: 'get_invitations_by_group'
|
112
|
+
delete 'invitations/by-group/:group_type/:group_id', action: 'delete_invitations_by_group'
|
113
|
+
post 'invitations/:invitation_id/reinvite', action: 'reinvite'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
## Sinatra Integration
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
require 'sinatra/base'
|
122
|
+
require 'vortex/sinatra'
|
123
|
+
|
124
|
+
class MyApp < Sinatra::Base
|
125
|
+
register Vortex::Sinatra
|
126
|
+
|
127
|
+
configure do
|
128
|
+
set :vortex_api_key, ENV['VORTEX_API_KEY']
|
129
|
+
end
|
130
|
+
|
131
|
+
def authenticate_vortex_user
|
132
|
+
# Implement authentication logic
|
133
|
+
user_id = request.env['HTTP_X_USER_ID']
|
134
|
+
return nil unless user_id
|
135
|
+
|
136
|
+
{
|
137
|
+
user_id: user_id,
|
138
|
+
identifiers: [{ type: 'email', value: 'user@example.com' }],
|
139
|
+
groups: [{ id: 'team1', type: 'team', name: 'Engineering' }],
|
140
|
+
role: 'user'
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
def authorize_vortex_operation(operation, user)
|
145
|
+
# Implement authorization logic
|
146
|
+
user != nil
|
147
|
+
end
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
## API Methods
|
152
|
+
|
153
|
+
All methods match the functionality of other Vortex SDKs:
|
154
|
+
|
155
|
+
### JWT Generation
|
156
|
+
- `generate_jwt(user_id:, identifiers:, groups:, role: nil)` - Generate JWT token
|
157
|
+
|
158
|
+
### Invitation Management
|
159
|
+
- `get_invitations_by_target(target_type, target_value)` - Get invitations by target
|
160
|
+
- `get_invitation(invitation_id)` - Get specific invitation
|
161
|
+
- `revoke_invitation(invitation_id)` - Revoke invitation
|
162
|
+
- `accept_invitations(invitation_ids, target)` - Accept invitations
|
163
|
+
- `get_invitations_by_group(group_type, group_id)` - Get group invitations
|
164
|
+
- `delete_invitations_by_group(group_type, group_id)` - Delete group invitations
|
165
|
+
- `reinvite(invitation_id)` - Reinvite user
|
166
|
+
|
167
|
+
## Route Structure
|
168
|
+
|
169
|
+
The SDK provides these routes (same as other SDKs for React provider compatibility):
|
170
|
+
|
171
|
+
- `POST /api/vortex/jwt`
|
172
|
+
- `GET /api/vortex/invitations?targetType=email&targetValue=user@example.com`
|
173
|
+
- `GET /api/vortex/invitations/:id`
|
174
|
+
- `DELETE /api/vortex/invitations/:id`
|
175
|
+
- `POST /api/vortex/invitations/accept`
|
176
|
+
- `GET /api/vortex/invitations/by-group/:type/:id`
|
177
|
+
- `DELETE /api/vortex/invitations/by-group/:type/:id`
|
178
|
+
- `POST /api/vortex/invitations/:id/reinvite`
|
179
|
+
|
180
|
+
## Error Handling
|
181
|
+
|
182
|
+
All methods raise `Vortex::VortexError` on failures:
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
begin
|
186
|
+
jwt = client.generate_jwt(user_data)
|
187
|
+
rescue Vortex::VortexError => e
|
188
|
+
logger.error "Vortex error: #{e.message}"
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
## Development
|
193
|
+
|
194
|
+
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.
|
195
|
+
|
196
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
197
|
+
|
198
|
+
## Contributing
|
199
|
+
|
200
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vortexsoftware/vortex-ruby-sdk.
|
201
|
+
|
202
|
+
## License
|
203
|
+
|
204
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|