class MajesticSeo::Api::Response

Attributes

code[RW]
error_message[RW]
full_error[RW]
items[RW]
parsed_items[RW]
response[RW]
success[RW]

Public Class Methods

new(response = nil) click to toggle source
# File lib/majestic_seo/api/response.rb, line 6
def initialize(response = nil)
  self.response             =   response
  self.success              =   false
  self.items                =   []
  self.parsed_items         =   []

  parse_response
end

Public Instance Methods

parse_response() click to toggle source
# File lib/majestic_seo/api/response.rb, line 15
def parse_response
  if self.response.is_a?(Faraday::Response)
    self.response           =   (self.response && self.response.body) ? self.response.body : nil
    
    if self.response
      self.code             =   self.response.fetch("Code", "")
      self.success          =   self.code.downcase.eql?("ok")
      self.error_message    =   self.response.fetch("ErrorMessage", "")
      self.full_error       =   self.response.fetch("FullError", "")
    
      if success?
        self.parsed_items   =   self.response.fetch("DataTables", {}).fetch("Results", {}).fetch("Data", [])
      end
    end
  end
end
stacktrace() click to toggle source
# File lib/majestic_seo/api/response.rb, line 36
def stacktrace
  self.full_error
end
success?() click to toggle source
# File lib/majestic_seo/api/response.rb, line 32
def success?
  self.success
end