Class: MajesticSeo::Api::ItemInfoResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/majestic_seo/api/item_info_response.rb

Instance Attribute Summary

Attributes inherited from Response

#code, #error_message, #full_error, #global_variables, #items, #response, #success, #table_key, #tables

Instance Method Summary collapse

Methods inherited from Response

#parse_global_variables, #parse_response, #parse_table, #parse_tables, #stacktrace, #success?

Constructor Details

#initialize(response, table_key = "Results") ⇒ ItemInfoResponse

Returns a new instance of ItemInfoResponse.



37
38
39
40
41
42
# File 'lib/majestic_seo/api/item_info_response.rb', line 37

def initialize(response, table_key = "Results")
  self.table_key = table_key
  super(response)
  raise_exceptions_if_necessary
  parse_item_info_objects
end

Instance Method Details

#parse_item_info_objectsObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/majestic_seo/api/item_info_response.rb', line 51

def parse_item_info_objects
  parsed      = []
  item_infos  = self.items
  
  if (item_infos && item_infos.any?)
    item_infos.each do |item_info|
      parsed << MajesticSeo::Api::ItemInfo.new(item_info)
    end 

    @items = parsed if (parsed.any?)
  end
end

#raise_exceptions_if_necessaryObject



44
45
46
47
48
49
# File 'lib/majestic_seo/api/item_info_response.rb', line 44

def raise_exceptions_if_necessary
  case self.code
    when 'InsufficientIndexItemInfoUnits'
      raise MajesticSeo::Api::InsufficientIndexItemInfoUnitsException.new(self.error_message)
  end unless success?
end