Class: Netflix::Queue
- Inherits:
-
JsonResource
- Object
- JsonResource
- Netflix::Queue
- Defined in:
- lib/netflix/queue.rb
Constant Summary collapse
- TYPE_DISC =
"disc"
- TYPE_INSTANT =
"instant"
- MAX_RESULTS =
500
Instance Method Summary collapse
-
#add(title_ref, position = nil) ⇒ Object
def queue_items queue_items = [queue_item].flatten queue_items.map {|queue_item| Disc.new(queue_item)} end.
- #discs ⇒ Object
-
#initialize(oauth_access_token, user_id, type = TYPE_DISC) ⇒ Queue
constructor
A new instance of Queue.
- #refresh ⇒ Object
- #remove(position) ⇒ Object
- #remove_by_title_ref(title_ref) ⇒ Object
Methods inherited from JsonResource
Constructor Details
#initialize(oauth_access_token, user_id, type = TYPE_DISC) ⇒ Queue
Returns a new instance of Queue.
11 12 13 14 15 16 |
# File 'lib/netflix/queue.rb', line 11 def initialize(oauth_access_token, user_id, type=TYPE_DISC) @oauth_access_token = oauth_access_token @user_id = user_id @type = type super(retrieve) end |
Instance Method Details
#add(title_ref, position = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/netflix/queue.rb', line 23 def add(title_ref, position=nil) response = @oauth_access_token.post "/users/#{@user_id}/queues/#{@type}?output=json", {:etag => etag, :title_ref => title_ref, :position=> position} #@map = retrieve #netflix is wacky. GET after an add can be STALE. ughg #so recreate the contents programattically instead response_obj = JSON.parse(response.body) new_queue_item = response_obj["status"]["resources_created"]["queue_item"] new_etag = response_obj["status"]["etag"] repopulate(new_queue_item, new_etag) self end |
#discs ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/netflix/queue.rb', line 50 def discs if queue_item queue_items = [queue_item].flatten queue_items.map {|queue_item| Disc.new(queue_item)} else [] end end |
#refresh ⇒ Object
59 60 61 62 |
# File 'lib/netflix/queue.rb', line 59 def refresh @map = retrieve(etag) self end |
#remove(position) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/netflix/queue.rb', line 35 def remove(position) id = discs[position-1].id #response = @oauth_access_token.delete "/users/#{@user_id}/queues/#{@type}/available/#{position}?output=json" , {'etag' => etag} response = @oauth_access_token.delete "#{id}?output=json" @map = retrieve self end |
#remove_by_title_ref(title_ref) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/netflix/queue.rb', line 43 def remove_by_title_ref(title_ref) disc = discs.find {|disc| disc =~ /\/#{title_ref}\//} response = @oauth_access_token.delete "#{disc.id}?output=json" @map = retrieve self end |