Class: Passage::User

Inherits:
Object
  • Object
show all
Defined in:
lib/passageidentity/user.rb

Overview

The User class provides methods for interacting with Passage Users

Instance Method Summary collapse

Constructor Details

#initialize(app_id:, req_opts:) ⇒ User

Returns a new instance of User.



9
10
11
12
13
14
15
16
# File 'lib/passageidentity/user.rb', line 9

def initialize(app_id:, req_opts:)
  @app_id = app_id
  @req_opts = req_opts

  @user_client = OpenapiClient::UsersApi.new
  @user_device_client = OpenapiClient::UserDevicesApi.new
  @tokens_client = OpenapiClient::TokensApi.new
end

Instance Method Details

#activate(user_id:) ⇒ Object

Raises:

  • (ArgumentError)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/passageidentity/user.rb', line 58

def activate(user_id:)
  raise ArgumentError, 'user_id is required.' if blank_str?(user_id)

  begin
    response = @user_client.activate_user(@app_id, user_id, @req_opts)
    response.user
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end
end

#create(args:) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/passageidentity/user.rb', line 116

def create(args:)
  if blank_str?(args['email']) && blank_str?(args['phone'])
    raise ArgumentError,
          'At least one of args.email or args.phone is required.'
  end

  begin
    response = @user_client.create_user(@app_id, args, @req_opts)
    response.user
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end
end

#deactivate(user_id:) ⇒ Object

Raises:

  • (ArgumentError)


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/passageidentity/user.rb', line 77

def deactivate(user_id:)
  raise ArgumentError, 'user_id is required.' if blank_str?(user_id)

  begin
    response = @user_client.deactivate_user(@app_id, user_id, @req_opts)
    response.user
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end
end

#delete(user_id:) ⇒ Object

Raises:

  • (ArgumentError)


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/passageidentity/user.rb', line 138

def delete(user_id:)
  raise ArgumentError, 'user_id is required.' if blank_str?(user_id)

  begin
    @user_client.delete_user(@app_id, user_id, @req_opts)
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      'failed to delete Passage User',
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end
end

#get(user_id:) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/passageidentity/user.rb', line 18

def get(user_id:)
  raise ArgumentError, 'user_id is required.' if blank_str?(user_id)

  begin
    response = @user_client.get_user(@app_id, user_id, @req_opts)
    response.user
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end
end

#get_by_identifier(identifier:) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/passageidentity/user.rb', line 37

def get_by_identifier(identifier:)
  raise ArgumentError, 'identifier is required.' if blank_str?(identifier)

  begin
    req_opts = set_get_by_identifier_query_params(identifier: identifier)
    response = @user_client.list_paginated_users(@app_id, req_opts)
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end

  handle_get_by_identifier(users: response.users)
end

#list_devices(user_id:) ⇒ Object

Raises:

  • (ArgumentError)


176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/passageidentity/user.rb', line 176

def list_devices(user_id:)
  raise ArgumentError, 'user_id is required.' if blank_str?(user_id)

  begin
    response = @user_device_client.list_user_devices(@app_id, user_id, @req_opts)
    response.devices
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end
end

#revoke_device(user_id:, device_id:) ⇒ Object

Raises:

  • (ArgumentError)


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/passageidentity/user.rb', line 157

def revoke_device(user_id:, device_id:)
  raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
  raise ArgumentError, 'device_id is required.' if blank_str?(device_id)

  begin
    @user_device_client.delete_user_devices(@app_id, user_id, device_id, @req_opts)
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end
end

#revoke_refresh_tokens(user_id:) ⇒ Object

Raises:

  • (ArgumentError)


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/passageidentity/user.rb', line 195

def revoke_refresh_tokens(user_id:)
  raise ArgumentError, 'user_id is required.' if blank_str?(user_id)

  begin
    @tokens_client.revoke_user_refresh_tokens(@app_id, user_id, @req_opts)
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end
end

#update(user_id:, options:) ⇒ Object

Raises:

  • (ArgumentError)


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/passageidentity/user.rb', line 96

def update(user_id:, options:)
  raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
  raise ArgumentError, 'options are required.' if options.empty?

  begin
    response = @user_client.update_user(@app_id, user_id, options, @req_opts)
    response.user
  rescue OpenapiClient::ApiError => e
    raise PassageError.new(
      status_code: e.code,
      body: try_parse_json_string(e.response_body)
    )
  rescue Faraday::Error => e
    raise PassageError.new(
      status_code: e.response[:status],
      body: e.response[:body]
    )
  end
end