Class: BOTR::ChannelView

Inherits:
Object
  • Object
show all
Defined in:
lib/botr/channels/channel_view.rb

Overview

The BOTR::ChannelView class contains calls for requesting channel views statistics.

A channel view is counted every time:

The RSS feed of that channel is requested from the content server. A player from our content server containing a channel is embedded in a webpage.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Authentication

#signature

Methods included from API

#api_call_class, #api_format, #api_key, #api_nonce, #api_protocol, #api_secret_key, #api_server, #api_timestamp, #api_url, #api_version, #progress_url, #upload_address, #upload_key, #upload_protocol, #upload_token, #upload_url

Methods included from HTTP

#client, #delete_request, #get_request, #post_request, #put_request

Constructor Details

#initialize(params = {}) ⇒ ChannelView

Returns a new instance of ChannelView.



134
135
136
137
138
139
140
# File 'lib/botr/channels/channel_view.rb', line 134

def initialize(params = {})
	params.each do |key, val|
		param = "@#{key.to_s}"
		next unless methods.include? key.to_sym
		instance_variable_set(param, val)
	end		
end

Class Attribute Details

.last_statusObject (readonly)

Returns the value of attribute last_status.



15
16
17
# File 'lib/botr/channels/channel_view.rb', line 15

def last_status
  @last_status
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def date
  @date
end

#daysObject (readonly)

Returns the value of attribute days.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def days
  @days
end

#keyObject (readonly)

Returns the value of attribute key.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def key
  @key
end

#last_statusObject (readonly)

Returns the value of attribute last_status.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def last_status
  @last_status
end

#numberObject (readonly)

Returns the value of attribute number.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def number
  @number
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def timestamp
  @timestamp
end

#titleObject (readonly)

Returns the value of attribute title.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def title
  @title
end

#totalObject (readonly)

Returns the value of attribute total.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def total
  @total
end

#viewsObject (readonly)

Returns the value of attribute views.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def views
  @views
end

#yearObject (readonly)

Returns the value of attribute year.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def year
  @year
end

#yearsObject (readonly)

Returns the value of attribute years.



131
132
133
# File 'lib/botr/channels/channel_view.rb', line 131

def years
  @years
end

Class Method Details

.allObject



94
95
96
# File 'lib/botr/channels/channel_view.rb', line 94

def all
	list({})
end

.list(**options) ⇒ Array

Returns a list of objects with the statistics of the all channels matching the given criteria.

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • aggregate (String)

    specifies if returned channel views statistics should be aggregate: true or false

  • group_days (String)

    specifies if returned channel views statistics should be grouped by year and month

  • include_empty_days (String)

    specifies if channel views statistics should include days for which there is no statistics available: true or false

Returns:

  • (Array)

    a list of objects with the statistics of the all channels matching the given criteria



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/botr/channels/channel_view.rb', line 81

def list(**options)
	json = get_request(options.merge(:method => 'list'))
	res = JSON.parse(json.body)
	
	if json.status == 200
		results = process_list_response(res)
	else
		raise "HTTP Error #{json.status}: #{json.body}"
	end

	return results
end

.show(channel_key, **options) ⇒ BOTR::ChannelView Also known as: find

information

Parameters:

  • channel_key (String)

    key of the channel for which to show

  • options (Hash)

    channel views parameters

Options Hash (**options):

  • start_date (Integer)

    Unix timestamp of date from which channel views statistics should be start

  • end_date (Integer)

    Unix timestamp of date on which channel views statistics should be end

  • aggregate (String)

    specifies if returned channel views statistics should be aggregate: true or false

  • group_days (String)

    specifies if returned channel views statistics should be grouped by year and month

  • include_empty_days (String)

    specifies if channel views statistics should include days for which there is no statistics available: true or false

Returns:

  • (BOTR::ChannelView)

    a new object with the view statistics of the channel referenced by the channel key



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/botr/channels/channel_view.rb', line 37

def show(channel_key, **options)
	json = get_request(options.merge(:method => 'show',
					    			 :channel_key => channel_key))
	res = JSON.parse(json.body)

	if json.status == 200
		params = process_show_response(res)
	else
		raise "HTTP Error #{json.status}: #{json.body}"
	end

	return new(params)
end