Class: Files::TwoFactorAuthenticationMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/files.com/models/two_factor_authentication_method.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ TwoFactorAuthenticationMethod

Returns a new instance of TwoFactorAuthenticationMethod.



7
8
9
10
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 7

def initialize(attributes = {}, options = {})
  @attributes = attributes || {}
  @options = options || {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 5

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 5

def options
  @options
end

Class Method Details

.create(params = {}, options = {}) ⇒ Object

Parameters:

method_type (required) - string - Type of 2fa
name - string - 2fa method name
phone_number - string - 2fa phone number (if SMS)


184
185
186
187
188
189
190
191
192
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 184

def self.create(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: method_type must be an String") if params.dig(:method_type) and !params.dig(:method_type).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: name must be an String") if params.dig(:name) and !params.dig(:name).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: phone_number must be an String") if params.dig(:phone_number) and !params.dig(:phone_number).is_a?(String)
  raise MissingParameterError.new("Parameter missing: method_type") unless params.dig(:method_type)

  response, options = Api.send_request("/2fa", :post, params, options)
  TwoFactorAuthenticationMethod.new(response.data, options)
end

.delete(id, params = {}, options = {}) ⇒ Object



216
217
218
219
220
221
222
223
224
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 216

def self.delete(id, params = {}, options = {})
  params ||= {}
  params[:id] = id
  raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

  response, _options = Api.send_request("/2fa/#{params[:id]}", :delete, params, options)
  response.data
end

.destroy(id, params = {}, options = {}) ⇒ Object



226
227
228
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 226

def self.destroy(id, params = {}, options = {})
  delete(id, params, options)
end

.get(params = {}, options = {}) ⇒ Object

Parameters:

page - integer - Current page number.
per_page - integer - Number of records to show per page.  (Max: 10,000, 1,000 or less is recommended).
action - string - Deprecated: If set to `count` returns a count of matching records rather than the records themselves.


171
172
173
174
175
176
177
178
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 171

def self.get(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: page must be an Integer") if params.dig(:page) and !params.dig(:page).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: per_page must be an Integer") if params.dig(:per_page) and !params.dig(:per_page).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)

  response, options = Api.send_request("/2fa", :get, params, options)
  response.data.map { |object| TwoFactorAuthenticationMethod.new(object, options) }
end

.send_code(params = {}, options = {}) ⇒ Object

Parameters:

u2f_only - boolean - Set to `true` to only generate an OTP for U2F (FIDO) keys and skip things like SMS.


196
197
198
199
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 196

def self.send_code(params = {}, options = {})
  response, options = Api.send_request("/2fa/send_code", :post, params, options)
  U2fSignRequest.new(response.data, options)
end

.update(id, params = {}, options = {}) ⇒ Object

Parameters:

otp - string - Current value of OTP, Yubikey string, or U2F response value.  U2F response value requires a json stringified object containing fields `clientData`, `keyHandle`, and `signatureData`.
name - string - 2fa method name


204
205
206
207
208
209
210
211
212
213
214
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 204

def self.update(id, params = {}, options = {})
  params ||= {}
  params[:id] = id
  raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: otp must be an String") if params.dig(:otp) and !params.dig(:otp).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: name must be an String") if params.dig(:name) and !params.dig(:name).is_a?(String)
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

  response, options = Api.send_request("/2fa/#{params[:id]}", :patch, params, options)
  TwoFactorAuthenticationMethod.new(response.data, options)
end

Instance Method Details

#delete(params = {}) ⇒ Object



144
145
146
147
148
149
150
151
152
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 144

def delete(params = {})
  params ||= {}
  params[:id] = @attributes[:id]
  raise MissingParameterError.new("Current object doesn't have a id") unless @attributes[:id]
  raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

  Api.send_request("/2fa/#{@attributes[:id]}", :delete, params, @options)
end

#destroy(params = {}) ⇒ Object



154
155
156
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 154

def destroy(params = {})
  delete(params)
end

#idObject

int64 - 2fa ID



13
14
15
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 13

def id
  @attributes[:id]
end

#id=(value) ⇒ Object



17
18
19
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 17

def id=(value)
  @attributes[:id] = value
end

#method_typeObject

string - Type of 2fa



22
23
24
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 22

def method_type
  @attributes[:method_type]
end

#method_type=(value) ⇒ Object



26
27
28
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 26

def method_type=(value)
  @attributes[:method_type] = value
end

#nameObject

string - 2fa method name



31
32
33
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 31

def name
  @attributes[:name]
