themoviedb 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,14 @@
1
- require 'rubygems'
2
- require 'httparty'
3
-
4
- ["api","search","resource", "configuration"].each do |inc|
5
- require File.join(File.dirname(__FILE__), "themoviedb", inc)
6
- end
7
-
8
- ["movie", "collection", "people", "company"].each do |inc|
9
- require File.join(File.dirname(__FILE__), "themoviedb", inc)
10
- end
11
-
12
- module Tmdb
13
- VERSION = "0.0.5"
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ ["api","search","resource", "configuration"].each do |inc|
5
+ require File.join(File.dirname(__FILE__), "themoviedb", inc)
6
+ end
7
+
8
+ ["movie", "collection", "people", "company", "genre"].each do |inc|
9
+ require File.join(File.dirname(__FILE__), "themoviedb", inc)
10
+ end
11
+
12
+ module Tmdb
13
+ VERSION = "0.0.6"
14
14
  end
@@ -0,0 +1,63 @@
1
+ module Tmdb
2
+ class Genre
3
+ def initialize(attributes={})
4
+ attributes.each do |key, value|
5
+ if self.respond_to?(key.to_sym)
6
+ self.instance_variable_set("@#{key}", value)
7
+ end
8
+ end
9
+ end
10
+
11
+ #http://docs.themoviedb.apiary.io/#genres
12
+ @@fields = [
13
+ :id,
14
+ :page,
15
+ :total_pages,
16
+ :total_results,
17
+ :results
18
+ ]
19
+
20
+ @@fields.each do |field|
21
+ attr_accessor field
22
+ end
23
+
24
+ def self.search(query)
25
+ self.detail(self.list['genres'].detect { |g| g['name'] == query }['id'])
26
+ end
27
+
28
+ class << self
29
+ alias_method :find, :search
30
+ end
31
+
32
+ def self.list
33
+ search = Tmdb::Search.new("/genre/list")
34
+ search.fetch_response
35
+ end
36
+
37
+ def self.detail(id, conditions={})
38
+ url = "/genre/#{id}/movies"
39
+ if !conditions.empty?
40
+ url << "?"
41
+ conditions.each_with_index do |(key, value), index|
42
+ url << "#{key}=#{value}"
43
+ if index != conditions.length - 1
44
+ url << "&"
45
+ end
46
+ end
47
+ end
48
+ search = Tmdb::Search.new(url)
49
+ self.new(search.fetch_response)
50
+ end
51
+
52
+ def name
53
+ @name ||= self.class.list['genres'].detect { |g| g['id'] == @id }['name']
54
+ end
55
+
56
+ def get_page(page_number, conditions={})
57
+ if page_number != @page and page_number > 0 and page_number <= @total_pages
58
+ conditions.merge!({ :page => page_number })
59
+ self.class.detail(id, conditions)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,33 +1,34 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "themoviedb"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "themoviedb"
7
- s.version = Tmdb::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Ahmet Abdi"]
10
- s.email = ["ahmetabdi@gmail.com"]
11
- s.homepage = "http://rubygems.org/gems/themoviedb"
12
- s.summary = %q{A Ruby wrapper for the The Movie Database API.}
13
- s.description = %q{Provides a simple, easy to use interface for the Movie Database API.}
14
- s.rubyforge_project = "themoviedb"
15
- s.files = [
16
- "themoviedb.gemspec",
17
- "lib/themoviedb.rb",
18
- "lib/themoviedb/api.rb",
19
- "lib/themoviedb/collection.rb",
20
- "lib/themoviedb/company.rb",
21
- "lib/themoviedb/configuration.rb",
22
- "lib/themoviedb/movie.rb",
23
- "lib/themoviedb/people.rb",
24
- "lib/themoviedb/resource.rb",
25
- "lib/themoviedb/search.rb",
26
- "test/movie_test.rb"
27
- ]
28
- s.test_files = [
29
- "test/movie_test.rb"
30
- ]
31
- s.require_paths = ["lib"]
32
- s.add_dependency('httparty')
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "themoviedb"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "themoviedb"
7
+ s.version = Tmdb::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ahmet Abdi"]
10
+ s.email = ["ahmetabdi@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/themoviedb"
12
+ s.summary = %q{A Ruby wrapper for the The Movie Database API.}
13
+ s.description = %q{Provides a simple, easy to use interface for the Movie Database API.}
14
+ s.rubyforge_project = "themoviedb"
15
+ s.files = [
16
+ "themoviedb.gemspec",
17
+ "lib/themoviedb.rb",
18
+ "lib/themoviedb/api.rb",
19
+ "lib/themoviedb/collection.rb",
20
+ "lib/themoviedb/company.rb",
21
+ "lib/themoviedb/configuration.rb",
22
+ "lib/themoviedb/genre.rb",
23
+ "lib/themoviedb/movie.rb",
24
+ "lib/themoviedb/people.rb",
25
+ "lib/themoviedb/resource.rb",
26
+ "lib/themoviedb/search.rb",
27
+ "test/movie_test.rb"
28
+ ]
29
+ s.test_files = [
30
+ "test/movie_test.rb"
31
+ ]
32
+ s.require_paths = ["lib"]
33
+ s.add_dependency('httparty')
33
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: themoviedb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -40,6 +40,7 @@ files:
40
40
  - lib/themoviedb/collection.rb
41
41
  - lib/themoviedb/company.rb
42
42
  - lib/themoviedb/configuration.rb
43
+ - lib/themoviedb/genre.rb
43
44
  - lib/themoviedb/movie.rb
44
45
  - lib/themoviedb/people.rb
45
46
  - lib/themoviedb/resource.rb