Class: Awis::Models::UrlInfo
Instance Attribute Summary collapse
-
#asin ⇒ Object
Returns the value of attribute asin.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#contact_info ⇒ Object
Returns the value of attribute contact_info.
-
#content_data ⇒ Object
Returns the value of attribute content_data.
-
#contributing_subdomains ⇒ Object
Returns the value of attribute contributing_subdomains.
-
#data_url ⇒ Object
Returns the value of attribute data_url.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#rank_by_country ⇒ Object
Returns the value of attribute rank_by_country.
-
#related_links ⇒ Object
Returns the value of attribute related_links.
-
#usage_statistics ⇒ Object
Returns the value of attribute usage_statistics.
Attributes inherited from Base
#request_id, #response, #status_code
Instance Method Summary collapse
- #alexa_gdn ⇒ Object
- #alexa_speed_rating ⇒ Object
- #categories_node_name ⇒ Object
- #content_node_name ⇒ Object
- #contributing_hostnames ⇒ Object
- #contributing_subdomains_node_name ⇒ Object
- #daily_GDN_page_views ⇒ Object
- #domains ⇒ Object
- #geos_hash ⇒ Object
- #geos_sorted ⇒ Object
- #get_median_load_time ⇒ Object
- #get_pvs_per_mil ⇒ Object
- #has_data? ⇒ Boolean
- #init_entity_data(attr_name, data, kclass) ⇒ Object
-
#initialize(response) ⇒ UrlInfo
constructor
A new instance of UrlInfo.
- #not_found? ⇒ Boolean (also: #is_404?)
- #pvs_per_user ⇒ Object
- #pvs_rank ⇒ Object
- #rank_by_country_node_name ⇒ Object
- #rank_page_view ⇒ Object
- #related_links_node_name ⇒ Object
- #related_node_name ⇒ Object
- #setup_data!(response) ⇒ Object
- #speed_percentile ⇒ Object
- #speed_rating ⇒ Object
- #statistic_node_name ⇒ Object
- #traffic_node_name ⇒ Object
Methods inherited from Base
#action_name, #loading_response, #pretty_xml, #relationship_collections, #root_node_name, #success?
Constructor Details
#initialize(response) ⇒ UrlInfo
Returns a new instance of UrlInfo.
9 10 11 12 13 14 15 16 17 |
# File 'lib/awis/models/url_info.rb', line 9 def initialize(response) @usage_statistics = [] @related_links = [] @categories = [] @contributing_subdomains = [] @rank_by_country = [] super(response) end |
Instance Attribute Details
#asin ⇒ Object
Returns the value of attribute asin.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def asin @asin end |
#categories ⇒ Object
Returns the value of attribute categories.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def categories @categories end |
#contact_info ⇒ Object
Returns the value of attribute contact_info.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def contact_info @contact_info end |
#content_data ⇒ Object
Returns the value of attribute content_data.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def content_data @content_data end |
#contributing_subdomains ⇒ Object
Returns the value of attribute contributing_subdomains.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def contributing_subdomains @contributing_subdomains end |
#data_url ⇒ Object
Returns the value of attribute data_url.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def data_url @data_url end |
#rank ⇒ Object
Returns the value of attribute rank.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def rank @rank end |
#rank_by_country ⇒ Object
Returns the value of attribute rank_by_country.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def rank_by_country @rank_by_country end |
#related_links ⇒ Object
Returns the value of attribute related_links.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def @related_links end |
#usage_statistics ⇒ Object
Returns the value of attribute usage_statistics.
6 7 8 |
# File 'lib/awis/models/url_info.rb', line 6 def usage_statistics @usage_statistics end |
Instance Method Details
#alexa_gdn ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/awis/models/url_info.rb', line 285 def alexa_gdn { 250000 => '< 1K', 100000 => '1K - 10K', 50000 => '10K - 100K', 20000 => '100K - 500K', 10000 => '500K - 1M', 5000 => '1M - 2M', 2000 => '2M - 5M', 1000 => '5M - 10M', 500 => '10M - 20M', 150 => '20M - 50M', 30 => '50M - 100M', 0 => '100M+' } end |
#alexa_speed_rating ⇒ Object
261 262 263 264 265 266 267 |
# File 'lib/awis/models/url_info.rb', line 261 def { 2200 => 'POOR ( > 5s)', 1200 => 'AVERAGE ( < 5s)', 0 => 'GOOD ( < 3s)' } end |
#categories_node_name ⇒ Object
176 177 178 |
# File 'lib/awis/models/url_info.rb', line 176 def categories_node_name "#{}/aws:Categories/aws:CategoryData" end |
#content_node_name ⇒ Object
164 165 166 |
# File 'lib/awis/models/url_info.rb', line 164 def content_node_name "#{root_node_name}/aws:ContentData" end |
#contributing_hostnames ⇒ Object
219 220 221 |
# File 'lib/awis/models/url_info.rb', line 219 def contributing_hostnames contributing_subdomains.map(&:data_url).reject { |hostname| hostname == 'OTHER' } end |
#contributing_subdomains_node_name ⇒ Object
188 189 190 |
# File 'lib/awis/models/url_info.rb', line 188 def contributing_subdomains_node_name "#{traffic_node_name}/aws:ContributingSubdomains/aws:ContributingSubdomain" end |
#daily_GDN_page_views ⇒ Object
243 244 245 246 247 248 249 |
# File 'lib/awis/models/url_info.rb', line 243 def daily_GDN_page_views return unless rank alexa_gdn.each do |max_pvs, gdn_range| return gdn_range if rank > max_pvs end end |
#domains ⇒ Object
215 216 217 |
# File 'lib/awis/models/url_info.rb', line 215 def domains content_data.owned_domains.map(&:domain) end |
#geos_hash ⇒ Object
206 207 208 |
# File 'lib/awis/models/url_info.rb', line 206 def geos_hash @geos_hash ||= geos_sorted.reduce({}, :merge) end |
#geos_sorted ⇒ Object
200 201 202 203 204 |
# File 'lib/awis/models/url_info.rb', line 200 def geos_sorted rank_by_country.select { |rbc| !rbc.rank.nil? && !rbc.contribution_page_views.nil? }. sort_by { |rbc| - rbc.contribution_page_views.round }. map { |rbc| { rbc.country_code => rbc.contribution_page_views.round } } end |
#get_median_load_time ⇒ Object
239 240 241 |
# File 'lib/awis/models/url_info.rb', line 239 def get_median_load_time content_data.speed_median_load_time end |
#get_pvs_per_mil ⇒ Object
231 232 233 |
# File 'lib/awis/models/url_info.rb', line 231 def get_pvs_per_mil usage_statistics.first.page_views_per_million_value end |
#has_data? ⇒ Boolean
196 197 198 |
# File 'lib/awis/models/url_info.rb', line 196 def has_data? !@rank.nil? end |
#init_entity_data(attr_name, data, kclass) ⇒ Object
158 159 160 161 162 |
# File 'lib/awis/models/url_info.rb', line 158 def init_entity_data(attr_name, data, kclass) return if data.empty? instance_variable_set("@#{attr_name}", kclass.new(data)) end |
#not_found? ⇒ Boolean Also known as: is_404?
210 211 212 |
# File 'lib/awis/models/url_info.rb', line 210 def not_found? ([content_data.data_url, content_data.site_title] & [404, '404']).size > 0 end |
#pvs_per_user ⇒ Object
223 224 225 |
# File 'lib/awis/models/url_info.rb', line 223 def pvs_per_user usage_statistics.first.page_views_per_user_value end |
#pvs_rank ⇒ Object
227 228 229 |
# File 'lib/awis/models/url_info.rb', line 227 def pvs_rank usage_statistics.first.page_views_rank_value end |
#rank_by_country_node_name ⇒ Object
192 193 194 |
# File 'lib/awis/models/url_info.rb', line 192 def rank_by_country_node_name "#{traffic_node_name}/aws:RankByCountry/aws:Country" end |
#rank_page_view ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/awis/models/url_info.rb', line 269 def rank_page_view { 20000 => '< 1K', 5000 => '1K - 10K', 3000 => '10K - 100K', 1900 => '100K - 500K', 1300 => '500K - 1M', 850 => '2M - 5M', 550 => '5M - 10M', 350 => '10M - 20M', 200 => '20M - 50M', 100 => '50M - 100M', 28 => '100M+' } end |
#related_links_node_name ⇒ Object
172 173 174 |
# File 'lib/awis/models/url_info.rb', line 172 def "#{}/aws:RelatedLinks/aws:RelatedLink" end |
#related_node_name ⇒ Object
168 169 170 |
# File 'lib/awis/models/url_info.rb', line 168 def "#{root_node_name}/aws:Related" end |
#setup_data!(response) ⇒ Object
19 20 21 22 23 24 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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/awis/models/url_info.rb', line 19 def setup_data!(response) content_data = { owned_domains: [] } contact_info = { phone_numbers: [] } statistics = [] = [] category_data = [] rank_by_country = [] contributing_subdomains = [] response.each_node do |node, path| text = node.inner_xml candidate_text = text.delete(',') value = if integer_value?(candidate_text) && node.name != 'aws:Delta' candidate_text.to_i elsif float_value?(candidate_text) candidate_text.to_f elsif text.is_a?(String) && text.empty? nil else text end if node.name == 'aws:RequestId' @request_id ||= value elsif node.name == 'aws:StatusCode' @status_code ||= value elsif node.name == 'aws:DataUrl' && path == "#{traffic_node_name}/aws:DataUrl" @data_url = value elsif node.name == 'aws:Asin' && path == "#{traffic_node_name}/aws:Asin" @asin = value elsif node.name == 'aws:Rank' && path == "#{traffic_node_name}/aws:Rank" @rank = value elsif node.name == 'aws:DataUrl' && path == "#{content_node_name}/aws:DataUrl" content_data[:data_url] = value elsif node.name == 'aws:Title' && path == "#{content_node_name}/aws:SiteData/aws:Title" content_data[:site_title] = value elsif node.name == 'aws:Description' content_data[:site_description] = value elsif node.name == 'aws:MedianLoadTime' content_data[:speed_median_load_time] = value elsif node.name == 'aws:Percentile' content_data[:speed_percentile] = value elsif node.name == 'aws:AdultContent' content_data[:adult_content] = value elsif node.name == 'aws:Locale' content_data[:language_locale] = value elsif node.name == 'aws:LinksInCount' content_data[:links_in_count] = value elsif node.name == 'aws:Domain' && path == "#{content_node_name}/aws:OwnedDomains/aws:OwnedDomain/aws:Domain" content_data[:owned_domains] << { domain: value } elsif node.name == 'aws:Title' && path == "#{content_node_name}/aws:OwnedDomains/aws:OwnedDomain/aws:Title" content_data[:owned_domains] << { title: value } elsif node.name == 'aws:OnlineSince' content_data[:online_since] = value elsif node.name == 'aws:DataUrl' && path == "#{root_node_name}/aws:ContactInfo/aws:DataUrl" contact_info[:data_url] = value elsif node.name == 'aws:OwnerName' contact_info[:owner_name] = value elsif node.name == 'aws:Email' contact_info[:email] = value elsif node.name == 'aws:PhysicalAddress' contact_info[:physical_address] = value elsif node.name == 'aws:CompanyStockTicker' contact_info[:company_stock_ticker] = value elsif node.name == 'aws:PhoneNumber' contact_info[:phone_numbers] << value elsif node.name == 'aws:DataUrl' && path == "#{}/aws:DataUrl" << { data_url: value } elsif node.name == 'aws:NavigableUrl' && path == "#{}/aws:NavigableUrl" << { navigable_url: value } elsif node.name == 'aws:Title' && path == "#{}/aws:Title" << { title: value } elsif node.name == 'aws:Title' && path == "#{categories_node_name}/aws:Title" category_data << { title: value } elsif node.name == 'aws:AbsolutePath' && path == "#{categories_node_name}/aws:AbsolutePath" category_data << { absolute_path: value } elsif node.name == 'aws:Months' && path == "#{statistic_node_name}/aws:TimeRange/aws:Months" statistics << { time_range_months: value } elsif node.name == 'aws:Days' && path == "#{statistic_node_name}/aws:TimeRange/aws:Days" statistics << { time_range_days: value } elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Rank/aws:Value" statistics << { rank_value: value } elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Rank/aws:Delta" statistics << { rank_delta: value } elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Reach/aws:Rank/aws:Value" statistics << { reach_rank_value: value } elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Reach/aws:Rank/aws:Delta" statistics << { reach_rank_delta: value } elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Reach/aws:PerMillion/aws:Value" statistics << { reach_per_million_value: value } elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Reach/aws:PerMillion/aws:Delta" statistics << { reach_per_million_delta: value } elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:PerMillion/aws:Value" statistics << { page_views_per_million_value: value } elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:PerMillion/aws:Delta" statistics << { page_views_per_million_delta: value } elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:Rank/aws:Value" statistics << { page_views_rank_value: value } elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:Rank/aws:Delta" statistics << { page_views_rank_delta: value } elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:PerUser/aws:Value" statistics << { page_views_per_user_value: value } elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:PerUser/aws:Delta" statistics << { page_views_per_user_delta: value } elsif node.name == 'aws:Country' && path == rank_by_country_node_name rank_by_country << { country_code: node.attributes['Code'] } elsif node.name == 'aws:Rank' && path == "#{rank_by_country_node_name}/aws:Rank" rank_by_country << { rank: value } elsif node.name == 'aws:PageViews' && path == "#{rank_by_country_node_name}/aws:Contribution/aws:PageViews" rank_by_country << { contribution_page_views: value } elsif node.name == 'aws:Users' && path == "#{rank_by_country_node_name}/aws:Contribution/aws:Users" rank_by_country << { contribution_users: value } elsif node.name == 'aws:DataUrl' && path == "#{contributing_subdomains_node_name}/aws:DataUrl" contributing_subdomains << { data_url: value } elsif node.name == 'aws:Months' && path == "#{contributing_subdomains_node_name}/aws:TimeRange/aws:Months" contributing_subdomains << { time_range_months: value } elsif node.name == 'aws:Percentage' && path == "#{contributing_subdomains_node_name}/aws:Reach/aws:Percentage" contributing_subdomains << { reach_percentage: value } elsif node.name == 'aws:Percentage' && path == "#{contributing_subdomains_node_name}/aws:PageViews/aws:Percentage" contributing_subdomains << { page_views_percentage: value } elsif node.name == 'aws:PerUser' && path == "#{contributing_subdomains_node_name}/aws:PageViews/aws:PerUser" contributing_subdomains << { page_views_per_user: value } end end init_entity_data('content_data', content_data, ContentData) init_entity_data('contact_info', contact_info, ContactInfo) relationship_collections(@usage_statistics, statistics, 13, UsageStatistic) relationship_collections(@related_links, , 3, RelatedLink) relationship_collections(@categories, category_data, 3, CategoryData) relationship_collections(@rank_by_country, rank_by_country, 4, RankByCountry) relationship_collections(@contributing_subdomains, contributing_subdomains, 5, ContributingSubdomain) end |
#speed_percentile ⇒ Object
235 236 237 |
# File 'lib/awis/models/url_info.rb', line 235 def speed_percentile content_data.speed_percentile end |
#speed_rating ⇒ Object
251 252 253 254 255 256 257 258 259 |
# File 'lib/awis/models/url_info.rb', line 251 def if get_median_load_time .each do |max_load_time, | return if get_median_load_time > max_load_time end end 'AVERAGE ( < 5s)' end |
#statistic_node_name ⇒ Object
184 185 186 |
# File 'lib/awis/models/url_info.rb', line 184 def statistic_node_name "#{traffic_node_name}/aws:UsageStatistics/aws:UsageStatistic" end |
#traffic_node_name ⇒ Object
180 181 182 |
# File 'lib/awis/models/url_info.rb', line 180 def traffic_node_name "#{root_node_name}/aws:TrafficData" end |