Class: Majestic::Api::ItemInfo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ItemInfo

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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/majestic/api/item_info.rb', line 25

def initialize(data)
  self.data           =   data
  
  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},
    "DownloadRefDomainBacklinksAnalysisResUnitsCost"  => {:download_referring_domains_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},
    "OutLinksPages"                         =>    {:outbound_links_pages                            =>    :integer},
    "Title"                                 =>    {:title                                           =>    :string},
    "RedirectTo"                            =>    {:redirecting_to                                  =>    :string},
    "CitationFlow"                          =>    {:citation_flow                                   =>    :integer},
    "TrustFlow"                             =>    {:trust_flow                                      =>    :integer},
    "TrustMetric"                           =>    {:trust_metric                                    =>    :integer},
    "CrawledURLs"                           =>    {:crawled_urls                                    =>    :integer},
    "RootDomainIPAddress"                   =>    {:root_domain_ip_address                          =>    :string},
    "Language"                              =>    {:language_codes                                  =>    :string_array},
    "LanguageDesc"                          =>    {:language_descriptions                           =>    :string_array},
    "LanguageConfidence"                    =>    {:language_confidences                            =>    :integer_array},
    "LanguagePageRatios"                    =>    {:language_page_ratios                            =>    :float_array},
    "LanguageTotalPages"                    =>    {:language_total_pages                            =>    :integer},          
    "RefLanguage"                           =>    {:referring_language_codes                        =>    :string_array},
    "RefLanguageDesc"                       =>    {:referring_language_descriptions                 =>    :string_array},
    "RefLanguageConfidence"                 =>    {:referring_language_confidences                  =>    :integer_array},
    "RefLanguagePageRatios"                 =>    {:referring_language_page_ratios                  =>    :float_array},
    "RefLanguageTotalPages"                 =>    {:referring_language_total_pages                  =>    :integer},
    "TotalNonUniqueLinks"                   =>    {:total_non_unique_links                          =>    :integer},
  }
  
  self.non_unique_link_types            =   {}
  
  self.non_unique_link_types_mappings   =   {
    "NonUniqueLinkTypeHomepages"            =>    {:homepages                                       =>    :integer},
    "NonUniqueLinkTypeIndirect"             =>    {:indirect                                        =>    :integer},
    "NonUniqueLinkTypeDeleted"              =>    {:deleted                                         =>    :integer},
    "NonUniqueLinkTypeNoFollow"             =>    {:no_follow                                       =>    :integer},
    "NonUniqueLinkTypeProtocolHTTPS"        =>    {:https                                           =>    :integer},
    "NonUniqueLinkTypeFrame"                =>    {:frame                                           =>    :integer},
    "NonUniqueLinkTypeImageLink"            =>    {:image_link                                      =>    :integer},
    "NonUniqueLinkTypeRedirect"             =>    {:redirect                                        =>    :integer},
    "NonUniqueLinkTypeTextLink"             =>    {:text_link                                       =>    :integer},
  }
  
  self.referring_domain_types           =   {}
  
  self.referring_domain_types_mappings  =   {
    "RefDomainTypeLive"                     =>    {:live                                            =>    :integer},
    "RefDomainTypeFollow"                   =>    {:follow                                          =>    :integer},
    "RefDomainTypeHomepageLink"             =>    {:homepage_link                                   =>    :integer},
    "RefDomainTypeDirect"                   =>    {:direct                                          =>    :integer},
    "RefDomainTypeProtocolHTTPS"            =>    {:https                                           =>    :integer},
  }
  
  self.hash_mappings                    =   {
    /^NonUniqueLinkType/i                   =>  :non_unique_link_types,
    /^RefDomainType/i                       =>  :referring_domain_types
  }
  
  self.topical_trust_flows              =   {}
          
  parse_item_info
end

Instance Attribute Details

#ac_rankObject

Returns the value of attribute ac_rank.



6
7
8
# File 'lib/majestic/api/item_info.rb', line 6

def ac_rank
  @ac_rank
end

#analysis_results_unit_costObject

Returns the value of attribute analysis_results_unit_cost.



6
7
8
# File 'lib/majestic/api/item_info.rb', line 6

def analysis_results_unit_cost
  @analysis_results_unit_cost
end

#citation_flowObject

Returns the value of attribute citation_flow.



14
15
16
# File 'lib/majestic/api/item_info.rb', line 14

def citation_flow
  @citation_flow
end

#crawledObject

Returns the value of attribute crawled.



11
12
13
# File 'lib/majestic/api/item_info.rb', line 11

def crawled
  @crawled
end

