Skip to content

Commit 8d264e2

Browse files
committed
v1 client
0 parents  commit 8d264e2

File tree

710 files changed

+104763
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

710 files changed

+104763
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Gem files
2+
*.gem
3+
.bundle/
4+
vendor/bundle
5+
6+
# IDE
7+
.idea/
8+
.vscode/
9+
*.swp
10+
*.swo
11+
*~
12+
13+
# OS
14+
.DS_Store
15+
16+
# RSpec
17+
.rspec_status

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec

Gemfile.lock

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PATH
2+
remote: .
3+
specs:
4+
fastcomments-ruby (0.0.1)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
diff-lcs (1.6.2)
10+
rake (13.3.1)
11+
rspec (3.13.2)
12+
rspec-core (~> 3.13.0)
13+
rspec-expectations (~> 3.13.0)
14+
rspec-mocks (~> 3.13.0)
15+
rspec-core (3.13.6)
16+
rspec-support (~> 3.13.0)
17+
rspec-expectations (3.13.5)
18+
diff-lcs (>= 1.2.0, < 2.0)
19+
rspec-support (~> 3.13.0)
20+
rspec-mocks (3.13.7)
21+
diff-lcs (>= 1.2.0, < 2.0)
22+
rspec-support (~> 3.13.0)
23+
rspec-support (3.13.6)
24+
25+
PLATFORMS
26+
x86_64-linux-gnu
27+
28+
DEPENDENCIES
29+
fastcomments-ruby!
30+
rake (~> 13.0)
31+
rspec (~> 3.12)
32+
33+
BUNDLED WITH
34+
2.4.20

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 FastComments
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.

