Class: Twilito::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/twilito/result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success:, errors: [], sid: nil, response: nil) ⇒ Result

Returns a new instance of Result.



7
8
9
10
11
12
# File 'lib/twilito/result.rb', line 7

def initialize(success:, errors: [], sid: nil, response: nil)
  @success = success
  @errors = errors
  @sid = sid
  @response = response
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/twilito/result.rb', line 5

def errors
  @errors
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/twilito/result.rb', line 5

def response
  @response
end

#sidObject (readonly)

Returns the value of attribute sid.



5
6
7
# File 'lib/twilito/result.rb', line 5

def sid
  @sid
end

#successObject (readonly)

Returns the value of attribute success.



5
6
7
# File 'lib/twilito/result.rb', line 5

def success
  @success
end

Class Method Details

.failure(response:, errors:) ⇒ Object



18
19
20
# File 'lib/twilito/result.rb', line 18

def self.failure(response:, errors:)
  new(success: false, response: response, errors: errors)
end

.success(response:, sid:) ⇒ Object



14
15
16
# File 'lib/twilito/result.rb', line 14

def self.success(response:, sid:)
  new(success: true, response: response, sid: sid)
end

Instance Method Details

#dataObject



22
23
24
# File 'lib/twilito/result.rb', line 22

def data
  JSON.parse(response_body || '{}')
end

#success?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/twilito/result.rb', line 26

def success?
  success || false
end