movlog 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1994033597fd6c1f1be9b75f998939f88a0b0156
4
- data.tar.gz: c4e7cda4def3d1149f553af8bc7937037bb06a48
3
+ metadata.gz: 88e2f1c152861fc072c2866f74efd96334a3bf1f
4
+ data.tar.gz: 07d881d6457b555ee1dbdf3fd928c4f749a30029
5
5
  SHA512:
6
- metadata.gz: 944b3e8dbf997bb1a389e713bd787d9e0cdfa8ab72719a95c857980af08a8d16919ce16a12e8cda09de1a7331dd101b999fd3c0c2648291c3ce4a4b2336171ce
7
- data.tar.gz: b1b72d62056e9100bcd56fe8cbe2ba0211729dc6e9bdfdca1b465713a0f3ed6bc3d83b5232d25ca5c488d9009f5286ebda7034562832aef45fbfd73997ad7722
6
+ metadata.gz: 8e1f322f41da7fe17eb18c0ba026b0b8cf8741871a8b05fa97dd8d688c60698a371ae63359acc2539e5e79a6e95df830e262d16990ede66307377d05ef604dea
7
+ data.tar.gz: c2a7ed53192338ac5173cdea886babcfb7ffdd8d282e776b607bddca9658669cbe2a1d9b59a701e3005a29e70230004dbe3664a1bfd1dc883c781a551ce10669
data/lib/movlog/movie.rb CHANGED
@@ -4,27 +4,44 @@ require_relative 'omdb_api'
4
4
  module Movlog
5
5
  # Movie info
6
6
  class Movie
7
- attr_reader :imdb_id, :title, :year, :actors, :poster, :plot, :location
7
+ attr_reader :imdb_id, :type, :title, :year, :poster
8
+ attr_reader :rating, :plot, :runtime
9
+ attr_reader :awards, :director, :actors
10
+ attr_reader :country, :language
8
11
  attr_reader :response
9
-
12
+ attr_reader :location
13
+
10
14
  def initialize(data:)
11
- @imdb_id = data['imdbID']
12
- @title = data['Title']
13
- @year = data['Year']
14
- @actors = data['Actors']
15
- @poster = data['Poster']
16
- @plot = data['Plot']
17
- @response = data['Response']
15
+ @imdb_id = data[:imdb_id]
16
+ @title = data[:title]
17
+ @year = data[:year]
18
+ @type = data[:type]
19
+ @poster = data[:poster]
18
20
  end
19
21
 
20
- def self.find(t:)
21
- movie_data = OmdbApi.movie_info(t)
22
- new(data: movie_data)
22
+ def self.find(data)
23
+ new(data: data)
23
24
  end
24
25
 
25
26
  def get_location
26
27
  return @location if @location
27
28
  @location = OmdbApi.location(@imdb_id)
28
29
  end
30
+
31
+ def get_details
32
+ movie_details = OmdbApi.movie_info(t)
33
+ parse_details(details: movie_details)
34
+ end
35
+
36
+ def parse_details(details:)
37
+ @rating = details['imdbRating']
38
+ @plot = details['Plot']
39
+ @runtime = details['Runtime']
40
+ @awards = details['Awards']
41
+ @director = details['Director']
42
+ @actors = details['Actors']
43
+ @country = details['Country']
44
+ @language = details['Language']
45
+ end
29
46
  end
30
47
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'omdb_api'
3
+
4
+ module Movlog
5
+ # Movies search
6
+ class Movies
7
+ attr_reader :movies
8
+ attr_reader :num
9
+ attr_reader :response
10
+
11
+ def initialize(data:)
12
+ @movies = parse_movie(data['Search'])
13
+ @num = data['totalResults']
14
+ @response = data['Response']
15
+ end
16
+
17
+ def self.find(s:)
18
+ search_result = OmdbApi.search_movie(s)
19
+ new(data: search_result)
20
+ end
21
+
22
+ def parse_movie(result)
23
+ result.map do |movie|
24
+ Movie.find(imdb_id: movie['imdbID'], title: movie['Title'],
25
+ year: movie['Year'], poster: movie['Poster'], type: movie['Type']
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
@@ -20,25 +20,31 @@ module Movlog
20
20
  t: t,
21
21
  y: '',
22
22
  plot: 'short',
23
+ type: 'movie',
23
24
  r: 'json'
24
25
  }