README.md

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# fastcomments-ruby
2+
The FastComments Ruby SDK. You can use this to build secure and scalable backend applications that interact with FastComments, or build reactive client applications.
3+
4+
## Installation
5+
6+
Add this line to your application's Gemfile:
7+
8+
```ruby
9+
gem 'fastcomments-ruby'
10+
```
11+
12+
And then execute:
13+
14+
```bash
15+
bundle install
16+
```
17+
18+
Or install it yourself as:
19+
20+
```bash
21+
gem install fastcomments-ruby
22+
```
23+
24+
### Library Contents
25+
26+
This library contains the generated API client and the SSO utilities to make working with the API easier.
27+
28+
- [API Client Library Docs](./client/README.md)
29+
30+
### Public vs Secured APIs
31+
32+
For the API client, there are two classes, `DefaultAPI` and `PublicAPI`. The `DefaultAPI` contains methods that require your API key, and `PublicAPI` contains api calls
33+
that can be made directly from a browser/mobile device/etc without authentication.
34+
35+
## Quick Start
36+
37+
### Using Authenticated APIs (DefaultAPI)
38+
39+
**Important:** You must set your API key on the ApiClient before making authenticated requests. If you don't, requests will fail with a 401 error.
40+
41+
```ruby
42+
require 'fastcomments-client'
43+
44+
# Create and configure the API client
45+
config = FastCommentsClient::Configuration.new
46+
api_client = FastCommentsClient::ApiClient.new(config)
47+
48+
# REQUIRED: Set your API key (get this from your FastComments dashboard)
49+
config.api_key['ApiKeyAuth'] = 'YOUR_API_KEY_HERE'
50+
51+
# Create the API instance with the configured client
52+
api = FastCommentsClient::DefaultAPI.new(api_client)
53+
54+
# Now you can make authenticated API calls
55+
begin
56+
# Example: Add an SSO user
57+
user_data = {
58+
id: 'user-123',
59+
60+
displayName: 'John Doe'
61+
}
62+
63+
response = api.add_sso_user('YOUR_TENANT_ID', user_data)
64+
puts "User created: #{response}"
65+
66+
rescue FastCommentsClient::ApiError => e
67+
puts "Error: #{e.response_body}"
68+
# Common errors:
69+
# - 401: API key is missing or invalid
70+
# - 400: Request validation failed
71+
end
72+
```
73+
74+
### Using Public APIs (PublicAPI)
75+
76+
Public endpoints don't require authentication:
77+
78+
```ruby
79+
require 'fastcomments-client'
80+
81+
public_api = FastCommentsClient::PublicAPI.new
82+
83+
begin
84+
response = public_api.get_comments_public(
85+
tenant_id: 'YOUR_TENANT_ID',
86+
url_id: 'page-url-id'
87+
)
88+
puts response
89+
rescue FastCommentsClient::ApiError => e
90+
puts e.message
91+
end
92+
```
93+
94+
### Common Issues
95+
96+
1. **401 "missing-api-key" error**: Make sure you set `config.api_key['ApiKeyAuth'] = 'YOUR_KEY'` before creating the DefaultAPI instance.
97+
2. **Wrong API class**: Use `DefaultAPI` for server-side authenticated requests, `PublicAPI` for client-side/public requests.
98+
3. **Null API key**: The SDK will silently skip authentication if the API key is null, leading to 401 errors.
99+
100+
## Notes
101+
102+
### Broadcast Ids
103+
104+
You'll see you're supposed to pass a `broadcastId` in some API calls. When you receive events, you'll get this ID back, so you know to ignore the event if you plan to optimistically apply changes on the client
105+
(which you'll probably want to do since it offers the best experience). Pass a UUID here. The ID should be unique enough to not occur twice in a browser session.
106+
107+
### SSO (Single Sign-On)
108+
109+
For SSO examples, see below.
110+
111+
## SSO Usage
112+
113+
### Simple SSO
114+
115+
```ruby
116+
require 'fastcomments'
117+
require 'fastcomments-client'
118+
119+
# Create Simple SSO token
120+
user = FastComments::SSO::SimpleSSOUserData.new(
121+
user_id: 'user-123',
122+
123+
avatar: 'https://example.com/avatar.jpg'
124+
)
125+
126+
sso = FastComments::SSO::FastCommentsSSO.new_simple(user)
127+
token = sso.create_token
128+
129+
puts "SSO Token: #{token}"
130+
131+
# Use the SSO token to make an authenticated API call
132+
config = FastCommentsClient::Configuration.new
133+
api_client = FastCommentsClient::ApiClient.new(config)
134+
public_api = FastCommentsClient::PublicAPI.new(api_client)
135+
136+
response = public_api.get_comments_public(
137+
tenant_id: 'your-tenant-id',
138+
url_id: 'your-page-url-id',
139+
sso: token
140+
)
141+
142+
puts "Status: #{response}"
143+
```
144+
145+
### Secure SSO
146+
147+
```ruby
148+
require 'fastcomments'
149+
require 'fastcomments-client'
150+
151+
# Create Secure SSO token
152+
user = FastComments::SSO::SecureSSOUserData.new(
153+
user_id: 'user-123',
154+
155+
username: 'johndoe',
156+
avatar: 'https://example.com/avatar.jpg'
157+
)
158+
159+
api_key = 'your-api-key'
160+
sso = FastComments::SSO::FastCommentsSSO.new_secure(api_key, user)
161+
token = sso.create_token
162+
163+
puts "Secure SSO Token: #{token}"
164+
165+
# Use the SSO token to make an authenticated API call
166+
config = FastCommentsClient::Configuration.new
167+
api_client = FastCommentsClient::ApiClient.new(config)
168+
public_api = FastCommentsClient::PublicAPI.new(api_client)
169+
170+
response = public_api.get_comments_public(
171+
tenant_id: 'your-tenant-id',
172+
url_id: 'your-page-url-id',
173+
sso: token
174+
)
175+
176+
puts "Status: #{response}"
177+
```
178+
179+
## Testing
180+
181+
Set the required environment variables:
182+
183+
```bash
184+
export FASTCOMMENTS_API_KEY="your-api-key"
185+
export FASTCOMMENTS_TENANT_ID="your-tenant-id"
186+
```
187+
188+
Run the tests:
189+
190+
```bash
191+
bundle exec rspec
192+
```
193+
194+
## Development
195+
196+
To update the generated client from the OpenAPI spec:
197+
198+
```bash
199+
./update.sh
200+
```
201+
202+
This will download the latest OpenAPI spec from a running FastComments server (or use a local copy) and regenerate the client code.
203+
204+
## License
205+
206+
MIT License - see LICENSE file for details
207+
208+
## Support
209+
210+
For support, please visit https://fastcomments.com/auth/my-account/help or email [email protected]

Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "bundler/gem_tasks"
2+
require "rspec/core/rake_task"
3+
4+
RSpec::Core::RakeTask.new(:spec)
5+
6+
task default: :spec

client/.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Generated by: https://openapi-generator.tech
2+
#
3+
4+
*.gem
5+
*.rbc
6+
/.config
7+
/coverage/
8+
/InstalledFiles
9+
/pkg/
10+
/spec/reports/
11+
/spec/examples.txt
12+
/test/tmp/
13+
/test/version_tmp/
14+
/tmp/
15+
16+
## Specific to RubyMotion:
17+
.dat*
18+
.repl_history
19+
build/
20+
21+
## Documentation cache and generated files:
22+
/.yardoc/
23+
/_yardoc/
24+
/doc/
25+
/rdoc/
26+
27+
## Environment normalization:
28+
/.bundle/
29+
/vendor/bundle
30+
/lib/bundler/man/
31+
32+
# for a library or gem, you might want to ignore these files since the code is
33+
# intended to run in multiple environments; otherwise, check them in:
34+
# Gemfile.lock
35+
# .ruby-version
36+
# .ruby-gemset
37+
38+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
39+
.rvmrc

client/.gitlab-ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.ruby: &ruby
2+
variables:
3+
LANG: "C.UTF-8"
4+
before_script:
5+
- ruby -v
6+
- bundle config set --local deployment true
7+
- bundle install -j $(nproc)
8+
parallel:
9+
matrix:
10+
- RUBY_VERSION: ['2.7', '3.0', '3.1']
11+
image: "ruby:$RUBY_VERSION"
12+
cache:
13+
paths:
14+
- vendor/ruby
15+
key: 'ruby-$RUBY_VERSION'
16+
17+
gem:
18+
extends: .ruby
19+
script:
20+
- bundle exec rspec
21+
- bundle exec rake build
22+
- bundle exec rake install
23+
artifacts:
24+
paths:
25+
- pkg/*.gem
26+

client/.openapi-generator-ignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md

0 commit comments

Comments
 (0)