Class: BOTR::Channel

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

Overview

The BOTR::Channel class contains calls for creating new channels, searching for channels, managing the channel properties (title, description etc.) and deleting channels.

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 = {}) ⇒ Channel

Returns a new instance of Channel.



95
96
97
98
99
100
101
# File 'lib/botr/channels/channel.rb', line 95

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.



10
11
12
# File 'lib/botr/channels/channel.rb', line 10

def last_status
  @last_status
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def author
  @author
end

#descriptionObject (readonly)

Returns the value of attribute description.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def description
  @description
end

#keyObject (readonly)

Returns the value of attribute key.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def key
  @key
end

#last_statusObject (readonly)

Returns the value of attribute last_status.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def last_status
  @last_status
end

Returns the value of attribute link.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def link
  @link
end

#sort_orderObject (readonly)

Returns the value of attribute sort_order.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def sort_order
  @sort_order
end

#tagsObject (readonly)

Returns the value of attribute tags.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def tags
  @tags
end

#tags_modeObject (readonly)

Returns the value of attribute tags_mode.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def tags_mode
  @tags_mode
end

#titleObject (readonly)

Returns the value of attribute title.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def type
  @type
end

#videosObject (readonly)

Returns the value of attribute videos.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def videos
  @videos
end

#viewsObject (readonly)

Returns the value of attribute views.



92
93
94
# File 'lib/botr/channels/channel.rb', line 92

def views
  @views
end

Class Method Details

.allObject



69
70
71
# File 'lib/botr/channels/channel.rb', line 69

def all
	list({})
end

.list(**options) ⇒ BOTR::Channel

Returns a new object with the properties of the channel referenced by the channel key.

Returns:

  • (BOTR::Channel)

    a new object with the properties of the channel referenced by the channel key



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/botr/channels/channel.rb', line 56

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) ⇒ BOTR::Channel Also known as: find

information

Parameters:

  • channel_key (String)

    key of the channel for which to show

Returns:

  • (BOTR::Channel)

    a new object with the properties of the channel referenced by the channel key



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/botr/channels/channel.rb', line 19

def show(channel_key)
	json = get_request({: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

Instance Method Details

#create(type, **options) ⇒ BOTR::Channel

Create a new (dynamic or manual) channel.

information

Parameters:

  • type (String)

    type of the channel: "dynamic" or "manual"

  • options (Hash)

    channel parameters

Options Hash (**options):

  • title (String)

    title of the channel

  • description (String)

    description of the channel

  • link (String)

    user defined URL

  • author (String)

    author of the channel

Returns:

  • (BOTR::Channel)

    this object with the properties specified in the options hash



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/botr/channels/channel.rb', line 116

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

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

	return self
end

#deleteBOTR::Channel

Delete a channel.

Returns:



172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/botr/channels/channel.rb', line 172

def delete
	json = delete_request({:channel_key => @key})
	res = JSON.parse(json.body)

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

	return self
end

#update(**options) ⇒ BOTR::Channel

Configure or update the properties of a channel.

Parameters:

  • options (Hash)

    channel parameters

Options Hash (**options):

  • channel_key (String)

    key of the channel which should be configured or updated

  • title (String)

    title of the channel

  • description (String)

    description of the channel

  • link (String)

    user defined URL

  • author (String)

    author of the channel

  • tags (String)

    tags of the channel; restricts the inclusion of videos to the channel to the videos tagged with the specified tags

  • tags_mode (String)

    tags search mode for the dynamic channel: "all" -- a video will only be added if it has all tags specified in the tags parameter or "any" -- a video will be added if it has at least one tag specified in the tags parameter

  • sort_order (String)

    specifies sorting order of the videos in a dynamic channel: "date-asc", "date-desc", "title-asc", "title-desc", "duration-asc", "duration-desc", "views-asc" or "views-desc"

  • videos_max (Integer)

    maximum number of videos to allow in a dynamic channel; default is 10

Returns:

  • (BOTR::Channel)

    this object with the properties specified in the options hash



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/botr/channels/channel.rb', line 156

def update(**options)
	json = put_request(options.merge(:channel_key => @key))
	res = JSON.parse(json.body)

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

	return self
end