Skip to content

Commit bf8f8a4

Browse files
committed
Fixing class/method casing and how api key is passed
1 parent 6746beb commit bf8f8a4

File tree

2 files changed

+51
-38
lines changed

2 files changed

+51
-38
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ This library contains the generated API client and the SSO utilities to make wor
2929

3030
### Public vs Secured APIs
3131

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
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
3333
that can be made directly from a browser/mobile device/etc without authentication.
3434

3535
## Quick Start
3636

37-
### Using Authenticated APIs (DefaultAPI)
37+
### Using Authenticated APIs (DefaultApi)
3838

3939
**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.
4040

@@ -46,10 +46,10 @@ config = FastCommentsClient::Configuration.new
4646
api_client = FastCommentsClient::ApiClient.new(config)
4747

4848
# REQUIRED: Set your API key (get this from your FastComments dashboard)
49-
config.api_key['ApiKeyAuth'] = 'YOUR_API_KEY_HERE'
49+
config.api_key['x-api-key'] = 'YOUR_API_KEY_HERE'
5050

5151
# Create the API instance with the configured client
52-
api = FastCommentsClient::DefaultAPI.new(api_client)
52+
api = FastCommentsClient::DefaultApi.new(api_client)
5353

5454
# Now you can make authenticated API calls
5555
begin
@@ -71,14 +71,14 @@ rescue FastCommentsClient::ApiError => e
7171
end
7272
```
7373

74-
### Using Public APIs (PublicAPI)
74+
### Using Public APIs (PublicApi)
7575

7676
Public endpoints don't require authentication:
7777

7878
```ruby
7979
require 'fastcomments-client'
8080

81-
public_api = FastCommentsClient::PublicAPI.new
81+
public_api = FastCommentsClient::PublicApi.new
8282

