Class: Episodic::Platform::Item
- Inherits:
-
Object
- Object
- Episodic::Platform::Item
- Defined in:
- lib/episodic/platform/query_methods.rb
Overview
Base class for parsed items from a query response.
Direct Known Subclasses
CustomFieldItem, DownloadItem, EpisodeItem, EpisodePlaylistItem, PlayerItem, PlaylistEpisodeItem, PlaylistItem, ShowItem, ThumbnailItem
Instance Method Summary collapse
-
#exists? ⇒ Boolean
When requesting specific items in a query it may be the case that the item specified could not be found.
-
#id ⇒ Object
Explcitly declare to avoid
warning: Object#id will be deprecated; use Object#object_id
. -
#initialize(item) ⇒ Item
constructor
Constructor.
-
#method_missing(method_sym, *arguments, &block) ⇒ Object
Overridden to pull properties from the item.
-
#players ⇒ Object
Gets the list of players for this item.
-
#respond_to?(symbol, include_private = false) ⇒ Boolean
Always return
true
. -
#thumbnails ⇒ Object
Gets the list of thumbnails for this item.
Constructor Details
#initialize(item) ⇒ Item
Constructor
Parameters
- item<Hash>
-
The parsed item in the response. This may be a show, episode or playlist item.
315 316 317 318 |
# File 'lib/episodic/platform/query_methods.rb', line 315 def initialize(item) super() @item = item end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
Overridden to pull properties from the item.
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/episodic/platform/query_methods.rb', line 380 def method_missing(method_sym, *arguments, &block) method_name = method_sym.to_s value = @item[method_name] # Dates are always in UTC if (value && date_fields.include?(method_sym)) return value.empty? ? nil : Time.parse("#{value} +0000") elsif (value && boolean_fields.include?(method_sym)) return @item[method_sym.to_s] == "true" elsif (value && integer_fields.include?(method_sym)) return value.empty? ? nil : value.to_i end return value && value.empty? ? nil : value end |
Instance Method Details
#exists? ⇒ Boolean
When requesting specific items in a query it may be the case that the item specified could not be found. In this case the XML returned looks something like the following for the item:
<id>adfadsfasdf</id>
<error>
<code>6</code>
<message>Show not found</message>
</error>
Therefore, this method allows the caller to check if the item actually exists before trying to pull out other properties that will result in an exception. You really only need to use this method when you make a query request with IDs specified.
Returns
- Boolean
-
true
if the item was found and requests for other attributes will succeed.
349 350 351 |
# File 'lib/episodic/platform/query_methods.rb', line 349 def exists? return @item["error"].nil? end |
#id ⇒ Object
Explcitly declare to avoid warning: Object#id will be deprecated; use Object#object_id
.
Parameters
- String
-
The id of the item.
327 328 329 |
# File 'lib/episodic/platform/query_methods.rb', line 327 def id return @item["id"] end |
#players ⇒ Object
Gets the list of players for this item.
Returns
- Array
-
An array of
Episodic::Platform::PlayerItem
objects.
372 373 374 375 |
# File 'lib/episodic/platform/query_methods.rb', line 372 def players @players ||= nested_items("players", "player", PlayerItem) return @players end |
#respond_to?(symbol, include_private = false) ⇒ Boolean
Always return true
.
400 401 402 |
# File 'lib/episodic/platform/query_methods.rb', line 400 def respond_to?(symbol, include_private = false) return true end |
#thumbnails ⇒ Object
Gets the list of thumbnails for this item.
Returns
- Array
-
An array of
Episodic::Platform::ThumbnailItem
objects.
360 361 362 363 |
# File 'lib/episodic/platform/query_methods.rb', line 360 def thumbnails @thumbnails ||= nested_items("thumbnails", "thumbnail", ThumbnailItem) return @thumbnails end |