Class: Onlyfans::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/onlyfans/client.rb

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

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(api_key: ENV["ONLYFANSAPI_API_KEY"], base_url: ENV["ONLY_FANS_API_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.

Defaults to ‘ENV`

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • api_key (String, nil) (defaults to: ENV["ONLYFANSAPI_API_KEY"])

    Get your API Key from OnlyFansAPI Console - app.onlyfansapi.com/api-keys

  • base_url (String, nil) (defaults to: ENV["ONLY_FANS_API_BASE_URL"])

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/onlyfans/client.rb', line 198

def initialize(
  api_key: ENV["ONLYFANSAPI_API_KEY"],
  base_url: ENV["ONLY_FANS_API_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://app.onlyfansapi.com"

  if api_key.nil?
    raise ArgumentError.new("api_key is required, and can be set via environ: \"ONLYFANSAPI_API_KEY\"")
  end

  headers = {}
  custom_headers_env = ENV["ONLY_FANS_API_CUSTOM_HEADERS"]
  unless custom_headers_env.nil?
    parsed = {}
    custom_headers_env.split("\n").each do |line|
      colon = line.index(":")
      unless colon.nil?
        parsed[line[0...colon].strip] = line[(colon + 1)..].strip
      end
    end
    headers = parsed.merge(headers)
  end

  @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: headers
  )

  @whoami = Onlyfans::Resources::Whoami.new(client: self)
  @accounts = Onlyfans::Resources::Accounts.new(client: self)
  @me = Onlyfans::Resources::Me.new(client: self)
  @analytics = Onlyfans::Resources::Analytics.new(client: self)
  @banking = Onlyfans::Resources::Banking.new(client: self)
  @chargebacks = Onlyfans::Resources::Chargebacks.new(client: self)
  @chats = Onlyfans::Resources::Chats.new(client: self)
  @messages = Onlyfans::Resources::Messages.new(client: self)
  @client_sessions = Onlyfans::Resources::ClientSessions.new(client: self)
  @authenticate = Onlyfans::Resources::Authenticate.new(client: self)
  @data_exports = Onlyfans::Resources::DataExports.new(client: self)
  @engagement = Onlyfans::Resources::Engagement.new(client: self)
  @fans = Onlyfans::Resources::Fans.new(client: self)
  @following = Onlyfans::Resources::Following.new(client: self)
  @trial_links = Onlyfans::Resources::TrialLinks.new(client: self)
  @giphy = Onlyfans::Resources::Giphy.new(client: self)
  @link_tags = Onlyfans::Resources::LinkTags.new(client: self)
  @mass_messaging = Onlyfans::Resources::MassMessaging.new(client: self)
  @media = Onlyfans::Resources::Media.new(client: self)
  @notifications = Onlyfans::Resources::Notifications.new(client: self)
  @payouts = Onlyfans::Resources::Payouts.new(client: self)
  @posts = Onlyfans::Resources::Posts.new(client: self)
  @promotions = Onlyfans::Resources::Promotions.new(client: self)
  @profiles = Onlyfans::Resources::Profiles.new(client: self)
  @search = Onlyfans::Resources::Search.new(client: self)
  @queue = Onlyfans::Resources::Queue.new(client: self)
  @release_forms = Onlyfans::Resources::ReleaseForms.new(client: self)
  @saved_for_later = Onlyfans::Resources::SavedForLater.new(client: self)
  @settings = Onlyfans::Resources::Settings.new(client: self)
  @shared_trial_links = Onlyfans::Resources::SharedTrialLinks.new(client: self)
  @shared_tracking_links = Onlyfans::Resources::SharedTrackingLinks.new(client: self)
  @smart_link_postbacks = Onlyfans::Resources::SmartLinkPostbacks.new(client: self)
  @smart_links = Onlyfans::Resources::SmartLinks.new(client: self)
  @statistics = Onlyfans::Resources::Statistics.new(client: self)
  @subscribers = Onlyfans::Resources::Subscribers.new(client: self)
  @stored = Onlyfans::Resources::Stored.new(client: self)
  @stories = Onlyfans::Resources::Stories.new(client: self)
  @bundles = Onlyfans::Resources::Bundles.new(client: self)
  @tracking_links = Onlyfans::Resources::TrackingLinks.new(client: self)
  @transactions = Onlyfans::Resources::Transactions.new(client: self)
  @user_lists = Onlyfans::Resources::UserLists.new(client: self)
  @users = Onlyfans::Resources::Users.new(client: self)
  @webhooks = Onlyfans::Resources::Webhooks.new(client: self)
end

Instance Attribute Details

#accountsOnlyfans::Resources::Accounts (readonly)

Endpoints for your linked accounts



27
28
29
# File 'lib/onlyfans/client.rb', line 27

def accounts
  @accounts
end

#analyticsOnlyfans::Resources::Analytics (readonly)



34
35
36
# File 'lib/onlyfans/client.rb', line 34

def analytics
  @analytics
end

#api_keyString (readonly)

Get your API Key from OnlyFansAPI Console - app.onlyfansapi.com/api-keys

Returns:

  • (String)


20
21
22
# File 'lib/onlyfans/client.rb', line 20

def api_key
  @api_key
end

#authenticateOnlyfans::Resources::Authenticate (readonly)



54
55
56
# File 'lib/onlyfans/client.rb', line 54

def authenticate
  @authenticate
end

#bankingOnlyfans::Resources::Banking (readonly)

Operations related to user banking details, payout methods, legal and tax information, and account country settings.



39
40
41
# File 'lib/onlyfans/client.rb', line 39

def banking
  @banking
end

#bundlesOnlyfans::Resources::Bundles (readonly)



154
155
156
# File 'lib/onlyfans/client.rb', line 154

def bundles
  @bundles
end

#chargebacksOnlyfans::Resources::Chargebacks (readonly)



42
43
44
# File 'lib/onlyfans/client.rb', line 42

def chargebacks
  @chargebacks
end

#chatsOnlyfans::Resources::Chats (readonly)



45
46
47
# File 'lib/onlyfans/client.rb', line 45

def chats
  @chats
end

#client_sessionsOnlyfans::Resources::ClientSessions (readonly)



51
52
53
# File 'lib/onlyfans/client.rb', line 51

def client_sessions
  @client_sessions
end

#data_exportsOnlyfans::Resources::DataExports (readonly)

APIs for managing data exports



58
59
60
# File 'lib/onlyfans/client.rb', line 58

def data_exports
  @data_exports
end

#engagementOnlyfans::Resources::Engagement (readonly)



61
62
63
# File 'lib/onlyfans/client.rb', line 61

def engagement
  @engagement
end

#fansOnlyfans::Resources::Fans (readonly)

APIs for managing OnlyFans fans (subscribers)



65
66
67
# File 'lib/onlyfans/client.rb', line 65

def fans
  @fans
end

#followingOnlyfans::Resources::Following (readonly)

APIs for managing OnlyFans followings (people you’re subscribed to)



69
70
71
# File 'lib/onlyfans/client.rb', line 69

def following
  @following
end

#giphyOnlyfans::Resources::Giphy (readonly)



76
77
78
# File 'lib/onlyfans/client.rb', line 76

def giphy
  @giphy
end

APIs for managing tags on free trial links and tracking links



80
81
82
# File 'lib/onlyfans/client.rb', line 80

def link_tags
  @link_tags
end

#mass_messagingOnlyfans::Resources::MassMessaging (readonly)



83
84
85
# File 'lib/onlyfans/client.rb', line 83

def mass_messaging
  @mass_messaging
end

#meOnlyfans::Resources::Me (readonly)

Endpoints for your linked accounts



31
32
33
# File 'lib/onlyfans/client.rb', line 31

def me
  @me
end

#mediaOnlyfans::Resources::Media (readonly)



86
87
88
# File 'lib/onlyfans/client.rb', line 86

def media
  @media
end

#messagesOnlyfans::Resources::Messages (readonly)



48
49
50
# File 'lib/onlyfans/client.rb', line 48

def messages
  @messages
end

#notificationsOnlyfans::Resources::Notifications (readonly)

Endpoints for managingr account notifications



90
91
92
# File 'lib/onlyfans/client.rb', line 90

def notifications
  @notifications
end

#payoutsOnlyfans::Resources::Payouts (readonly)



93
94
95
# File 'lib/onlyfans/client.rb', line 93

def payouts
  @payouts
end

#postsOnlyfans::Resources::Posts (readonly)

APIs for managing OnlyFans posts



97
98
99
# File 'lib/onlyfans/client.rb', line 97

def posts
  @posts
end

#profilesOnlyfans::Resources::Profiles (readonly)



103
104
105
# File 'lib/onlyfans/client.rb', line 103

def profiles
  @profiles
end

#promotionsOnlyfans::Resources::Promotions (readonly)



100
101
102
# File 'lib/onlyfans/client.rb', line 100

def promotions
  @promotions
end

#queueOnlyfans::Resources::Queue (readonly)



109
110
111
# File 'lib/onlyfans/client.rb', line 109

def queue
  @queue
end

#release_formsOnlyfans::Resources::ReleaseForms (readonly)

APIs for managing OnlyFans release forms



113
114
115
# File 'lib/onlyfans/client.rb', line 113

def release_forms
  @release_forms
end

#saved_for_laterOnlyfans::Resources::SavedForLater (readonly)



116
117
118
# File 'lib/onlyfans/client.rb', line 116

def saved_for_later
  @saved_for_later
end

#searchOnlyfans::Resources::Search (readonly)



106
107
108
# File 'lib/onlyfans/client.rb', line 106

def search
  @search
end

#settingsOnlyfans::Resources::Settings (readonly)



119
120
121
# File 'lib/onlyfans/client.rb', line 119

def settings
  @settings
end

APIs for Tracking Links (campaigns) that other OF creators have shared with this account. Revenue, cost, and spender data are not available for shared campaigns.



129
130
131
# File 'lib/onlyfans/client.rb', line 129

def shared_tracking_links
  @shared_tracking_links
end

APIs for Free Trial Links that other OF creators have shared with this account. Revenue, cost, and spender data are not available for shared links.



124
125
126
# File 'lib/onlyfans/client.rb', line 124

def shared_trial_links
  @shared_trial_links
end

APIs for managing Smart Link postback destinations



133
134
135
# File 'lib/onlyfans/client.rb', line 133

def smart_link_postbacks
  @smart_link_postbacks
end

APIs for managing Smart Links (Free Trial Links and Tracking Links with pooled inventory)



138
139
140
# File 'lib/onlyfans/client.rb', line 138

def smart_links
  @smart_links
end

#statisticsOnlyfans::Resources::Statistics (readonly)



141
142
143
# File 'lib/onlyfans/client.rb', line 141

def statistics
  @statistics
end

#storedOnlyfans::Resources::Stored (readonly)



147
148
149
# File 'lib/onlyfans/client.rb', line 147

def stored
  @stored
end

#storiesOnlyfans::Resources::Stories (readonly)

APIs for managing OnlyFans stories



151
152
153
# File 'lib/onlyfans/client.rb', line 151

def stories
  @stories
end

#subscribersOnlyfans::Resources::Subscribers (readonly)



144
145
146
# File 'lib/onlyfans/client.rb', line 144

def subscribers
  @subscribers
end

APIs for managing tracking links



158
159
160
# File 'lib/onlyfans/client.rb', line 158

def tracking_links
  @tracking_links
end

#transactionsOnlyfans::Resources::Transactions (readonly)

APIs for managing OnlyFans transactions



162
163
164
# File 'lib/onlyfans/client.rb', line 162

def transactions
  @transactions
end

APIs for managing Free Trial Links



73
74
75
# File 'lib/onlyfans/client.rb', line 73

def trial_links
  @trial_links
end

#user_listsOnlyfans::Resources::UserLists (readonly)



165
166
167
# File 'lib/onlyfans/client.rb', line 165

def user_lists
  @user_lists
end

#usersOnlyfans::Resources::Users (readonly)

APIs for fetching OnlyFans users



169
170
171
# File 'lib/onlyfans/client.rb', line 169

def users
  @users
end

#webhooksOnlyfans::Resources::Webhooks (readonly)



172
173
174
# File 'lib/onlyfans/client.rb', line 172

def webhooks
  @webhooks
end

#whoamiOnlyfans::Resources::Whoami (readonly)



23
24
25
# File 'lib/onlyfans/client.rb', line 23

def whoami
  @whoami
end