25
26
  )
26
- JSON.load(movie_response.to_s)
27
+ JSON.parse(movie_response.to_s)
28
+ end
29
+
30
+ def self.search_movie(s)
31
+ movie_response = HTTP.get(
32
+ OMDB_URL,
33
+ params: {
34
+ s: s,
35
+ type: 'movie',
36
+ r: 'json'
37
+ }
38
+ )
39
+ JSON.parse(movie_response.to_s)
27
40
  end
28
41
 
29
42
  def self.location(movie_id)
30
-
31
43
  page_url = "http://www.imdb.com/title/#{movie_id}/locations?ref_=tt_dt_dt"
32
-
33
- # Fetch and parse HTML document
34
44
  location_arr = []
35
-
36
45
  doc = Nokogiri::HTML(open(page_url))
37
-
38
46
  doc.search('//div[@class="soda sodavote odd"]/dt/a').each { |link| location_arr << link.content}
39
-
40
47
  doc.search('//div[@class="soda sodavote even"]/dt/a').each { |link| location_arr << link.content}
41
-
42
48
  location_arr.to_json
43
49
  end
44
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Movlog
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  end
@@ -1873,4 +1873,154 @@ http_interactions:
1873
1873
  KCJiZSIpOwogICAgfQo8L3NjcmlwdD4KCiAgICA8L2JvZHk+CjwvaHRtbD4K
1874
1874
  http_version:
1875
1875
  recorded_at: Thu, 03 Nov 2016 11:32:43 GMT