#crawled_urlsObject

Returns the value of attribute crawled_urls.



15
16
17
# File 'lib/majestic/api/item_info.rb', line 15

def crawled_urls
  @crawled_urls
end

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

Returns the value of attribute download_backlinks_analysis_results_unit_cost.



7
8
9
# File 'lib/majestic/api/item_info.rb', line 7

def download_backlinks_analysis_results_unit_cost
  @download_backlinks_analysis_results_unit_cost
end

#download_referring_domains_analysis_results_unit_costObject

Returns the value of attribute download_referring_domains_analysis_results_unit_cost.



7
8
9
# File 'lib/majestic/api/item_info.rb', line 7

def download_referring_domains_analysis_results_unit_cost
  @download_referring_domains_analysis_results_unit_cost
end

#error_messageObject

Returns the value of attribute error_message.



5
6
7
# File 'lib/majestic/api/item_info.rb', line 5

def error_message
  @error_message
end

Returns the value of attribute exact_external_edu_backlinks.



10
11
12
# File 'lib/majestic/api/item_info.rb', line 10

def exact_external_edu_backlinks
  @exact_external_edu_backlinks
end

Returns the value of attribute exact_external_gov_backlinks.



10
11
12
# File 'lib/majestic/api/item_info.rb', line 10

def exact_external_gov_backlinks
  @exact_external_gov_backlinks
end

#exact_referring_edu_domainsObject

Returns the value of attribute exact_referring_edu_domains.



10
11
12
# File 'lib/majestic/api/item_info.rb', line 10

def exact_referring_edu_domains
  @exact_referring_edu_domains
end

#exact_referring_gov_domainsObject

Returns the value of attribute exact_referring_gov_domains.



10
11
12
# File 'lib/majestic/api/item_info.rb', line 10

def exact_referring_gov_domains
  @exact_referring_gov_domains
end

Returns the value of attribute external_backlinks.



6
7
8
# File 'lib/majestic/api/item_info.rb', line 6

def external_backlinks
  @external_backlinks
end

Returns the value of attribute external_edu_backlinks.



9
10
11
# File 'lib/majestic/api/item_info.rb', line 9

def external_edu_backlinks
  @external_edu_backlinks
end

Returns the value of attribute external_gov_backlinks.



9
10
11
# File 'lib/majestic/api/item_info.rb', line 9

def external_gov_backlinks
  @external_gov_backlinks
end

#final_redirect_resultObject

Returns the value of attribute final_redirect_result.



11
12
13
# File 'lib/majestic/api/item_info.rb', line 11

def final_redirect_result
  @final_redirect_result
end

Returns the value of attribute get_top_backlinks_analysis_results_unit_cost.



7
8
9
# File 'lib/majestic/api/item_info.rb', line 7

def get_top_backlinks_analysis_results_unit_cost
  @get_top_backlinks_analysis_results_unit_cost
end

#hash_mappingsObject

Returns the value of attribute hash_mappings.



20
21
22
# File 'lib/majestic/api/item_info.rb', line 20

def hash_mappings
  @hash_mappings
end

#indexObject

Returns the value of attribute index.



5
6
7
# File 'lib/majestic/api/item_info.rb', line 5

def index
  @index
end

#indexed_urlsObject

Returns the value of attribute indexed_urls.



6
7
8
# File 'lib/majestic/api/item_info.rb', line 6

def indexed_urls
  @indexed_urls
end

#language_codesObject

Returns the value of attribute language_codes.



16
17
18
# File 'lib/majestic/api/item_info.rb', line 16

def language_codes
  @language_codes
end

#language_confidencesObject

Returns the value of attribute language_confidences.



16
17
18
# File 'lib/majestic/api/item_info.rb', line 16

def language_confidences
  @language_confidences
end

#language_descriptionsObject

Returns the value of attribute language_descriptions.



16
17
18
# File 'lib/majestic/api/item_info.rb', line 16

def language_descriptions
  @language_descriptions
end

#language_page_ratiosObject

Returns the value of attribute language_page_ratios.



16
17
18
# File 'lib/majestic/api/item_info.rb', line 16

def language_page_ratios
  @language_page_ratios
end

#language_total_pagesObject

Returns the value of attribute language_total_pages.



16
17
18
# File 'lib/majestic/api/item_info.rb', line 16

def language_total_pages
  @language_total_pages
end

#last_crawl_dateObject

Returns the value of attribute last_crawl_date.



11
12
13
# File 'lib/majestic/api/item_info.rb', line 11

def last_crawl_date
  @last_crawl_date
end

#last_crawl_resultObject

