tvdb-api 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +7 -0
  4. data/Readme.md +41 -0
  5. data/lib/tvdb_api.rb +123 -0
  6. data/tvdb_api.gemspec +17 -0
  7. metadata +63 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b5585c7aa4d9e2520813b5448b202976a527d2b
4
+ data.tar.gz: 311ebb228e76a8dd865a75c478f957e5b9c5ee7d
5
+ SHA512:
6
+ metadata.gz: c0eb82b21d9e3b4bc544a96b177d3f07b73aa205bb639268de828191f399c234a6ac679700c818d9825825670bd2310179c80f1caeb3cbab7a8866da0ba8b588
7
+ data.tar.gz: ac991c3ea3ad35fb5914828e7bb1ba2e2da9960748373625842dd60b4cfc62c753b00914cb2eeee7a3923e57f76b50313f065118a1569211cc26cd8d8ed50b12
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://www.rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 Matt Edlefsen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ TVDB API
2
+ ========
3
+
4
+ Yet another Ruby client for the TVDB ( http://thetvdb.com ).
5
+
6
+ * Clean and fully featured API client that streamlines usage but gets out of your way when you need it to.
7
+ * Supports all non-deprecated aspects of the TVDB Api.
8
+ * Uses compression for all calls making the API very quick.
9
+ * All XML responses parsed into simple Ruby Hash structure.
10
+
11
+ See http://thetvdb.com/wiki/index.php?title=Programmers_API for documentation of API.
12
+
13
+ **This library does not do caching. Please use some form of caching when interacting with TVDB**
14
+
15
+ Usage
16
+ -----
17
+
18
+ client = TVDBApi.new API_KEY
19
+ # or
20
+ client = TVDBApi.new API_KEY, 'en'
21
+
22
+ # Dynamic Interfaces
23
+ client.get_series 'Futurama'
24
+ client.get_series_by_remote_id :imdb, 'tt0149460'
25
+ # etc...
26
+
27
+ ## Files Interface
28
+
29
+ client['updates/updates_day.xml']
30
+
31
+ # Adds .xml for you
32
+ client['languages'] # => languages.xml
33
+
34
+ # Automatically gets the default language if not specified
35
+ client['series/73871'] => series/73871/en.xml
36
+
37
+ # Allows array input for more structured calls
38
+ client[:series, 73871, :default, 1, 1] => 'series/73871/default/1/1/en.xml'
39
+
40
+ # Adds 'updates_' prefix to updates calls
41
+ client[:updates, :day] => 'updates/updates_day.xml'
@@ -0,0 +1,123 @@
1
+ require 'httparty'
2
+
3
+ class TVDBApi
4
+ include HTTParty
5
+ format :xml
6
+ base_uri 'http://www.thetvdb.com'
7
+ headers 'Accept-encoding' => 'gzip'
8
+
9
+ def initialize(api_key,opts = {})
10
+ @lang = opts[:lang] || 'en'
11
+ @api_key = api_key
12
+ @tries = 3
13
+ end
14
+
15
+ def get_series(series_name, lang = @lang)
16
+ get 'GetSeries.php', seriesname: series_name, language: lang
17
+ end
18
+
19
+ def get_series_by_remote_id(type, id, lang = @lang)
20
+ query = {language: lang}
21
+ case type
22
+ when :imdb then query[:imdbid] = id
23
+ when :zap2it then query[:zap2it] = id
24
+ else raise "Invalid remote id type '#{type}'"
25
+ end
26
+ get 'GetSeriesByRemoteID.php', query
27
+ end
28
+
29
+ def get_episode_by_air_date(series_id, air_date, lang = @lang)
30
+ if air_date.respond_to? :to_time
31
+ air_date = air_date.to_time
32
+ end
33
+ if air_date.respond_to? :strftime
34
+ air_date = air_date.strftime('%F')
35
+ end
36
+
37
+ get 'GetEpisodeByAirDate.php',
38
+ apikey: @api_key, language: lang,
39
+ seriesid: series_id, airdate: air_date
40
+ end
41
+
42
+ def get_retings_for_user(account_id, series_id = nil)
43
+ query = { apikey: @api_key, accountid: account_id }
44
+ query[:seriesid] = series_id if series_id
45
+ get 'GetRatingsForUser.php', query
46
+ end
47
+
48
+ def user_preferred_language(account_id)
49
+ get 'User_PreferredLanguage.php', accountid: account_id
50
+ end
51
+
52
+ def user_favorites(account_id, change = nil, series_id = nil)
53
+ query = {accountid: account_id}
54
+ if change
55
+ if [:add,:remove].include?(change) && series_id
56
+ query[:type] = change
57
+ query[:seriesid] = series_id
58
+ else
59
+ raise ArgumentError.new("change may only be :add or :remove and series_id must be set if change is set")
60
+ end
61
+ end
62
+ get 'User_Favorites.php', query
63
+ end
64
+
65
+ def user_rating(account_id, item_type, item_id, rating)
66
+ get 'User_Rating.php',
67
+ accountid: account_id, itemtype: item_type,
68
+ itemid: itemid, rating: rating
69
+ end
70
+
71
+ def to_full(path)
72
+ if path !~ /\.php$/
73
+ path = @api_key+'/'+path
74
+
75
+ if path =~ /\/\d+(\/all)?\/?$/
76
+ path += '/' + @lang + '.xml'
77
+ end
78
+
79
+ if path =~ /(.*\/updates\/)(?!updates_)(.*)/
80
+ path = $1+"updates_"+$2
81
+ end
82
+
83
+ if path =~ /\/[^\/\.]*$/
84
+ path += '.xml'
85
+ end
86
+ end
87
+
88
+ if path[0] != '/'
89
+ if path !~ /^?api\//
90
+ path = '/api/'+path
91
+ else
92
+ path = '/' + path
93
+ end
94
+ end
95
+
96
+ path
97
+ end
98
+
99
+ def get(path,query=nil, options={})
100
+ if path.respond_to? :join
101
+ path = path.join("/")
102
+ end
103
+ path = to_full path
104
+ if query
105
+ options[:query] = query
106
+ end
107
+ ex = nil
108
+ @tries.times do
109
+ begin
110
+ res = self.class.get(path,options)
111
+ return res
112
+ rescue => e
113
+ ex = e
114
+ end
115
+ end
116
+ raise ex
117
+ end
118
+
119
+ def [](*args)
120
+ get args
121
+ end
122
+
123
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'tvdb-api'
3
+ s.version = '1.0.1'
4
+ s.summary = "Straightforward Ruby client for TVDB"
5
+ s.description = "Clean Ruby API interface to The TVDB"
6
+ s.authors = ["Matt Edlefsen"]
7
+ s.email = 'matt@xforty.com'
8
+ s.files = `git ls-files`.split("\n")
9
+ s.license = "MIT"
10
+ s.homepage = 'https://github.com/medlefsen/tvdb-api'
11
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ s.require_paths = ["lib"]
13
+ s.extra_rdoc_files = [
14
+ "Readme.md"
15
+ ]
16
+ s.add_dependency('httparty', '~> 0.10.0')
17
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tvdb-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Edlefsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.0
27
+ description: Clean Ruby API interface to The TVDB
28
+ email: matt@xforty.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - Readme.md
33
+ files:
34
+ - Gemfile
35
+ - LICENSE
36
+ - Readme.md
37
+ - lib/tvdb_api.rb
38
+ - tvdb_api.gemspec
39
+ homepage: https://github.com/medlefsen/tvdb-api
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.0.0
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Straightforward Ruby client for TVDB
63
+ test_files: []