1876
+ - request:
1877
+ method: get
1878
+ uri: http://www.omdbapi.com/?r=json&s=hobbit&type=movie
1879
+ body:
1880
+ encoding: US-ASCII
1881
+ string: ''
1882
+ headers:
1883
+ Connection:
1884
+ - close
1885
+ Host:
1886
+ - www.omdbapi.com
1887
+ User-Agent:
1888
+ - http.rb/2.1.0
1889
+ response:
1890
+ status:
1891
+ code: 200
1892
+ message: OK
1893
+ headers:
1894
+ Date:
1895
+ - Fri, 23 Dec 2016 09:41:35 GMT
1896
+ Content-Type:
1897
+ - application/json; charset=utf-8
1898
+ Content-Length:
1899
+ - '2050'
1900
+ Connection:
1901
+ - close
1902
+ Set-Cookie:
1903
+ - __cfduid=d5ce0b88a3d8304d4743d2d5dacf3a1b31482486095; expires=Sat, 23-Dec-17
1904
+ 09:41:35 GMT; path=/; domain=.omdbapi.com; HttpOnly
1905
+ Cache-Control:
1906
+ - public, max-age=86400
1907
+ Expires:
1908
+ - Sat, 24 Dec 2016 09:41:35 GMT
1909
+ Last-Modified:
1910
+ - Fri, 23 Dec 2016 09:41:33 GMT
1911
+ Vary:
1912
+ - "*"
1913
+ X-Aspnet-Version:
1914
+ - 4.0.30319
1915
+ X-Powered-By:
1916
+ - ASP.NET
1917
+ Access-Control-Allow-Origin:
1918
+ - "*"
1919
+ Cf-Cache-Status:
1920
+ - MISS
1921
+ Server:
1922
+ - cloudflare-nginx
1923
+ Cf-Ray:
1924
+ - 315adbce2383469e-TPE
1925
+ body:
1926
+ encoding: UTF-8
1927
+ string: '{"Search":[{"Title":"The Hobbit: An Unexpected Journey","Year":"2012","imdbID":"tt0903624","Type":"movie","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BMTcwNTE4MTUxMl5BMl5BanBnXkFtZTcwMDIyODM4OA@@._V1_SX300.jpg"},{"Title":"The
1928
+ Hobbit: The Desolation of Smaug","Year":"2013","imdbID":"tt1170358","Type":"movie","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BMzU0NDY0NDEzNV5BMl5BanBnXkFtZTgwOTIxNDU1MDE@._V1_SX300.jpg"},{"Title":"The
1929
+ Hobbit: The Battle of the Five Armies","Year":"2014","imdbID":"tt2310332","Type":"movie","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BODAzMDgxMDc1MF5BMl5BanBnXkFtZTgwMTI0OTAzMjE@._V1_SX300.jpg"},{"Title":"The
1930
+ Hobbit","Year":"1977","imdbID":"tt0077687","Type":"movie","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BMjA0ODY3NTkwOF5BMl5BanBnXkFtZTcwODU3NzIyMQ@@._V1_SX300.jpg"},{"Title":"The
1931
+ Hobbit","Year":"1966","imdbID":"tt1686804","Type":"movie","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BYTU4OTUwYmQtYjVhZS00ZGRkLWExY2EtYzY5NzkzZGY4YmU1XkEyXkFqcGdeQXVyMjMyNTkxNzY@._V1_SX300.jpg"},{"Title":"A
1932
+ Day in the Life of a Hobbit","Year":"2002","imdbID":"tt0473467","Type":"movie","Poster":"http://ia.media-imdb.com/images/M/MV5BMTk3ODI5Nzk4Nl5BMl5BanBnXkFtZTcwMDE5MTcyMQ@@._V1_SX300.jpg"},{"Title":"The
1933
+ Hobbit: An Unexpected Journey - The Company of Thorin","Year":"2013","imdbID":"tt3345514","Type":"movie","Poster":"N/A"},{"Title":"Secrets
1934
+ of Middle-Earth: Inside Tolkien''s ''The Hobbit''","Year":"2003","imdbID":"tt0401776","Type":"movie","Poster":"http://ia.media-imdb.com/images/M/MV5BMTc4MzUxMDU3Nl5BMl5BanBnXkFtZTcwNjYxMzQyMQ@@._V1_SX300.jpg"},{"Title":"The
1935
+ Hobbit: The Swedolation of Smaug","Year":"2014","imdbID":"tt4171362","Type":"movie","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BMzQxMTkyYmQtMWZmYi00NzJmLTg3MDItZmEyZDQ3NmE5OWE4XkEyXkFqcGdeQXVyMjMyNTkxNzY@._V1_SX300.jpg"},{"Title":"The
1936
+ Hobbit Enigma","Year":"2008","imdbID":"tt1297277","Type":"movie","Poster":"N/A"}],"totalResults":"35","Response":"True"}'
1937
+ http_version:
1938
+ recorded_at: Fri, 23 Dec 2016 09:41:35 GMT
1939
+ - request:
1940
+ method: get
1941
+ uri: http://www.imdb.com/title//locations?ref_=tt_dt_dt
1942
+ body:
1943
+ encoding: US-ASCII
1944
+ string: ''
1945
+ headers:
1946
+ Accept-Encoding:
1947
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
1948
+ Accept:
1949
+ - "*/*"
1950
+ User-Agent:
1951
+ - Ruby
1952
+ response:
1953
+ status:
1954
+ code: 404
1955
+ message: Not Found
1956
+ headers:
1957
+ Date:
1958
+ - Fri, 23 Dec 2016 10:28:52 GMT
1959
+ Server:
1960
+ - HTTPDaemon
1961
+ Cache-Control:
1962
+ - private
1963
+ Content-Type:
1964
+ - text/html; charset=iso-8859-1
1965
+ Set-Cookie:
1966
+ - uu=BCYj5RXZmurLubyUGTBj5f-gXmP6umTkO2NkvdIIZ5oZL_n_M5Jbpvl-jGK7idbOqjdC3ULYtZirybtZRIdIYQbTnmaBtu-hb--mvSvEN-7APoyMwNNvLJjy1jdB76t131vLT0-mowwevTV4JnOQSmXgAPd911eRoj_LV-UIAbKyfK0;expires=Thu,
1967
+ 30 Dec 2037 00:00:00 GMT;path=/;domain=.imdb.com
1968
+ - uu=BCYqiiuovIxN22VlWKqAuCNDt2T6umTkO2NkvdIIZ5oZL_m0oN8eAYT_SNL8Ve2tgfPjsOBWlYDIOPDw-e83vr7QTh-0cPejvyKxKtcRqdQPOlNE1uW_1uqTm-FjI0WTGtfIWNApNJiPGtpWOzmQNnrMBTuYEmZu-khW8DUex-tFQjwxLlxQ3cEQiTa5LvWVpbiTKzsZ-BdbzmfFZKEVtw6RIcD6wDBvN0LFn-syb7Y1TFkcPAuUe2vJbhsWGe7O7dC2;expires=Thu,
1969
+ 30 Dec 2037 00:00:00 GMT;path=/;domain=.imdb.com
1970
+ Vary:
1971
+ - Accept-Encoding,User-Agent
1972
+ P3p:
1973
+ - policyref="http://i.imdb.com/images/p3p.xml",CP="CAO DSP LAW CUR ADM IVAo
1974
+ IVDo CONo OTPo OUR DELi PUBi OTRi BUS PHY ONL UNI PUR FIN COM NAV INT DEM
1975
+ CNT STA HEA PRE LOC GOV OTC "
1976
+ Content-Length:
1977
+ - '1189'
1978
+ body:
1979
+ encoding: ASCII-8BIT
1980
+ string: "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\"
1981
+ />\n <title>404 Error</title>\n</head>\n<body>\n\n<style>\nhtml, body {\n
1982
+ \ height: 100%;\n}\nbody {\n margin: auto;\n width: 1008px;\n background-color:
1983
+ #D4D9DD;\n font-family: Verdana, Arial, sans-serif;\n}\na {\n text-decoration:
1984
+ none;\n}\na:hover {\n text-decoration: underline;\n}\na:link, a:hover, a:visited
1985
+ {\n color: #136CB2;\n}\na:active {\n color: #E7BE00;\n}\n#error {\n height:
1986
+ 100%;\n background-color: white;\n border-left: 1px solid #999999;\n border-right:
1987
+ 1px solid #999999;\n box-shadow: 0 0 5px 5px #C5CACD;\n}\n.error_message
1988
+ {\n color: #999999;\n font-size: 17.5px;\n padding: 30px 70px 20px;\n}\n.error_bubble
1989
+ {\n font-family: Arial, helvetica, sans-serif;\n font-weight: bold;\n border-radius:
1990
+ 8px;\n -moz-border-radius: 8px;\n margin: 0 70px 0 70px;\n padding: 50px;\n}\n.error_bubble
1991
+ div {\n display: inline-block;\n vertical-align: middle;\n}\n.error_quote
1992
+ {\n color: #FFFFFF;\n font-size: 30px;\n line-height: 1.35em;\n padding-left:
1993
+ 50px;\n width: 500px;\n}\n.error_code {\n font-size: 100px;\n line-height:
1994
+ 50px;\n margin-top:8px\n}\n.error_arrow {\n border-color: #DECA16 transparent
1995
+ transparent transparent;\n border-style: solid;\n border-width: 21px 0px
1996
+ 0px 32px;\n height: 0;\n left: 700px;\n line-height: 0;\n position: relative;\n
1997
+ \ top: -1px;\n width: 0;\n}\n.error_code > span {\n font-size: 50px;\n}\n.error_attrib
1998
+ {\n color: #999999;\n float: right;\n font-size: 14px;\n font-style: italic;\n
1999
+ \ padding: 10px 70px 36px;\n}\n.error_code_404 .error_bubble {\n background:
2000
+ none repeat scroll 0% 0% #DECA16;\n border: 1px solid #DECA16;\n}\n.error_code_500
2001
+ .error_bubble {\n background: none repeat scroll 0% 0% #EDCA24;\n border:
2002
+ 1px solid #EDCA24;\n}\n.error_code_404 .error_code {\n color: #BFAD13;\n}\n.error_code_500
2003
+ .error_code {\n color: #CCAD1F;\n}\n.error_code_500 .error_arrow {\n border-color:
2004
+ #EDCA24 transparent transparent transparent;\n}\na.btn {\n background-repeat:
2005
+ repeat-x; \n background-color: #ECE2C6;\n background-image: linear-gradient(rgba(255,255,255,.8)
2006
+ 5%, rgba(255,255,255,0.0) 70%, rgba(255,255,255,0.8) 100%); \n background-image:
2007
+ -moz-linear-gradient(rgba(255,255,255,.8) 5%, rgba(255,255,255,0.0) 70%, rgba(255,255,255,0.8)
2008
+ 100%); \n background-image: -webkit-linear-gradient(rgba(255,255,255,.8)
2009
+ 5%, rgba(255,255,255,0.0) 70%, rgba(255,255,255,0.8) 100%); \n background-image:
2010
+ -ms-linear-gradient(rgba(255,255,255,.8) 5%, rgba(255,255,255,0.0) 70%, rgba(255,255,255,0.8)
2011
+ 100%); \n border-color: #E0E0E0 #C0C0C0 #C0C0C0 #E0E0E0;\n border-radius:
2012
+ 3px 3px 3px 3px;\n border-style: solid;\n border-width: 1px;\n color: #000000;\n
2013
+ \ cursor: pointer;\n float: right;\n margin-right: 70px;\n margin-top:
2014
+ 26px;\n padding: 0.3em 0.6em;\n text-decoration: none;\n}\na.btn:hover {\n
2015
+ \ background-image: none;\n border-color: #E6B800;\n}\n.clear {\n clear:
2016
+ both;\n}\n</style>\n<div id=\"error\" class=\"error_code_404\">\n <div
2017
+ class=\"error_message\">\n The requested URL was not found on our server.
2018
+ <a href=\"/\">Go to the IMDb homepage</a> &raquo;\n </div>\n <div class=\"error_bubble\">\n
2019
+ \ <div class=\"error_code\">404<br><span>ERROR</span></div>\n <div
2020
+ class=\"error_quote\">What's on the page?!</div>\n </div>\n <div class=\"error_arrow\"></div>\n
2021
+ \ <div class=\"error_attrib\"> <span>Detective David Mills, </span>
2022
+ \ <a href=\"/title/tt0114369/\">Se7en (1995)</a>\n </div>\n <div
2023
+ class=\"clear\"></div>\n</div>\n\n\n\n</body>\n</html>\n"
2024
+ http_version:
2025
+ recorded_at: Fri, 23 Dec 2016 10:28:53 GMT
1876
2026
  recorded_with: VCR 3.0.3
data/spec/omdb_spec.rb CHANGED
@@ -9,7 +9,7 @@ describe 'OMDB specifications' do
9
9
 
10
10
  before do
11
11
  VCR.insert_cassette CASSETTE_FILE_1, record: :new_episodes
12
- @movie = Movlog::Movie.find(t: OMDB_KEYWORD)
12
+ @movies = Movlog::Movies.find(s: OMDB_KEYWORD)
13
13
  end
14
14
 
15
15
  after do
@@ -17,15 +17,11 @@ describe 'OMDB specifications' do
17
17
  end
18
18
 
19
19
  it 'should get the data of a movie' do
20
- @movie.imdb_id.length.must_be :>, 0
21
- @movie.title.length.must_be :>, 0
22
- @movie.year.length.must_be :>, 0
23
- @movie.actors.length.must_be :>, 0
24
- @movie.poster.length.must_be :>, 0
25
- @movie.plot.length.must_be :>, 0
20
+ @movies.movies.length.must_be :>, 0
21
+ @movies.num.to_i.must_be :>, 0
26
22
  end
27
23
 
28
24
  it 'should get the filming location of a movie' do
29
- @movie.get_location.length.must_be :>, 0
25
+ @movies.movies.first.get_location.length.must_be :>, 0
30
26
  end
31
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: movlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Wen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-12-18 00:00:00.000000000 Z
13
+ date: 2016-12-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
@@ -198,6 +198,7 @@ files:
198
198
  - lib/movlog/airport.rb
199
199
  - lib/movlog/geonames_api.rb
200
200
  - lib/movlog/movie.rb
201
+ - lib/movlog/movies.rb
201
202
  - lib/movlog/omdb_api.rb
202
203
  - lib/movlog/room.rb
203
204
  - lib/movlog/route.rb