Returns the value of attribute last_crawl_result.



11
12
13
# File 'lib/majestic/api/item_info.rb', line 11

def last_crawl_result
  @last_crawl_result
end

#last_seenObject

Returns the value of attribute last_seen.



11
12
13
# File 'lib/majestic/api/item_info.rb', line 11

def last_seen
  @last_seen
end

#mappingsObject

Returns the value of attribute mappings.



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

def mappings
  @mappings
end

Returns the value of attribute non_unique_link_types.



18
19
20
# File 'lib/majestic/api/item_info.rb', line 18

def non_unique_link_types
  @non_unique_link_types
end

Returns the value of attribute non_unique_link_types_mappings.



18
19
20
# File 'lib/majestic/api/item_info.rb', line 18

def non_unique_link_types_mappings
  @non_unique_link_types_mappings
end

Returns the value of attribute outbound_domain_links.



12
13
14
# File 'lib/majestic/api/item_info.rb', line 12

def outbound_domain_links
  @outbound_domain_links
end

#outbound_external_backliksObject

Returns the value of attribute outbound_external_backliks.



12
13
14
# File 'lib/majestic/api/item_info.rb', line 12

def outbound_external_backliks
  @outbound_external_backliks
end

Returns the value of attribute outbound_internal_backlinks.



12
13
14
# File 'lib/majestic/api/item_info.rb', line 12

def outbound_internal_backlinks
  @outbound_internal_backlinks
end

Returns the value of attribute outbound_links_pages.



12
13
14
# File 'lib/majestic/api/item_info.rb', line 12

def outbound_links_pages
  @outbound_links_pages
end

#redirectingObject

Returns the value of attribute redirecting.



11
12
13
# File 'lib/majestic/api/item_info.rb', line 11

def redirecting
  @redirecting
end

#redirecting_toObject

Returns the value of attribute redirecting_to.



13
14
15
# File 'lib/majestic/api/item_info.rb', line 13

def redirecting_to
  @redirecting_to
end

#referring_domain_typesObject

Returns the value of attribute referring_domain_types.



19
20
21
# File 'lib/majestic/api/item_info.rb', line 19

def referring_domain_types
  @referring_domain_types
end

#referring_domain_types_mappingsObject

Returns the value of attribute referring_domain_types_mappings.



19
20
21
# File 'lib/majestic/api/item_info.rb', line 19

def referring_domain_types_mappings
  @referring_domain_types_mappings
end

#referring_domainsObject

Returns the value of attribute referring_domains.



6
7
8
# File 'lib/majestic/api/item_info.rb', line 6

def referring_domains
  @referring_domains
end

#referring_edu_domainsObject

Returns the value of attribute referring_edu_domains.



9
10
11
# File 'lib/majestic/api/item_info.rb', line 9

def referring_edu_domains
  @referring_edu_domains
end

#referring_gov_domainsObject

Returns the value of attribute referring_gov_domains.



9
10
11
# File 'lib/majestic/api/item_info.rb', line 9

def referring_gov_domains
  @referring_gov_domains
end

#referring_ip_addressesObject

Returns the value of attribute referring_ip_addresses.



8
9
10
# File 'lib/majestic/api/item_info.rb', line 8

def referring_ip_addresses
  @referring_ip_addresses
end

#referring_language_codesObject

Returns the value of attribute referring_language_codes.



17
18
19
# File 'lib/majestic/api/item_info.rb', line 17

def referring_language_codes
  @referring_language_codes
end

#referring_language_confidencesObject

Returns the value of attribute referring_language_confidences.



17
18
19
# File 'lib/majestic/api/item_info.rb', line 17

def referring_language_confidences
  @referring_language_confidences
end

#referring_language_descriptionsObject

Returns the value of attribute referring_language_descriptions.



17
18
19
# File 'lib/majestic/api/item_info.rb', line 17

def referring_language_descriptions
  @referring_language_descriptions
end

#referring_language_page_ratiosObject

Returns the value of attribute referring_language_page_ratios.



17
18
19
# File 'lib/majestic/api/item_info.rb', line 17

def referring_language_page_ratios
  @referring_language_page_ratios
end

#referring_language_total_pagesObject

Returns the value of attribute referring_language_total_pages.



17
18
19
# File 'lib/majestic/api/item_info.rb', line 17

def referring_language_total_pages
  @referring_language_total_pages
end

#referring_subnetsObject

Returns the value of attribute referring_subnets.



8
9
10
# File 'lib/majestic/api/item_info.rb', line 8

def referring_subnets
  @referring_subnets
end

#result_codeObject

