Class: ActorBuilder

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

Class Method Summary collapse

Class Method Details

.from_movie(movie) ⇒ Object



11
12
13
14
15
# File 'lib/net_flix/builders/actor_builder.rb', line 11

def from_movie(movie)
  actors = movie.search('link[@rel="http://schemas.netflix.com/catalog/person.actor"]').map{|f| f['title'] }
  
  actors + request_cast_for(movie)
end

.from_xml(xml) ⇒ Object



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

def from_xml(xml)
  Nokogiri.XML(xml).xpath('//people/person/name').map do |actor_data|
    actor_data.content
  end
end

.request_cast_for(movie) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/net_flix/builders/actor_builder.rb', line 17

def request_cast_for(movie)
  cast_link_node = movie.search('link[@rel="http://schemas.netflix.com/catalog/people.cast"]').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