Class: OperationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/maropost_api/custom_types/operation_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ OperationResult

Returns a new instance of OperationResult.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/maropost_api/custom_types/operation_result.rb', line 3

def initialize(result)
  if (200..206).to_a.include? result.code
    @success = true
    @errors = nil
    @data = JSON.parse([result.body].to_json).first
    @data = JSON.parse(@data) if @data.kind_of? String and @data.start_with?("{", "[")
    @data = nil if @data == ""
  else
    @success = false
    @errors = JSON.parse(JSON.parse([result.body].to_json).first) if result.code != 404
    @errors = nil if @errors == ""
    @errors['message'] = 'Page not found!' if result.code == 404
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



2
3
4
# File 'lib/maropost_api/custom_types/operation_result.rb', line 2

def data
  @data
end

#errorsObject

Returns the value of attribute errors.



2
3
4
# File 'lib/maropost_api/custom_types/operation_result.rb', line 2

def errors
  @errors
end

#successObject

Returns the value of attribute success.



2
3
4
# File 'lib/maropost_api/custom_types/operation_result.rb', line 2

def success
  @success
end