Sha256: ec9ea08f5c5adca1c6ceecfb38d8ab3cac9d0303df035b03a6f4295c306d09e7

Contents?: true

Size: 609 Bytes

Versions: 3

Compression:

Stored size: 609 Bytes

Contents

class OperationResult
  attr_accessor :errors, :success, :data
  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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
maropost-api-0.2.1 lib/maropost_api/custom_types/operation_result.rb
maropost-api-0.2.0 lib/maropost_api/custom_types/operation_result.rb
maropost-api-0.1.0 lib/maropost_api/custom_types/operation_result.rb