imdb_watchlist 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/imdb_watchlist.rb +88 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 209cae439555147f040e00f7dd61427dc6103e02
4
+ data.tar.gz: e956f5ff2471a1fe64a4b84b57ba7df2ff583fce
5
+ SHA512:
6
+ metadata.gz: 2df2bffc5c26d501d206c8bf3d4418b8610a89bbcc032b466a4c90c7fac27bc45a632840eadba82f41dc447fed9dc6ca6576eed69286976d9f3dbee4a53065dd
7
+ data.tar.gz: b3e9bdc75017c88c8a9cfc96a08e0bfb8e6e95735e16f0d33a8befeb44f925390d6e5e720f4689e29a049045a1f905d7f2fcb8fdeeed978083e513db71a88127
@@ -0,0 +1,88 @@
1
+ require 'open-uri'
2
+ require 'rss'
3
+ require 'uri'
4
+
5
+ class IMDbWatchlist
6
+ # Load and parse an IMDb watchlist.
7
+ #
8
+ # Example:
9
+ # url = 'http://www.imdb.com/user/ur13693513/watchlist'
10
+ # wl = ImdbWatchlist.new(url)
11
+ # puts wl.to_s
12
+ # wl.items.each do |item|
13
+ # puts item.to_s
14
+ # end
15
+ #
16
+ # Arguments:
17
+ # url: (String)
18
+
19
+ @url
20
+ @title
21
+ @items
22
+
23
+ attr_reader :url
24
+ attr_reader :title
25
+ attr_reader :items
26
+
27
+ def initialize(url)
28
+ @url = url
29
+
30
+ open(sanitize_url(url)) do |rss|
31
+ feed = RSS::Parser.parse(rss)
32
+ @title = feed.channel.title
33
+ @items = feed.items.map { |feed_item| Item.new(feed_item) }
34
+ end
35
+ end
36
+
37
+ def sanitize_url(url)
38
+ uri = URI(url)
39
+
40
+ # No scheme? Probably a local file path.
41
+ if uri.scheme == nil
42
+ return url
43
+ end
44
+
45
+ # Verify host
46
+ if not uri.host.end_with? 'imdb.com'
47
+ raise "Must provide an 'imdb.com' URL '#{url}"
48
+ end
49
+
50
+ # Verify path
51
+ path_matches = /user\/(ur\d+)\/watchlist/.match(uri.path)
52
+ if not path_matches
53
+ raise "Must provide a watchlist URL '#{url}'"
54
+ end
55
+
56
+ # Require RSS subdomain
57
+ uri.host = 'rss.imdb.com'
58
+
59
+ uri.to_s
60
+ end
61
+
62
+ def to_s
63
+ "#{title} - #{url} - #{items.count} Items"
64
+ end
65
+
66
+ class Item
67
+ @title
68
+ @id
69
+ @date_added
70
+ @url
71
+
72
+ attr_reader :title
73
+ attr_reader :id
74
+ attr_reader :date_added
75
+ attr_reader :url
76
+
77
+ def initialize(rss_item)
78
+ @title = rss_item.title
79
+ @id = URI(rss_item.link).path.split('/').last
80
+ @date_added = rss_item.pubDate
81
+ @url = rss_item.link
82
+ end
83
+
84
+ def to_s
85
+ "#{id} - #{title} - #{url} - #{date_added}"
86
+ end
87
+ end
88
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imdb_watchlist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian Partridge
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple utility for loading an IMDb user's watchlist.
14
+ email: brianpartridge@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/imdb_watchlist.rb
20
+ homepage: https://github.com/brianpartridge/IMDbWatchlist
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: IMDb Watchlist
44
+ test_files: []
45
+ has_rdoc: