Class: ScreenshotFreeAPI::Resources::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/screenshotfreeapi/resources/auth.rb

Overview

Authentication endpoints — registration, API key management, and JWT tokens.

Note: ‘token` and `refresh` return JWTs that should be passed as the `jwt:` parameter to billing, workspace, and monitor resource methods.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Auth

Returns a new instance of Auth.



10
11
12
# File 'lib/screenshotfreeapi/resources/auth.rb', line 10

def initialize(http)
  @http = http
end

Instance Method Details

#refresh(refresh_token:) ⇒ Hash

Refresh an expired JWT using a refresh token.

Parameters:

  • refresh_token (String)

    The refresh token from a previous ‘token` call

Returns:

  • (Hash)

    { “token”, “expiresAt” }



51
52
53
54
55
# File 'lib/screenshotfreeapi/resources/auth.rb', line 51

def refresh(refresh_token:)
  @http.request(:post, "/auth/refresh", body: {
    refreshToken: refresh_token
  })
end

#register(email:, password:, name:) ⇒ Hash

Register a new account.

Parameters:

  • email (String)

    User email address

  • password (String)

    Password (min 8 chars on the server)

  • name (String)

    Display name

Returns:

  • (Hash)

    { “userId”, “email”, “apiKey” } NOTE: apiKey is shown ONCE — store it securely.



22
23
24
25
26
27
28
# File 'lib/screenshotfreeapi/resources/auth.rb', line 22

def register(email:, password:, name:)
  @http.request(:post, "/auth/register", body: {
    email:    email,
    password: password,
    name:     name
  })
end

#token(email:, password:) ⇒ Hash

Obtain a management JWT by providing account credentials.

The returned token is required for billing, workspace, and monitor endpoints. Pass it as ‘jwt:` to those resource methods.

Parameters:

  • email (String)
  • password (String)

Returns:

  • (Hash)

    { “token”, “expiresAt” }



39
40
41
42
43
44
# File 'lib/screenshotfreeapi/resources/auth.rb', line 39

def token(email:, password:)
  @http.request(:post, "/auth/token", body: {
    email:    email,
    password: password
  })
end