Class: Assinafy::Resources::UserResource

Inherits:
BaseResource show all
Defined in:
lib/assinafy/resources/user_resource.rb,
sig/assinafy.rbs

Overview

The authenticated user's own profile and cross-account KPIs.

See https://api.assinafy.com.br/v1/docs for the User Object.

Constant Summary collapse

NOTIFICATION_PREFERENCE_CODES =

Returns:

  • (Array[String])
%w[
  DocumentCompleted
  SignerDeclined
  DocumentCancelled
  DocumentAboutToExpire
  DocumentExpired
  DocumentExpirationReset
  DocumentProcessingFailed
  TemplateProcessingFailed
  SignerWhatsappFailed
].freeze

Constants inherited from BaseResource

BaseResource::AUTH_HEADERS, BaseResource::PAGINATION_HEADERS, BaseResource::PATH_SEGMENT

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from Assinafy::Resources::BaseResource

Instance Method Details

#meHash{String=>Object}

Fetch the authenticated user's profile. The current OpenAPI response is an AuthUser directly, while some sandbox deployments return the login-like { 'user' => AuthUser, 'accounts' => [...] } shape. The SDK does not reshape either form; it returns the envelope's data value unchanged.

Examples:

Fetch the current user

# Request: GET /users/self
client.users.me

# Current OpenAPI response (unwrapped data payload):
{
  'id' => 'user-id',
  'name' => 'Example User',
  'email' => 'user@example.com',
  'telephone' => nil,
  'government_id' => '',
  'is_email_verified' => true,
  'has_accepted_terms' => true,
  'is_password_set' => true,
  'created_at' => '2026-05-12T18:05:11Z',
  'to_be_deleted_at' => nil
}

# Shape returned by some sandbox deployments (also passed through unchanged):
{
  'user' => {
    'id' => 'user-id',
    'name' => 'Example User',
    'email' => 'user@example.com',
    'telephone' => nil,
    'government_id' => '',
    'is_email_verified' => true,
    'has_accepted_terms' => true,
    'is_password_set' => true,
    'created_at' => '2026-05-12T18:05:11Z',
    'to_be_deleted_at' => nil
  },
  'accounts' => [
    {
      'id' => 'account-id',
      'name' => 'Example Workspace',
      'roles' => ['owner'],
      'is_delete_allowed' => true,
      'created_at' => '2026-05-12T18:05:11Z'
    }
  ]
}

Returns:

  • (Hash{String=>Object})

    an AuthUser Hash, or the sandbox { 'user' => {..}, 'accounts' => [{..}] } form

See Also:

  • /users/self


71
72
73
74
75
# File 'lib/assinafy/resources/user_resource.rb', line 71

def me
  call('Failed to fetch current user') do
    http_get('users/self')
  end
end

#notification_preferencesHash{String=>Boolean}

Fetch all owner-facing document email preferences. All nine keys are returned and default to true. Account and security email is not configurable through this endpoint.

Examples:

Fetch the current preferences

# Request: GET /users/self/notification-preferences

# Response (unwrapped data payload):
{
  'DocumentCompleted' => true,
  'SignerDeclined' => true,
  'DocumentCancelled' => true,
  'DocumentAboutToExpire' => true,
  'DocumentExpired' => true,
  'DocumentExpirationReset' => true,
  'DocumentProcessingFailed' => true,
  'TemplateProcessingFailed' => true,
  'SignerWhatsappFailed' => true
}

Returns:

  • (Hash{String=>Boolean})

    all nine documented preference codes

See Also:

  • /users/self/notification-preferences


135
136
137
138
139
# File 'lib/assinafy/resources/user_resource.rb', line 135

def notification_preferences
  call('Failed to fetch notification preferences') do
    http_get('users/self/notification-preferences')
  end
end

#stats(granularity: nil, month: nil) ⇒ Array<Hash>

Note:

Documented in the API reference but not enabled on every environment — the sandbox currently returns 404 for this route.

Fetch the authenticated user's cross-account document KPIs.

Examples:

Fetch monthly cross-account KPIs

# Request: GET /users/self/stats?granularity=monthly
client.users.stats(granularity: 'monthly')

# Response (unwrapped data payload):
[
  {
    'period' => '2026-06',
    'documents_uploaded' => 42,
    'documents_sent' => 37,
    'signature_requests' => 61,
    'signature_requests_notification_email' => 55,
    'signature_requests_notification_whatsapp' => 18,
    'signature_requests_notification_bypass' => 3,
    'signature_requests_verification_email' => 48,
    'signature_requests_verification_whatsapp' => 6,
    'signature_requests_verification_bypass' => 3,
    'signature_requests_verification_digital_certificate' => 4,
    'signature_requests_viewed' => 44,
    'signature_requests_completed' => 52,
    'documents_certified' => 30
  }
]

Parameters:

  • granularity (String, nil) (defaults to: nil)

    "monthly" or "daily"

  • month (String, nil) (defaults to: nil)

    e.g. "2026-06"

  • granularity: (String, nil) (defaults to: nil)
  • month: (String, nil) (defaults to: nil)

Returns:

  • (Array<Hash>)

    one KPI entry per period

See Also:

  • /users/self/stats


108
109
110
111
112
# File 'lib/assinafy/resources/user_resource.rb', line 108

def stats(granularity: nil, month: nil)
  call_array('Failed to fetch user stats') do
    http_get('users/self/stats', query_params(granularity: granularity, month: month))
  end
end

#update_notification_preferences(preferences) ⇒ Hash{String=>Boolean}

Merge selected owner-facing document email preferences.

Omitted keys keep their current values. The API returns the full nine-key map shown by #notification_preferences.

Examples:

Disable one notification

client.users.update_notification_preferences(SignerDeclined: false)

# Request: PUT /users/self/notification-preferences
# Body: { "SignerDeclined": false }

# Response (the full unwrapped preference map):
{
  'DocumentCompleted' => true,
  'SignerDeclined' => false,
  'DocumentCancelled' => true,
  'DocumentAboutToExpire' => true,
  'DocumentExpired' => true,
  'DocumentExpirationReset' => true,
  'DocumentProcessingFailed' => true,
  'TemplateProcessingFailed' => true,
  'SignerWhatsappFailed' => true
}

Parameters:

  • preferences (Hash{String,Symbol=>Boolean})

    non-empty partial map

Returns:

  • (Hash{String=>Boolean})

    the full updated map

Raises:

See Also:

  • /users/self/notification-preferences


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/assinafy/resources/user_resource.rb', line 167

def update_notification_preferences(preferences)
  preferences = require_payload(preferences, 'Notification preferences')
  raise ValidationError.new('At least one notification preference is required') if preferences.empty?

  preferences.each do |code, enabled|
    code = code.to_s
    unless NOTIFICATION_PREFERENCE_CODES.include?(code)
      raise ValidationError.new("Unknown notification preference: #{code}")
    end
    unless [true, false].include?(enabled)
      raise ValidationError.new("Notification preference #{code} must be boolean")
    end
  end

  call('Failed to update notification preferences') do
    http_put('users/self/notification-preferences', body_params(preferences))
  end
end