Class: Awis::Models::UrlInfo

Inherits:
Base
  • Object
show all
Defined in:
lib/awis/models/url_info.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#request_id, #response, #status_code

Instance Method Summary collapse

Methods inherited from Base

#action_name, #loading_response, #relationship_collections, #root_node_name, #success?

Constructor Details

#initialize(response) ⇒ UrlInfo



6
7
8
9
10
11
12
# File 'lib/awis/models/url_info.rb', line 6

def initialize(response)
  @usage_statistics = []
  @related_links = []
  @categories = []

  setup_data! loading_response(response)
end

Instance Attribute Details

#asinObject

Returns the value of attribute asin.



4
5
6
# File 'lib/awis/models/url_info.rb', line 4

def asin
  @asin
end

#categoriesObject

Returns the value of attribute categories.



4
5
6
# File 'lib/awis/models/url_info.rb', line 4

def categories
  @categories
end

#contact_infoObject

Returns the value of attribute contact_info.



4
5
6
# File 'lib/awis/models/url_info.rb', line 4

def contact_info
  @contact_info
end

#content_dataObject

Returns the value of attribute content_data.



4
5
6
# File 'lib/awis/models/url_info.rb', line 4

def content_data
  @content_data
end

#data_urlObject

Returns the value of attribute data_url.



4
5
6
# File 'lib/awis/models/url_info.rb', line 4

def data_url
  @data_url
end

#rankObject

Returns the value of attribute rank.



4
5
6
# File 'lib/awis/models/url_info.rb', line 4

def rank
  @rank
end

Returns the value of attribute related_links.



4
5
6
# File 'lib/awis/models/url_info.rb', line 4

def related_links
  @related_links
end

#usage_statisticsObject

Returns the value of attribute usage_statistics.



4
5
6
# File 'lib/awis/models/url_info.rb', line 4

def usage_statistics
  @usage_statistics
end

Instance Method Details

#categories_node_nameObject



145
146
147
# File 'lib/awis/models/url_info.rb', line 145

def categories_node_name
  "#{related_node_name}/aws:Categories/aws:CategoryData"
end

#content_node_nameObject



133
134
135
# File 'lib/awis/models/url_info.rb', line 133

def content_node_name
  "#{root_node_name}/aws:ContentData"
end

#init_entity_data(attr_name, data, kclass) ⇒ Object



127
128
129
130
131
# File 'lib/awis/models/url_info.rb', line 127

def init_entity_data(attr_name, data, kclass)
  return if data.empty?

  instance_variable_set("@#{attr_name}", kclass.new(data))
end

#is_404?Boolean



123
124
125
# File 'lib/awis/models/url_info.rb', line 123

def is_404?
  success? && rank == 404
end


141
142
143
# File 'lib/awis/models/url_info.rb', line 141

def related_links_node_name
  "#{related_node_name}/aws:RelatedLinks/aws:RelatedLink"
end


137
138
139
# File 'lib/awis/models/url_info.rb', line 137

def related_node_name
  "#{root_node_name}/aws:Related"
end

#setup_data!(response) ⇒ Object



14
15
16
17
18
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
# File 'lib/awis/models/url_info.rb', line 14