8383
begin
8484
response = public_api.get_comments_public(
@@ -93,8 +93,8 @@ end
9393

9494
### Common Issues
9595

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.
96+
1. **401 "missing-api-key" error**: Make sure you set `config.api_key['x-api-key'] = '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.
9898
3. **Null API key**: The SDK will silently skip authentication if the API key is null, leading to 401 errors.
9999

100100
## Notes
@@ -131,7 +131,7 @@ puts "SSO Token: #{token}"
131131
# Use the SSO token to make an authenticated API call
132132
config = FastCommentsClient::Configuration.new
133133
api_client = FastCommentsClient::ApiClient.new(config)
134-
public_api = FastCommentsClient::PublicAPI.new(api_client)
134+
public_api = FastCommentsClient::PublicApi.new(api_client)
135135

136136
response = public_api.get_comments_public(
137137
tenant_id: 'your-tenant-id',
@@ -165,7 +165,7 @@ puts "Secure SSO Token: #{token}"
165165
# Use the SSO token to make an authenticated API call
166166
config = FastCommentsClient::Configuration.new
167167
api_client = FastCommentsClient::ApiClient.new(config)
168-
public_api = FastCommentsClient::PublicAPI.new(api_client)
168+
public_api = FastCommentsClient::PublicApi.new(api_client)
169169

170170
response = public_api.get_comments_public(
171171
tenant_id: 'your-tenant-id',

spec/sso_integration_spec.rb

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ def get_tenant_id
2626
end
2727

2828
let(:public_api) do
29-
FastCommentsClient::PublicAPI.new(api_client)
29+
FastCommentsClient::PublicApi.new(api_client)
3030
end
3131

3232
let(:default_api) do
3333
config = FastCommentsClient::Configuration.new
34-
config.api_key['ApiKeyAuth'] = API_KEY
34+
config.api_key['x-api-key'] = API_KEY
3535
client = FastCommentsClient::ApiClient.new(config)
36-
FastCommentsClient::DefaultAPI.new(client)
36+
FastCommentsClient::DefaultApi.new(client)
3737
end
3838

3939
let(:mock_secure_user) do
@@ -61,9 +61,9 @@ def get_tenant_id
6161
sso_token = sso.create_token
6262

6363
response = public_api.get_comments_public(
64-
tenant_id: TENANT_ID,
65-
url_id: 'sdk-test-page-secure',
66-
sso: sso_token
64+
TENANT_ID,
65+
'sdk-test-page-secure',
66+
{ sso: sso_token }
6767
)
6868

6969
expect(response).not_to be_nil
@@ -83,21 +83,34 @@ def get_tenant_id
8383
}
8484

8585
response = public_api.create_comment_public(
86-
tenant_id: TENANT_ID,
87-
url_id: 'sdk-test-page-secure-comment',
88-
broadcast_id: "test-#{timestamp}",
89-
comment_data: comment_data,
90-
sso: sso_token
86+
TENANT_ID,
87+
'sdk-test-page-secure-comment',
88+
"test-#{timestamp}",
89+
comment_data,
90+
{ sso: sso_token }
9191
)
9292

9393
expect(response).not_to be_nil
9494
end
9595

9696
it 'gets comments with DefaultApi' do
97+
# First create the SSO user
98+
user_data = FastCommentsClient::CreateAPISSOUserData.new({
99+
id: mock_secure_user.user_id,
100+
email: mock_secure_user.email,
101+
username: mock_secure_user.username,
102+
avatar_src: mock_secure_user.avatar
103+
})
104+
105+
default_api.add_sso_user(TENANT_ID, user_data)
106+
107+
# Then get comments with that user's context
97108
response = default_api.get_comments(
98-
tenant_id: TENANT_ID,
99-
url_id: 'sdk-test-page-secure-admin',
100-
context_user_id: mock_secure_user.user_id
109+
TENANT_ID,
110+
{
111+
url_id: 'sdk-test-page-secure-admin',
112+
context_user_id: mock_secure_user.user_id
113+
}
101114
)
102115

103116
expect(response).not_to be_nil
@@ -110,9 +123,9 @@ def get_tenant_id
110123
sso_token = sso.create_token
111124

112125
response = public_api.get_comments_public(
113-
tenant_id: TENANT_ID,
114-
url_id: 'sdk-test-page-simple',
115-
sso: sso_token
126+
TENANT_ID,
127+
'sdk-test-page-simple',
128+
{ sso: sso_token }
116129
)
117130

118131
expect(response).not_to be_nil
@@ -132,11 +145,11 @@ def get_tenant_id
132145
}
133146

134147
response = public_api.create_comment_public(
135-
tenant_id: TENANT_ID,
136-
url_id: 'sdk-test-page-simple-comment',
137-
broadcast_id: "test-#{timestamp}",
138-
comment_data: comment_data,
139-
sso: sso_token
148+
TENANT_ID,
149+
'sdk-test-page-simple-comment',
150+
"test-#{timestamp}",
151+
comment_data,
152+
{ sso: sso_token }
140153
)
141154

142155
expect(response).not_to be_nil
@@ -150,9 +163,9 @@ def get_tenant_id
150163

151164
expect {
152165
public_api.get_comments_public(
153-
tenant_id: 'invalid-tenant-123',
154-
url_id: 'sdk-test-page-secure',
155-
sso: sso_token
166+
'invalid-tenant-123',
167+
'sdk-test-page-secure',
168+
{ sso: sso_token }
156169
)
157170
}.to raise_error(FastCommentsClient::ApiError) do |error|
158171
expect(error.code).to be >= 400
@@ -164,9 +177,9 @@ def get_tenant_id
164177

165178
expect {
166179
public_api.get_comments_public(
167-
tenant_id: TENANT_ID,
168-
url_id: 'sdk-test-page-secure',
169-
sso: malformed_sso
180+
TENANT_ID,
181+
'sdk-test-page-secure',
182+
{ sso: malformed_sso }
170183
)
171184
}.to raise_error(FastCommentsClient::ApiError) do |error|
172185
expect(error.code).to be >= 400

0 commit comments

Comments
 (0)