Class: FormatBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/net_flix/builders/format_builder.rb

Class Method Summary collapse

Class Method Details

.from_movie(movie) ⇒ Object



13
14
15
16
17
18
# File 'lib/net_flix/builders/format_builder.rb', line 13

def from_movie(movie)

  	    formats = movie.xpath("//title_index_item/delivery_formats/availability[not(@available_from) or @available_from < #{Time.now.to_i}]/category[@scheme='http://api.netflix.com/categories/title_formats']").map{|f| f['term'] }
 formats + request_cast_for(movie)

end

.from_xml(xml) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/net_flix/builders/format_builder.rb', line 5

def from_xml(xml)

  Nokogiri.XML(xml).xpath("//delivery_formats/availability[@available_from < #{Time.now.to_i} or not(@available_from)]/category").map do |format_data|

    format_data['term']
  end
end

.request_cast_for(movie) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/net_flix/builders/format_builder.rb', line 20

def request_cast_for(movie)
  cast_link_node = movie.search('link[@rel="http://schemas.netflix.com/catalog/titles/format_availability"]').first
  cast_link = cast_link_node['href'] if cast_link_node

  if cast_link.nil?
    []
  else
    request = NetFlix::Request.new(url: cast_link)
    response = request.send
    from_xml(response)
  end
end