def setup_data!(response)
  content_data = {
    owned_domains: []
  }
  contact_info = {
    phone_numbers: []
  }
  statistics = []
  related_related_links = []
  category_data = []

  response.each_node do |node, path|
    text = node.inner_xml
    text = text.to_i if text.to_i.to_s === text && node.name != 'aws:Delta'
    text = nil if (text.class == String && text.empty?)

    if node.name == 'aws:RequestId'
      @request_id ||= text
    elsif node.name == 'aws:StatusCode'
      @status_code ||= text
    elsif node.name == 'aws:DataUrl' && path == "#{traffic_node_name}/aws:DataUrl"
      @data_url = text
    elsif node.name == 'aws:Asin' && path == "#{traffic_node_name}/aws:Asin"
      @asin = text
    elsif node.name == 'aws:Rank' && path == "#{traffic_node_name}/aws:Rank"
      @rank = text
    elsif node.name == 'aws:DataUrl' && path == "#{content_node_name}/aws:DataUrl"
      content_data[:data_url] = text
    elsif node.name == 'aws:Title' && path == "#{content_node_name}/aws:SiteData/aws:Title"
      content_data[:site_title] = text
    elsif node.name == 'aws:Description'
      content_data[:site_description] = text
    elsif node.name == 'aws:MedianLoadTime'
      content_data[:speed_median_load_time] = text
    elsif node.name == 'aws:Percentile'
      content_data[:speed_percentile] = text
    elsif node.name == 'aws:AdultContent'
      content_data[:adult_content] = text
    elsif node.name == 'aws:Locale'
      content_data[:language_locale] = text
    elsif node.name == 'aws:LinksInCount'
      content_data[:links_in_count] = text
    elsif node.name == 'aws:Domain' && path == "#{content_node_name}/aws:OwnedDomains/aws:OwnedDomain/aws:Domain"
      content_data[:owned_domains] << { domain: text }
    elsif node.name == 'aws:Title' && path == "#{content_node_name}/aws:OwnedDomains/aws:OwnedDomain/aws:Title"
      content_data[:owned_domains] << { title: text }
    elsif node.name == 'aws:OnlineSince'
      content_data[:online_since] = text
    elsif node.name == 'aws:DataUrl' && path == "#{root_node_name}/aws:ContactInfo/aws:DataUrl"
      contact_info[:data_url] = text
    elsif node.name == 'aws:OwnerName'
      contact_info[:owner_name] = text
    elsif node.name == 'aws:Email'
      contact_info[:email] = text
    elsif node.name == 'aws:PhysicalAddress'
      contact_info[:physical_address] = text
    elsif node.name == 'aws:CompanyStockTicker'
      contact_info[:company_stock_ticker] = text
    elsif node.name == 'aws:PhoneNumber'
      contact_info[:phone_numbers] << text
    elsif node.name == 'aws:DataUrl' && path == "#{related_links_node_name}/aws:DataUrl"
      related_related_links << { data_url: text }
    elsif node.name == 'aws:NavigableUrl' && path == "#{related_links_node_name}/aws:NavigableUrl"
      related_related_links << { navigable_url: text }
    elsif node.name == 'aws:Title' &&  path == "#{related_links_node_name}/aws:Title"
      related_related_links << { title: text }
    elsif node.name == 'aws:Title' && path == "#{categories_node_name}/aws:Title"
      category_data << { title: text }
    elsif node.name == 'aws:AbsolutePath' &&  path == "#{categories_node_name}/aws:AbsolutePath"
      category_data << { absolute_path: text }
    elsif node.name == 'aws:Months' && path == "#{statistic_node_name}/aws:TimeRange/aws:Months"
      statistics << { time_range_months: text }
    elsif node.name == 'aws:Days' && path == "#{statistic_node_name}/aws:TimeRange/aws:Days"
      statistics << { time_range_days: text }
    elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Rank/aws:Value"
      statistics << { rank_value: text }
    elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Rank/aws:Delta"
      statistics << { rank_delta: text }
    elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Reach/aws:Rank/aws:Value"
      statistics << { reach_rank_value: text }
    elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Reach/aws:Rank/aws:Delta"
      statistics << { reach_rank_delta: text }
    elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:Reach/aws:PerMillion/aws:Value"
      statistics << { reach_per_million_value: text }
    elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:Reach/aws:PerMillion/aws:Delta"
      statistics << { reach_per_million_delta: text }
    elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:PerMillion/aws:Value"
      statistics << { reach_page_views_per_million_value: text }
    elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:PerMillion/aws:Delta"
      statistics << { reach_page_views_per_million_delta: text }
    elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:Rank/aws:Value"
      statistics << { reach_page_views_rank_value: text }
    elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:Rank/aws:Delta"
      statistics << { reach_page_views_rank_delta: text }
    elsif node.name == 'aws:Value' && path == "#{statistic_node_name}/aws:PageViews/aws:PerUser/aws:Value"
      statistics << { reach_page_views_per_user_value: text }
    elsif node.name == 'aws:Delta' && path == "#{statistic_node_name}/aws:PageViews/aws:PerUser/aws:Delta"
      statistics << { reach_page_views_per_user_delta: text }
    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, related_related_links, 3, RelatedLink)
  relationship_collections(@categories, category_data, 3, CategoryData)
end

#statistic_node_nameObject



153
154
155
# File 'lib/awis/models/url_info.rb', line 153

def statistic_node_name
  "#{traffic_node_name}/aws:UsageStatistics/aws:UsageStatistic"
end

#traffic_node_nameObject



149
150
151
# File 'lib/awis/models/url_info.rb', line 149

def traffic_node_name
  "#{root_node_name}/aws:TrafficData"
end