Class: WhopSDK::Client
Constant Summary
collapse
- DEFAULT_MAX_RETRIES =
Default max number of retries to attempt after a failed retryable request.
2
- DEFAULT_TIMEOUT_IN_SECONDS =
Default per-request timeout.
60.0
- DEFAULT_INITIAL_RETRY_DELAY =
Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.
0.5
- DEFAULT_MAX_RETRY_DELAY =
Default max retry delay in seconds.
8.0
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary
collapse
follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(api_key: ENV["WHOP_API_KEY"], app_id: ENV["WHOP_APP_ID"], base_url: ENV["WHOP_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client
Creates and returns a new client for interacting with the API.
‘ENV`
tokens Defaults to ‘ENV`
‘“api.example.com/v2/”`. Defaults to `ENV`
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
# File 'lib/whop_sdk/client.rb', line 171
def initialize(
api_key: ENV["WHOP_API_KEY"],
app_id: ENV["WHOP_APP_ID"],
base_url: ENV["WHOP_BASE_URL"],
max_retries: self.class::DEFAULT_MAX_RETRIES,
timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
base_url ||= "https://api.whop.com/api/v1"
if api_key.nil?
raise ArgumentError.new("api_key is required, and can be set via environ: \"WHOP_API_KEY\"")
end
= {
"x-whop-app-id" => (@app_id = app_id&.to_s)
}
@api_key = api_key.to_s
super(
base_url: base_url,
timeout: timeout,
max_retries: max_retries,
initial_retry_delay: initial_retry_delay,
max_retry_delay: max_retry_delay,
headers:
)
@apps = WhopSDK::Resources::Apps.new(client: self)
@invoices = WhopSDK::Resources::Invoices.new(client: self)
@course_lesson_interactions = WhopSDK::Resources::CourseLessonInteractions.new(client: self)
@products = WhopSDK::Resources::Products.new(client: self)
@companies = WhopSDK::Resources::Companies.new(client: self)
@webhooks = WhopSDK::Resources::Webhooks.new(client: self)
@plans = WhopSDK::Resources::Plans.new(client: self)
@entries = WhopSDK::Resources::Entries.new(client: self)
@forum_posts = WhopSDK::Resources::ForumPosts.new(client: self)
@transfers = WhopSDK::Resources::Transfers.new(client: self)
@ledger_accounts = WhopSDK::Resources::LedgerAccounts.new(client: self)
@memberships = WhopSDK::Resources::Memberships.new(client: self)
@authorized_users = WhopSDK::Resources::AuthorizedUsers.new(client: self)
@app_builds = WhopSDK::Resources::AppBuilds.new(client: self)
@shipments = WhopSDK::Resources::Shipments.new(client: self)
@checkout_configurations = WhopSDK::Resources::CheckoutConfigurations.new(client: self)
@messages = WhopSDK::Resources::Messages.new(client: self)
@chat_channels = WhopSDK::Resources::ChatChannels.new(client: self)
@users = WhopSDK::Resources::Users.new(client: self)
@payments = WhopSDK::Resources::Payments.new(client: self)
@support_channels = WhopSDK::Resources::SupportChannels.new(client: self)
@experiences = WhopSDK::Resources::Experiences.new(client: self)
@reactions = WhopSDK::Resources::Reactions.new(client: self)
@members = WhopSDK::Resources::Members.new(client: self)
@forums = WhopSDK::Resources::Forums.new(client: self)
@promo_codes = WhopSDK::Resources::PromoCodes.new(client: self)
@courses = WhopSDK::Resources::Courses.new(client: self)
@course_chapters = WhopSDK::Resources::CourseChapters.new(client: self)
@course_lessons = WhopSDK::Resources::CourseLessons.new(client: self)
@reviews = WhopSDK::Resources::Reviews.new(client: self)
@course_students = WhopSDK::Resources::CourseStudents.new(client: self)
@access_tokens = WhopSDK::Resources::AccessTokens.new(client: self)
@notifications = WhopSDK::Resources::Notifications.new(client: self)
@disputes = WhopSDK::Resources::Disputes.new(client: self)
@refunds = WhopSDK::Resources::Refunds.new(client: self)
@withdrawals = WhopSDK::Resources::Withdrawals.new(client: self)
@account_links = WhopSDK::Resources::AccountLinks.new(client: self)
@setup_intents = WhopSDK::Resources::SetupIntents.new(client: self)
@payment_methods = WhopSDK::Resources::PaymentMethods.new(client: self)
end
|
Instance Attribute Details
121
122
123
|
# File 'lib/whop_sdk/client.rb', line 121
def access_tokens
@access_tokens
end
|
136
137
138
|
# File 'lib/whop_sdk/client.rb', line 136
def account_links
@account_links
end
|
#api_key ⇒ String
The app API key from an app from the /dashboard/developer page
20
21
22
|
# File 'lib/whop_sdk/client.rb', line 20
def api_key
@api_key
end
|
67
68
69
|
# File 'lib/whop_sdk/client.rb', line 67
def app_builds
@app_builds
end
|
#app_id ⇒ String?
When using the SDK in app mode pass this parameter to allow verifying user tokens
25
26
27
|
# File 'lib/whop_sdk/client.rb', line 25
def app_id
@app_id
end
|
28
29
30
|
# File 'lib/whop_sdk/client.rb', line 28
def apps
@apps
end
|
64
65
66
|
# File 'lib/whop_sdk/client.rb', line 64
def authorized_users
@authorized_users
end
|
79
80
81
|
# File 'lib/whop_sdk/client.rb', line 79
def chat_channels
@chat_channels
end
|
73
74
75
|
# File 'lib/whop_sdk/client.rb', line 73
def checkout_configurations
@checkout_configurations
end
|
40
41
42
|
# File 'lib/whop_sdk/client.rb', line 40
def companies
@companies
end
|
109
110
111
|
# File 'lib/whop_sdk/client.rb', line 109
def course_chapters
@course_chapters
end
|
34
35
36
|
# File 'lib/whop_sdk/client.rb', line 34
def course_lesson_interactions
@course_lesson_interactions
end
|
112
113
114
|
# File 'lib/whop_sdk/client.rb', line 112
def course_lessons
@course_lessons
end
|
118
119
120
|
# File 'lib/whop_sdk/client.rb', line 118
def course_students
@course_students
end
|
106
107
108
|
# File 'lib/whop_sdk/client.rb', line 106
def courses
@courses
end
|
127
128
129
|
# File 'lib/whop_sdk/client.rb', line 127
def disputes
@disputes
end
|
49
50
51
|
# File 'lib/whop_sdk/client.rb', line 49
def entries
@entries
end
|
91
92
93
|
# File 'lib/whop_sdk/client.rb', line 91
def experiences
@experiences
end
|
52
53
54
|
# File 'lib/whop_sdk/client.rb', line 52
def forum_posts
@forum_posts
end
|
100
101
102
|
# File 'lib/whop_sdk/client.rb', line 100
def forums
@forums
end
|
31
32
33
|
# File 'lib/whop_sdk/client.rb', line 31
def invoices
@invoices
end
|
58
59
60
|
# File 'lib/whop_sdk/client.rb', line 58
def ledger_accounts
@ledger_accounts
end
|
97
98
99
|
# File 'lib/whop_sdk/client.rb', line 97
def members
@members
end
|
61
62
63
|
# File 'lib/whop_sdk/client.rb', line 61
def memberships
@memberships
end
|
76
77
78
|
# File 'lib/whop_sdk/client.rb', line 76
def messages
@messages
end
|
124
125
126
|
# File 'lib/whop_sdk/client.rb', line 124
def notifications
@notifications
end
|
142
143
144
|
# File 'lib/whop_sdk/client.rb', line 142
def payment_methods
@payment_methods
end
|
85
86
87
|
# File 'lib/whop_sdk/client.rb', line 85
def payments
@payments
end
|
46
47
48
|
# File 'lib/whop_sdk/client.rb', line 46
def plans
@plans
end
|
37
38
39
|
# File 'lib/whop_sdk/client.rb', line 37
def products
@products
end
|
103
104
105
|
# File 'lib/whop_sdk/client.rb', line 103
def promo_codes
@promo_codes
end
|
94
95
96
|
# File 'lib/whop_sdk/client.rb', line 94
def reactions
@reactions
end
|
130
131
132
|
# File 'lib/whop_sdk/client.rb', line 130
def refunds
@refunds
end
|
115
116
117
|
# File 'lib/whop_sdk/client.rb', line 115
def reviews
@reviews
end
|
139
140
141
|
# File 'lib/whop_sdk/client.rb', line 139
def setup_intents
@setup_intents
end
|
70
71
72
|
# File 'lib/whop_sdk/client.rb', line 70
def shipments
@shipments
end
|
88
89
90
|
# File 'lib/whop_sdk/client.rb', line 88
def support_channels
@support_channels
end
|
55
56
57
|
# File 'lib/whop_sdk/client.rb', line 55
def transfers
@transfers
end
|
82
83
84
|
# File 'lib/whop_sdk/client.rb', line 82
def users
@users
end
|
43
44
45
|
# File 'lib/whop_sdk/client.rb', line 43
def webhooks
@webhooks
end
|
133
134
135
|
# File 'lib/whop_sdk/client.rb', line 133
def withdrawals
@withdrawals
end
|
Instance Method Details
#verify_user_token(token_or_headers, **opts) ⇒ UserTokenPayload?
Verifies a Whop user token
265
266
267
268
269
|
# File 'lib/whop_sdk/client.rb', line 265
def verify_user_token(, **opts)
verify_user_token!(, **opts)
rescue StandardError
nil
end
|
#verify_user_token!(token_or_headers, **opts) ⇒ UserTokenPayload
Verifies a Whop user token
250
251
252
253
254
255
256
|
# File 'lib/whop_sdk/client.rb', line 250
def verify_user_token!(, **opts)
opts[:app_id] ||= app_id
unless opts[:app_id]
raise StandardError, "You must set app_id in the Whop client if you want to verify user tokens"
end
Helpers::VerifyUserToken.verify_user_token!(, **opts)
end
|