Class: MajesticSeo::Api::ItemInfo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = nil) ⇒ ItemInfo

This method returns a new instance of the Response class. If one of the parameters are not provided, it will default to nil.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/majestic_seo/api/item_info.rb', line 50

def initialize(response = nil)
  self.response       =   response
  
  self.mappings       =   {
    "ItemNum"                               =>    {:index                                           =>    :integer},
    "ItemType"                              =>    {:type                                            =>    :integer},
    "Item"                                  =>    {:url                                             =>    :string},
    "ResultCode"                            =>    {:result_code                                     =>    :string},
    "Status"                                =>    {:status                                          =>    :string},
    "ExtBackLinks"                          =>    {:external_backlinks                              =>    :integer},
    "RefDomains"                            =>    {:referring_domains                               =>    :integer},
    "IndexedURLs"                           =>    {:indexed_urls                                    =>    :integer},
    "AnalysisResUnitsCost"                  =>    {:analysis_results_unit_cost                      =>    :integer},
    "ACRank"                                =>    {:ac_rank                                         =>    :integer},
    "GetTopBackLinksAnalysisResUnitsCost"   =>    {:get_top_backlinks_analysis_results_unit_cost    =>    :integer},
    "DownloadBacklinksAnalysisResUnitsCost" =>    {:download_backlinks_analysis_results_unit_cost   =>    :integer},
    "RefIPs"                                =>    {:referring_ip_addresses                          =>    :integer},
    "RefSubNets"                            =>    {:referring_subnets                               =>    :integer},
    "RefDomainsEDU"                         =>    {:referring_edu_domains                           =>    :integer},
    "ExtBackLinksEDU"                       =>    {:external_edu_backlinks                          =>    :integer},
    "RefDomainsGOV"                         =>    {:referring_gov_domains                           =>    :integer},
    "ExtBackLinksGOV"                       =>    {:external_gov_backlinks                          =>    :integer},
    "RefDomainsEDU_Exact"                   =>    {:exact_referring_edu_domains                     =>    :integer},
    "ExtBackLinksEDU_Exact"                 =>    {:exact_external_edu_backlinks                    =>    :integer},
    "RefDomainsGOV_Exact"                   =>    {:exact_referring_gov_domains                     =>    :integer},
    "ExtBackLinksGOV_Exact"                 =>    {:exact_external_gov_backlinks                    =>    :integer},
    "CrawledFlag"                           =>    {:crawled                                         =>    :boolean},
    "LastCrawlDate"                         =>    {:last_crawl_date                                 =>    :date},
    "LastCrawlResult"                       =>    {:last_crawl_result                               =>    :string},
    "RedirectFlag"                          =>    {:redirecting                                     =>    :boolean},
    "FinalRedirectResult"                   =>    {:final_redirect_result                           =>    :string},
    "LastSeen"                              =>    {:last_seen                                       =>    :string},
    "OutDomainsExternal"                    =>    {:outbound_domain_links                           =>    :integer},
    "OutLinksExternal"                      =>    {:outbound_external_backliks                      =>    :integer},
    "OutLinksInternal"                      =>    {:outbound_internal_backlinks                     =>    :integer},
    "Title"                                 =>    {:title                                           =>    :string},
    "RedirectTo"                            =>    {:redirecting_to                                  =>    :string},
    "CitationFlow"                          =>    {:citation_flow                                   =>    :integer},
    "TrustFlow"                             =>    {:trust_flow                                      =>    :integer},
    "TrustMetric"                           =>    {:trust_metric                                    =>    :integer}
  }
  
  parse_item_info
end

Instance Attribute Details

#ac_rankObject

Returns the value of attribute ac_rank.



38
39
40
# File 'lib/majestic_seo/api/item_info.rb', line 38

def ac_rank
  @ac_rank
end

#analysis_results_unit_costObject

Returns the value of attribute analysis_results_unit_cost.



38
39
40
# File 'lib/majestic_seo/api/item_info.rb', line 38

def analysis_results_unit_cost
  @analysis_results_unit_cost
end

#citation_flowObject

Returns the value of attribute citation_flow.



46
47
48
# File 'lib/majestic_seo/api/item_info.rb', line 46

def citation_flow
  @citation_flow
end

#crawledObject

Returns the value of attribute crawled.



