Class: Awis::Models::TrafficHistory

Inherits:
Base
  • Object
show all
Defined in:
lib/awis/models/traffic_history.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, #pretty_xml, #relationship_collections, #root_node_name, #success?

Constructor Details

#initialize(response) ⇒ TrafficHistory

Returns a new instance of TrafficHistory.



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

def initialize(response)
  @historical_data = []

  super(response)
end

Instance Attribute Details

#historical_dataObject

Returns the value of attribute historical_data.



6
7
8
# File 'lib/awis/models/traffic_history.rb', line 6

def historical_data
  @historical_data
end

#rangeObject

Returns the value of attribute range.



6
7
8
# File 'lib/awis/models/traffic_history.rb', line 6

def range
  @range
end

#siteObject

Returns the value of attribute site.



6
7
8
# File 'lib/awis/models/traffic_history.rb', line 6

def site
  @site
end

#startObject

Returns the value of attribute start.



6
7
8
# File 'lib/awis/models/traffic_history.rb', line 6

def start
  @start
end

Instance Method Details

#base_node_nameObject

rubocop:enable Metrics/AbcSize rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity



54
55
56
# File 'lib/awis/models/traffic_history.rb', line 54

def base_node_name
  "#{root_node_name}/aws:TrafficHistory/aws:HistoricalData/aws:Data"
end

#setup_data!(response) ⇒ Object

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity



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
# File 'lib/awis/models/traffic_history.rb', line 17

def setup_data!(response)
  datas = []

  response.each_node do |node, path|
    text = node.inner_xml
    text = text.to_i if text.to_i.to_s == text
    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:Range'
      @range ||= text
    elsif node.name == 'aws:Site'
      @site ||= text
    elsif node.name == 'aws:Start'
      @start ||= text
    elsif node.name == 'aws:Date' && path == "#{base_node_name}/aws:Date"
      datas << { date: text }
    elsif node.name == 'aws:PerMillion' && path == "#{base_node_name}/aws:PageViews/aws:PerMillion"
      datas << { page_views_per_million: text }
    elsif node.name == 'aws:PerUser' && path == "#{base_node_name}/aws:PageViews/aws:PerUser"
      datas << { page_views_per_user: text }
    elsif node.name == 'aws:Rank' && path == "#{base_node_name}/aws:Rank"
      datas << { rank: text }
    elsif node.name == 'aws:PerMillion' && path == "#{base_node_name}/aws:Reach/aws:PerMillion"
      datas << { reach_per_million: text }
    end
  end

  relationship_collections(@historical_data, datas, 5, HistoricalData)
end