Returns the value of attribute result_code.



5
6
7
# File 'lib/majestic/api/item_info.rb', line 5

def result_code
  @result_code
end

#root_domain_ip_addressObject

Returns the value of attribute root_domain_ip_address.



15
16
17
# File 'lib/majestic/api/item_info.rb', line 15

def root_domain_ip_address
  @root_domain_ip_address
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/majestic/api/item_info.rb', line 5

def status
  @status
end

#successObject

Returns the value of attribute success.



5
6
7
# File 'lib/majestic/api/item_info.rb', line 5

def success
  @success
end

#titleObject

Returns the value of attribute title.



13
14
15
# File 'lib/majestic/api/item_info.rb', line 13

def title
  @title
end

#topical_trust_flowsObject

Returns the value of attribute topical_trust_flows.



21
22
23
# File 'lib/majestic/api/item_info.rb', line 21

def topical_trust_flows
  @topical_trust_flows
end

Returns the value of attribute total_non_unique_links.



18
19
20
# File 'lib/majestic/api/item_info.rb', line 18

def total_non_unique_links
  @total_non_unique_links
end

#trust_flowObject

Returns the value of attribute trust_flow.



14
15
16
# File 'lib/majestic/api/item_info.rb', line 14

def trust_flow
  @trust_flow
end

#trust_metricObject

Returns the value of attribute trust_metric.



14
15
16
# File 'lib/majestic/api/item_info.rb', line 14

def trust_metric
  @trust_metric
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/majestic/api/item_info.rb', line 5

def type
  @type
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/majestic/api/item_info.rb', line 5

def url
  @url
end

Instance Method Details

#convert_value(value, column, data_type) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/majestic/api/item_info.rb', line 166

def convert_value(value, column, data_type)
  return case data_type
    when :string
      value.to_s
    when :integer
      value.to_i
    when :float
      value.to_f
    when :date
      value.to_s
    when :boolean
      value.to_s.downcase.eql?("true")
    when :string_array
      value.to_s.include?(",") ? value.to_s.split(",").collect { |val| val.to_s } : [value.to_s]
    when :integer_array
      value.to_s.include?(",") ? value.to_s.split(",").collect { |val| val.to_i } : [value.to_s]
    when :float_array
      value.to_s.include?(",") ? value.to_s.split(",").collect { |val| val.to_f } : [value.to_s]
  end
end

#parse_field(column_mapping, api_column, api_value) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/majestic/api/item_info.rb', line 152

def parse_field(column_mapping, api_column, api_value)
  column    =   nil
  value     =   nil
  
  mapping   =   column_mapping.fetch(api_column, nil)
  
  mapping.each do |col, data_type|
    column  =   col
    value   =   convert_value(api_value.to_s, col, data_type)
  end if mapping && !mapping.empty? && !api_value.to_s.empty?
  
  return column, value
end

#parse_hashesObject



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/majestic/api/item_info.rb', line 128

def parse_hashes
  self.data.each do |api_column, api_value|
    self.hash_mappings.each do |regex, mappings_symbol|
      if api_column =~ regex
        column_mapping    =   self.send("#{mappings_symbol}_mappings".to_sym)
        column, value     =   parse_field(column_mapping, api_column, api_value)
        self.send(mappings_symbol)[column] = value if !column.nil? && !value.nil?
      end
    end
  end
end

#parse_item_infoObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/majestic/api/item_info.rb', line 116

def parse_item_info
  self.data.each do |api_column, api_value|
    column, value   =   parse_field(self.mappings, api_column, api_value)
    self.send("#{column}=", value) if !column.nil? && !value.nil?
  end
  
  parse_hashes
  parse_topical_trust_flows
  set_result_status
  set_item_type
end

#parse_topical_trust_flowsObject



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/majestic/api/item_info.rb', line 140

def parse_topical_trust_flows
  self.data.each do |api_column, api_value|
    if api_column =~ /^TopicalTrustFlow_Topic_\d*/i
      topic   =   api_value.to_s
      index   =   api_column.match(/TopicalTrustFlow_Topic_(?<index>\d*)/i)[:index].to_i
      value   =   self.data.fetch("TopicalTrustFlow_Value_#{index}", nil)
      
      self.topical_trust_flows[index] = {topic: topic, value: value.to_i} if !index.nil? && !topic.empty? && !value.nil?
    end
  end
end

#set_item_typeObject



192
193
194
195
196
197
198
# File 'lib/majestic/api/item_info.rb', line 192

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



187
188
189
190
# File 'lib/majestic/api/item_info.rb', line 187

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