end

#name=(value) ⇒ Object



35
36
37
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 35

def name=(value)
  @attributes[:name] = value
end

#otpObject

string - Current value of OTP, Yubikey string, or U2F response value. U2F response value requires a json stringified object containing fields ‘clientData`, `keyHandle`, and `signatureData`.



121
122
123
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 121

def otp
  @attributes[:otp]
end

#otp=(value) ⇒ Object



125
126
127
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 125

def otp=(value)
  @attributes[:otp] = value
end

#phone_numberObject

string - 2fa phone number (if SMS)



40
41
42
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 40

def phone_number
  @attributes[:phone_number]
end

#phone_number=(value) ⇒ Object



44
45
46
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 44

def phone_number=(value)
  @attributes[:phone_number] = value
end

#phone_number_countryObject

string - 2fa phone number country (if SMS)



49
50
51
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 49

def phone_number_country
  @attributes[:phone_number_country]
end

#phone_number_country=(value) ⇒ Object



53
54
55
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 53

def phone_number_country=(value)
  @attributes[:phone_number_country] = value
end

#phone_number_national_formatObject

string - 2fa phone number national format (if SMS)



58
59
60
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 58

def phone_number_national_format
  @attributes[:phone_number_national_format]
end

#phone_number_national_format=(value) ⇒ Object



62
63
64
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 62

def phone_number_national_format=(value)
  @attributes[:phone_number_national_format] = value
end

#saveObject



158
159
160
161
162
163
164
165
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 158

def save
  if @attributes[:id]
    update(@attributes)
  else
    new_obj = TwoFactorAuthenticationMethod.create(@attributes, @options)
    @attributes = new_obj.attributes
  end
end

#setup_completeObject

boolean - 2fa setup complete?



76
77
78
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 76

def setup_complete
  @attributes[:setup_complete]
end

#setup_complete=(value) ⇒ Object



80
81
82
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 80

def setup_complete=(value)
  @attributes[:setup_complete] = value
end

#setup_expiredObject

boolean - 2fa setup expired?



67
68
69
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 67

def setup_expired
  @attributes[:setup_expired]
end

#setup_expired=(value) ⇒ Object



71
72
73
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 71

def setup_expired=(value)
  @attributes[:setup_expired] = value
end

#setup_expires_atObject

date-time - 2fa setup expires at this date/time (typically 10 minutes after a new method is created)



85
86
87
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 85

def setup_expires_at
  @attributes[:setup_expires_at]
end

#setup_expires_at=(value) ⇒ Object



89
90
91
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 89

def setup_expires_at=(value)
  @attributes[:setup_expires_at] = value
end

#totp_provisioning_uriObject

string - TOTP provisioning URI (if TOTP)



94
95
96
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 94

def totp_provisioning_uri
  @attributes[:totp_provisioning_uri]
end

#totp_provisioning_uri=(value) ⇒ Object



98
99
100
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 98

def totp_provisioning_uri=(value)
  @attributes[:totp_provisioning_uri] = value
end

#u2f_app_idObject

string - U2F app ID (if U2F)



103
104
105
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 103

def u2f_app_id
  @attributes[:u2f_app_id]
end

#u2f_app_id=(value) ⇒ Object



107
108
109
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 107

def u2f_app_id=(value)
  @attributes[:u2f_app_id] = value
end

#u2f_registration_requestsObject

array - U2F registration requests (if U2F)



112
113
114
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 112

def u2f_registration_requests
  @attributes[:u2f_registration_requests]
end

#u2f_registration_requests=(value) ⇒ Object



116
117
118
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 116

def u2f_registration_requests=(value)
  @attributes[:u2f_registration_requests] = value
end

#update(params = {}) ⇒ Object

Parameters:

otp - string - Current value of OTP, Yubikey string, or U2F response value.  U2F response value requires a json stringified object containing fields `clientData`, `keyHandle`, and `signatureData`.
name - string - 2fa method name


132
133
134
135
136
137
138
139
140
141
142
# File 'lib/files.com/models/two_factor_authentication_method.rb', line 132

def update(params = {})
  params ||= {}
  params[:id] = @attributes[:id]
  raise MissingParameterError.new("Current object doesn't have a id") unless @attributes[:id]
  raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: otp must be an String") if params.dig(:otp) and !params.dig(:otp).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: name must be an String") if params.dig(:name) and !params.dig(:name).is_a?(String)
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

  Api.send_request("/2fa/#{@attributes[:id]}", :patch, params, @options)
end