43
44
45
# File 'lib/majestic_seo/api/item_info.rb', line 43

def crawled
  @crawled
end

Returns the value of attribute download_backlinks_analysis_results_unit_cost.



39
40
41
# File 'lib/majestic_seo/api/item_info.rb', line 39

def download_backlinks_analysis_results_unit_cost
  @download_backlinks_analysis_results_unit_cost
end

#error_messageObject

Returns the value of attribute error_message.



37
38
39
# File 'lib/majestic_seo/api/item_info.rb', line 37

def error_message
  @error_message
end

Returns the value of attribute exact_external_edu_backlinks.



42
43
44
# File 'lib/majestic_seo/api/item_info.rb', line 42

def exact_external_edu_backlinks
  @exact_external_edu_backlinks
end

Returns the value of attribute exact_external_gov_backlinks.



42
43
44
# File 'lib/majestic_seo/api/item_info.rb', line 42

def exact_external_gov_backlinks
  @exact_external_gov_backlinks
end

#exact_referring_edu_domainsObject

Returns the value of attribute exact_referring_edu_domains.



42
43
44
# File 'lib/majestic_seo/api/item_info.rb', line 42

def exact_referring_edu_domains
  @exact_referring_edu_domains
end

#exact_referring_gov_domainsObject

Returns the value of attribute exact_referring_gov_domains.



42
43
44
# File 'lib/majestic_seo/api/item_info.rb', line 42

def exact_referring_gov_domains
  @exact_referring_gov_domains
end

Returns the value of attribute external_backlinks.



38
39
40
# File 'lib/majestic_seo/api/item_info.rb', line 38

def external_backlinks
  @external_backlinks
end

Returns the value of attribute external_edu_backlinks.



41
42
43
# File 'lib/majestic_seo/api/item_info.rb', line 41

def external_edu_backlinks
  @external_edu_backlinks
end

Returns the value of attribute external_gov_backlinks.



41
42
43
# File 'lib/majestic_seo/api/item_info.rb', line 41

def external_gov_backlinks
  @external_gov_backlinks
end

#final_redirect_resultObject

Returns the value of attribute final_redirect_result.



43
44
45
# File 'lib/majestic_seo/api/item_info.rb', line 43

def final_redirect_result
  @final_redirect_result
end

Returns the value of attribute get_top_backlinks_analysis_results_unit_cost.



39
40
41
# File 'lib/majestic_seo/api/item_info.rb', line 39

def get_top_backlinks_analysis_results_unit_cost
  @get_top_backlinks_analysis_results_unit_cost
end

#indexObject

Returns the value of attribute index.



37
38
39
# File 'lib/majestic_seo/api/item_info.rb', line 37

def index
  @index
end

#indexed_urlsObject

Returns the value of attribute indexed_urls.



38
39
40
# File 'lib/majestic_seo/api/item_info.rb', line 38

def indexed_urls
  @indexed_urls
end

#last_crawl_dateObject

Returns the value of attribute last_crawl_date.



43
44
45
# File 'lib/majestic_seo/api/item_info.rb', line 43

def last_crawl_date
  @last_crawl_date
end

#last_crawl_resultObject

Returns the value of attribute last_crawl_result.



43
44
45
# File 'lib/majestic_seo/api/item_info.rb', line 43

def last_crawl_result
  @last_crawl_result
end

#last_seenObject

Returns the value of attribute last_seen.



43
44
45
# File 'lib/majestic_seo/api/item_info.rb', line 43

def last_seen
  @last_seen
end

#mappingsObject

Returns the value of attribute mappings.



36
37
38
# File 'lib/majestic_seo/api/item_info.rb', line 36

def mappings
  @mappings
end

Returns the value of attribute outbound_domain_links.



44
45
46
# File 'lib/majestic_seo/api/item_info.rb', line 44

def outbound_domain_links
  @outbound_domain_links
end

#outbound_external_backliksObject

Returns the value of attribute outbound_external_backliks.



44
45
46
# File 'lib/majestic_seo/api/item_info.rb', line 44

def outbound_external_backliks
  @outbound_external_backliks
end

Returns the value of attribute outbound_internal_backlinks.



44
45
46
# File 'lib/majestic_seo/api/item_info.rb', line 44

def outbound_internal_backlinks
  @outbound_internal_backlinks
end

#redirectingObject

Returns the value of attribute redirecting.



43
44
45
# File 'lib/majestic_seo/api/item_info.rb', line 43

def redirecting
  @redirecting
end

#redirecting_toObject

Returns the value of attribute redirecting_to.



45
46
47
# File 'lib/majestic_seo/api/item_info.rb', line 45

def redirecting_to
  @redirecting_to
end

#referring_domainsObject

Returns the value of attribute referring_domains.



38
39
40
# File 'lib/majestic_seo/api/item_info.rb', line 38

def referring_domains
  @referring_domains
end

#referring_edu_domainsObject

Returns the value of attribute referring_edu_domains.



41
42
43
# File 'lib/majestic_seo/api/item_info.rb', line 41

def referring_edu_domains
  @referring_edu_domains
end

#referring_gov_domainsObject

Returns the value of attribute referring_gov_domains.



41
42
43
# File 'lib/majestic_seo/api/item_info.rb', line 41

def referring_gov_domains
  @referring_gov_domains
end

#referring_ip_addressesObject

Returns the value of attribute referring_ip_addresses.



40
41
42
# File 'lib/majestic_seo/api/item_info.rb', line 40

def referring_ip_addresses
  @referring_ip_addresses
end

#referring_subnetsObject

Returns the value of attribute referring_subnets.



40
41
42
# File 'lib/majestic_seo/api/item_info.rb', line 40

def referring_subnets
  @referring_subnets
end

#responseObject

Returns the value of attribute response.



36
37
38
# File 'lib/majestic_seo/api/item_info.rb', line 36

def response
  @response
end

#result_codeObject

Returns the value of attribute result_code.



37
38
39
# File 'lib/majestic_seo/api/item_info.rb', line 37

def result_code
  @result_code
end

#statusObject

Returns the value of attribute status.



37
38
39
# File 'lib/majestic_seo/api/item_info.rb', line 37

def status
  @status
end

#successObject

Returns the value of attribute success.



37
38
39
# File 'lib/majestic_seo/api/item_info.rb', line 37

def success
  @success
end

#titleObject

Returns the value of attribute title.



45
46
47
# File 'lib/majestic_seo/api/item_info.rb', line 45

def title
  @title
end

#trust_flowObject

Returns the value of attribute trust_flow.



46
47
48
# File 'lib/majestic_seo/api/item_info.rb', line 46

def trust_flow
  @trust_flow
end

#trust_metricObject

Returns the value of attribute trust_metric.



46
47
48
# File 'lib/majestic_seo/api/item_info.rb', line 46

def trust_metric
  @trust_metric
end

#typeObject

Returns the value of attribute type.



37
38
39
# File 'lib/majestic_seo/api/item_info.rb', line 37

def type
  @type
end

#urlObject

Returns the value of attribute url.



37
38
39
# File 'lib/majestic_seo/api/item_info.rb', line 37

def url
  @url
end

Instance Method Details

#parse_item_infoObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/majestic_seo/api/item_info.rb', line 95

def parse_item_info
  self.response.each do |api_column, api_value|
    mapping   =   self.mappings[api_column]
    value     =   (!api_value.nil? && !api_value.to_s.eql?("")) ? api_value.to_s : nil
    
    mapping.each do |column, data_type|
      converted_value = case data_type
        when :string    then value
        when :integer   then value.to_i
        when :date      then value #Return it as a string for now - need to be able to retrieve a result with a date set to determine date parsing format
        when :boolean   then (value.downcase.eql?("true"))
      end
      
      self.send("#{column}=", converted_value)
    end if (mapping && !mapping.empty? && value)
  end
  
  set_result_status
  set_item_type
end

#set_item_typeObject



121
122
123
124
125
126
127
# File 'lib/majestic_seo/api/item_info.rb', line 121

def set_item_type
  self.type = case self.type
    when 1 then :root_domain
    when 2 then :sub_domain
    when 3 then :url
  end
end

#set_result_statusObject



116
117
118
119
# File 'lib/majestic_seo/api/item_info.rb', line 116

def set_result_status
  self.success          =   (self.result_code && self.result_code.downcase.eql?("ok"))
  self.error_message    =   (self.success) ? "" : self.result_code
end