| Class | TruveoResponse |
| In: |
lib/truveo.rb
|
| Parent: | Object |
TruveoResponse objects are returned from Truveo methods get_videos(), get_related_categories(), get_related_channels(), get_related_tags(), and get_related_users(). For example, the following line of code creates a new TruveoResponse object as the result of a call to Truveo.get_videos().
res = t.get_videos("funny")
The video_set attribute is an array of the videos returned by the TruveoResponse.get_videos call.
res.video_set.each{|v| ... } # iterates through the videos, each video is a hash of the metadata for that video
The channel_set is a hash of the channels that match the query. The key is the name of the channel. The value is the count of the number of videos in that channel that match the query.
res.channel_set.each_pair{|key,val| ... }
The tag_set, cateogry_set, and user_set members are similar to the channel_set member described above.
The TruveoResponse also implements the each method which supports iteration through the all the videos that can be returned by the get_videos() query that created the TruveoResponse, up to 1,000 videos.
res = t.get_videos("funny")
res.each{|v| puts v['title']}
| category_results_returned | [RW] |
String indicating the number of category results returned
res.category_set.length == res.cagegory_results_returned.to_i # <-- true |
| category_set | [RW] |
Hash of categories and their related counts for your query
res.category_set # <-- hash of the matching categories |
| channel_results_returned | [RW] |
String indicating the number of channel results returned
res.channel_set.length == res.channel_results_returned.to_i # <-- true |
| channel_set | [RW] |
Hash of channels and their related counts for your query
res.channel_set # <-- hash of the matching channels |
| error_code | [RW] | String indicating the integer code for the error if one occured |
| error_text | [RW] | String containing text of error code if one occured. |
| first_result_position | [RW] |
String representing the position of the first Video in the entire set of
matching videos.
res.first_result_position |
| method | [RW] |
String containing method, i.e., ‘truveo.videos.getVideos‘
res.method |
| query | [RW] |
String containing the query used to create this response object
res.query |
| query_suggestion | [RW] |
String containing the query suggestion, if any
res.query_suggestion |
| rss_url | [RW] |
String containing the URL which will return an RSS feed for the set of
videos returned in response to the submitted query.
res.rss_url |
| sortby | [RW] |
String containging the sorter used to create this response
res.sortby |
| tag_results_returned | [RW] |
String indicating the number of tag results returned
res.tag_set.length == res.tag_results_returned.to_i # <-- true |
| tag_set | [RW] |
Hash of tags and their related counts for your query
res.tag_set # <-- hash of the matching tags |
| total_results_available | [RW] |
String indicating the number of total results that matched the query
res.total_results_available |
| total_results_returned | [RW] |
String indicating the number of resutls returned in this result set. For
get_videos() the following should be true: video_set.length ==
total_resutls_returned.to_i)
res.total_results_returned |
| user_results_returned | [RW] |
String indicating the number of user results returned
res.user_set.length == res.user_results_returned.to_i # <-- true |
| user_set | [RW] |
Hash of users and their related counts for your query
res.user_set # <-- hash of the matching users |
| video_set | [RW] |
Array of videos returned by the query.
res.video_set # <-- array of the videos that matched query |
| video_set_title | [RW] |
String containing a human-readable title for the set of videos returned in
response to the submitted request. For example, this field would return a
string such as "Most popular ‘madonna’ videos in Music on
MTV" for the query ‘madonna category:Music channel:MTV
sort:mostPopular’.
res.video_set_title |
Iterate through all the videos in the response. Each video is a hash where the key is the metadata field, like title, and the value is the actual metadata. The videos are returned in whatever order was specified by the sorter, if any, used in the query that created the TruveoResponse object.
The following goes through all the videos that match the query and prints the title. If more than one thousand videos match the query, the each method will only iterate through the first thousand.
# create a Truveo object with my app id (apply for a free app id at http://developer.truveo.com/)
t = Truveo.new("appid")
res = t.get_videos("funny")
# print lots of titles
res.each{|vid| puts vid['title']}
Note that the each method will invoke another get_videos() method behind the scenes. These calls will count against your daily limit. This means iterating through a thousand results using each will result in 100 calls to get_videos() by default.