tmdb_trailer 0.2.8 → 0.2.9

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.2.9
@@ -9,30 +9,19 @@ module TMDB
9
9
  attr_reader :coll # MongoDB collection
10
10
  attr_accessor :country # country associated with Trailer instance
11
11
  API_KEY = File.read(File.join(File.expand_path(File.dirname(__FILE__)), "secret.txt")).gsub("\n","")
12
+ BASE_URI = "http://api.themoviedb.org/2.1/"
12
13
  NEXT_PAGE = 1
13
14
  # country - country code i.e "us" for united states, "hk" for hongkong
14
15
  # db_name - database name to store mongo documents, will create one for you if it doesnt exists
15
16
  def initialize(country,db_name)
16
- @base_uri = "http://api.themoviedb.org/2.1/Movie.browse/en/json/"
17
17
  @country = country
18
-
19
- #initialize the mongoDB connection
20
- @db = Mongo::Connection.new.db(db_name)
21
- @pstore = PStore.new("#{db_name}.pstore")
22
- @coll = @db["movies"]
23
-
18
+ db = Mongo::Connection.new.db(db_name)
19
+ @coll = db["movies"]
24
20
  #if mongo collection does not exist, create index to avoid duplicate documents
25
- if @coll.count == 0
26
- @coll.create_index("name", :unique => true)
27
- end
28
-
29
- # initialize pstore as well
30
- if @coll.find(:country=> @country).count == 0
31
- @pstore.transaction do
32
- @pstore[@country] = 1
33
- end
34
- end
35
-
21
+ @coll.create_index("name", :unique => true) if @coll.count == 0
22
+ # initialize pstore
23
+ @pstore = PStore.new("#{db_name}.pstore")
24
+ @pstore.transaction { @pstore[@country] = 1 } if @coll.find(:country=> @country).count == 0
36
25
  #initialize persistent http connection
37
26
  @http = Net::HTTP::Persistent.new
38
27
  end
@@ -54,9 +43,7 @@ module TMDB
54
43
  #
55
44
  # i.e http://api.themoviedb.org/2.1/Movie.browse/en-US/json/{API_KEY}?countries=jp&order_by=rating&order=desc&min_votes=1&page=4&per_page=50
56
45
  def get_page
57
- @pstore.transaction do
58
- return @pstore[@country]
59
- end
46
+ @pstore.transaction { @pstore[@country] }
60
47
  end
61
48
 
62
49
  # get the result of parsed json response of Movie.browse API call of TMDB
@@ -64,7 +51,7 @@ module TMDB
64
51
  votes = @country == "us" ? 3 : 0
65
52
  @params = "countries=#{@country}&order_by=rating&" +
66
53
  "min_votes=#{votes}&order=desc&page=#{page}&per_page=50"
67
- url = "#{@base_uri}#{API_KEY}?#{@params}"
54
+ url = "#{BASE_URI}Movie.browse/en/json/#{API_KEY}?#{@params}"
68
55
  uri = URI.parse(url)
69
56
  response = @http.request(uri).body
70
57
  movies = JSON.parse(response)
@@ -105,44 +92,34 @@ module TMDB
105
92
 
106
93
  # get the page which the API should use the next it calls Movie.browse
107
94
  def current_page
108
- @pstore.transaction do
109
- @pstore[@country]
110
- end
95
+ @pstore.transaction { @pstore[@country] }
111
96
  end
112
97
 
113
98
  # if called, give a summary of progress of populating the database
114
99
  def report
115
100
  total = total_movies
116
- params = {}
117
- params["country"] = @country
118
- movies_in_mongo = @coll.find(params).count
119
- report = "#{params["country"]} currently has populated #{movies_in_mongo} out of #{total} movies available on tmdb"
120
- return report
101
+ movies_in_mongo = @coll.find(:country => @country).count
102
+ return "#{@country} currently has populated #{movies_in_mongo} out of #{total} movies available on tmdb"
121
103
  end
122
104
 
123
105
  # gets the trailer, genre, keyword, year information using Movie.getInfo API call
124
106
  def get_extra_info(id)
125
107
  genres = []
126
108
  keywords = []
127
- url = "http://api.themoviedb.org/2.1/Movie.getInfo/en/json/#{API_KEY}/#{id}"
109
+ url = "#{BASE_URI}Movie.getInfo/en/json/#{API_KEY}/#{id}"
128
110
  uri = URI.parse(url)
129
111
  response = @http.request(uri).body
130
- movie = JSON.parse(response)
131
- trailer = movie[0]["trailer"] if movie[0]["trailer"]
132
- movie[0]["genres"].each do |genre|
133
- genres << genre["name"]
134
- end
135
- keywords = movie[0]["keywords"]
136
- movie[0]["released"] =~ /^(\d*)/
112
+ movie = JSON.parse(response)[0]
113
+ trailer, keywords = movie["trailer"], movie["keywords"]
114
+ movie["genres"].each {|g| genres << g["name"]}
115
+ movie["released"] =~ /^(\d*)/
137
116
  year = $1
138
117
  return trailer,genres,keywords,year
139
118
  end
140
119
 
141
120
  # stores locally the page which the API should use the next it calls Movie.browse
142
121
  def remember_page(page)
143
- @pstore.transaction do
144
- @pstore[@country] = page
145
- end
122
+ @pstore.transaction { @pstore[@country] = page }
146
123
  end
147
124
 
148
125
  end
@@ -1,2 +1,2 @@
1
1
  {
2
- "nzi"czi"bri"roi"usi
2
+ "czi"nzi"bri"roi"usi
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tmdb_trailer}
8
- s.version = "0.2.8"
8
+ s.version = "0.2.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["redgetan"]
12
- s.date = %q{2011-02-21}
12
+ s.date = %q{2011-02-23}
13
13
  s.description = %q{ Movie Trailer information will be stored in mongoDB. Information includes year released, movie genres, keywords, and country}
14
14
  s.email = %q{redge.tan@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmdb_trailer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 8
10
- version: 0.2.8
9
+ - 9
10
+ version: 0.2.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - redgetan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-21 00:00:00 -05:00
18
+ date: 2011-02-23 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency