Class: Majestic::Api::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/majestic/api/response.rb

Direct Known Subclasses

ItemInfoResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
# File 'lib/majestic/api/response.rb', line 6

def initialize(response = nil)
  self.response             =   response
  self.success              =   false
  self.items                =   []
  self.parsed_items         =   []

  parse_response
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/majestic/api/response.rb', line 4

def code
  @code
end

#error_messageObject

Returns the value of attribute error_message.



4
5
6
# File 'lib/majestic/api/response.rb', line 4

def error_message
  @error_message
end

#full_errorObject

Returns the value of attribute full_error.



4
5
6
# File 'lib/majestic/api/response.rb', line 4

def full_error
  @full_error
end

#itemsObject

Returns the value of attribute items.



4
5
6
# File 'lib/majestic/api/response.rb', line 4

def items
  @items
end

#parsed_itemsObject

Returns the value of attribute parsed_items.



4
5
6
# File 'lib/majestic/api/response.rb', line 4

def parsed_items
  @parsed_items
end

#responseObject

Returns the value of attribute response.



4
5
6
# File 'lib/majestic/api/response.rb', line 4

def response
  @response
end

#successObject

Returns the value of attribute success.



4
5
6
# File 'lib/majestic/api/response.rb', line 4

def success
  @success
end

Instance Method Details

#parse_responseObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/majestic/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

#stacktraceObject



36
37
38
# File 'lib/majestic/api/response.rb', line 36

def stacktrace
  self.full_error
end

#success?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/majestic/api/response.rb', line 32

def success?
  self.success
end