Class: LatestTomatoes::Movies

Inherits:
Object
  • Object
show all
Defined in:
lib/latest_tomatoes_cli_gem/movies.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#actorsObject

Returns the value of attribute actors.



2
3
4
# File 'lib/latest_tomatoes_cli_gem/movies.rb', line 2

def actors
  @actors
end

#mpaaRatingObject

Returns the value of attribute mpaaRating.



2
3
4
# File 'lib/latest_tomatoes_cli_gem/movies.rb', line 2

def mpaaRating
  @mpaaRating
end

#synopsisObject

Returns the value of attribute synopsis.



2
3
4
# File 'lib/latest_tomatoes_cli_gem/movies.rb', line 2

def synopsis
  @synopsis
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/latest_tomatoes_cli_gem/movies.rb', line 2

def title
  @title
end

#tomatoScoreObject

Returns the value of attribute tomatoScore.



2
3
4
# File 'lib/latest_tomatoes_cli_gem/movies.rb', line 2

def tomatoScore
  @tomatoScore
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/latest_tomatoes_cli_gem/movies.rb', line 2

def url
  @url
end

Class Method Details

.latestObject



4
5
6
# File 'lib/latest_tomatoes_cli_gem/movies.rb', line 4

def self.latest
  self.scrape_movies
end

.scrape_moviesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/latest_tomatoes_cli_gem/movies.rb', line 8

def self.scrape_movies
  movies = []
  doc = Nokogiri::HTML(open("http://d3biamo577v4eu.cloudfront.net/api/private/v1.0/m/list/find?page=1&limit=30&type=dvd-new-releases&services=amazon%3Bamazon_prime%3Bflixster%3Bhbo_go%3Bitunes%3Bnetflix_iw%3Bvudu&sortBy=release"))
  jsonstring = doc.search("p").text # gets json string from main html element
  x=JSON.parse(jsonstring) #parsed array/hash of movie data
  x["results"].each do |movie|
       
     movies << {

      :title => movie["title"],
      :tomatoScore =>  movie["tomatoScore"], 
      :actors =>  movie["actors"], 
      :mpaaRating =>  movie["mpaaRating"], 
      :synopsis =>  movie["synopsis"], 
      :url =>  movie["url"]

     }
   
  end

  movies

end