tvdb_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rspec +2 -0
  4. data/.rubyversion +1 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +2 -0
  7. data/Guardfile +20 -0
  8. data/README.md +43 -0
  9. data/Rakefile +9 -0
  10. data/conf/settings.example.yml +7 -0
  11. data/lib/tvdb_client.rb +13 -0
  12. data/lib/tvdb_client/authorization.rb +46 -0
  13. data/lib/tvdb_client/client.rb +30 -0
  14. data/lib/tvdb_client/connection.rb +98 -0
  15. data/lib/tvdb_client/series.rb +54 -0
  16. data/lib/tvdb_client/series/base.rb +32 -0
  17. data/lib/tvdb_client/series/series_episodes.rb +18 -0
  18. data/lib/tvdb_client/series/series_filter.rb +21 -0
  19. data/lib/tvdb_client/series/series_images.rb +14 -0
  20. data/lib/tvdb_client/service/threading.rb +8 -0
  21. data/lib/tvdb_client/service/threading/threaded_request.rb +51 -0
  22. data/lib/tvdb_client/settings.rb +10 -0
  23. data/lib/tvdb_client/version.rb +3 -0
  24. data/spec/spec_helper.rb +53 -0
  25. data/spec/support/fake_TVDB.rb +118 -0
  26. data/spec/support/fixtures/responses/login.json +3 -0
  27. data/spec/support/fixtures/responses/refresh_token.json +3 -0
  28. data/spec/support/fixtures/responses/series.json +33 -0
  29. data/spec/support/fixtures/responses/series_episodes_page_1.json +56 -0
  30. data/spec/support/fixtures/responses/series_episodes_page_2.json +56 -0
  31. data/spec/support/fixtures/responses/series_episodes_page_n.json +41 -0
  32. data/spec/support/fixtures/responses/series_episodes_query_airedSeason.json +41 -0
  33. data/spec/support/fixtures/responses/series_episodes_query_params.json +12 -0
  34. data/spec/support/fixtures/responses/series_episodes_summary.json +26 -0
  35. data/spec/support/fixtures/responses/series_filter.json +5 -0
  36. data/spec/support/fixtures/responses/series_filter_params.json +27 -0
  37. data/spec/support/fixtures/responses/series_images.json +9 -0
  38. data/spec/support/fixtures/responses/series_images_query.json +35 -0
  39. data/spec/support/fixtures/responses/series_images_query_params.json +60 -0
  40. data/spec/support/fixtures/settings.example.yml +6 -0
  41. data/spec/support/shared_contexts/authentication.rb +13 -0
  42. data/spec/support/shared_contexts/connection.rb +20 -0
  43. data/spec/support/shared_contexts/credentials.rb +20 -0
  44. data/spec/support/shared_contexts/series_subclass.rb +19 -0
  45. data/spec/tvdb_client/authorization_spec.rb +69 -0
  46. data/spec/tvdb_client/client_spec.rb +45 -0
  47. data/spec/tvdb_client/connection_spec.rb +159 -0
  48. data/spec/tvdb_client/series/base_spec.rb +13 -0
  49. data/spec/tvdb_client/series/series_episodes_spec.rb +55 -0
  50. data/spec/tvdb_client/series/series_filter_spec.rb +45 -0
  51. data/spec/tvdb_client/series/series_images_spec.rb +43 -0
  52. data/spec/tvdb_client/series_spec.rb +69 -0
  53. data/spec/tvdb_client/service/threading/threaded_request_spec.rb +54 -0
  54. data/spec/tvdb_client/version_spec.rb +12 -0
  55. data/tasks/version_bump.rake +102 -0
  56. data/templates/changelog_entry_template.md.erb +3 -0
  57. data/templates/version.rb.erb +3 -0
  58. data/tvdb_client.gemspec +41 -0
  59. metadata +412 -0
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe "TVDB::Series" do
5
+ include_context "Series Subclass"
6
+
7
+ describe "Initialization" do
8
+ it "should throw an error when trying to instantiate TVDB::Series::Base directly" do
9
+ expect { TVDB::Series::Base.new }.to raise_error( Exception )
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe "TVDB::Series" do
5
+ include_context "Series Subclass"
6
+
7
+ subject { TVDB::Series::Episodes.new( series_opts ) }
8
+
9
+ describe "Initialization" do
10
+ it "should create an instance of TVDB::Series" do
11
+ expect( subject ).to be_a_kind_of( TVDB::Series::Episodes )
12
+ end
13
+
14
+ it "should set a connection and a series ID" do
15
+ expect( subject.connection ).to be_a_kind_of( TVDB::Connection )
16
+ expect( subject.series_id ).to eq( '76703' )
17
+ end
18
+ end
19
+
20
+ describe "Episodes for a Series" do
21
+ context 'Listing episodes' do
22
+ it "should list the episodes for a series" do
23
+ episodes = subject.list
24
+ expect( episodes ).to be_a_kind_of( Hash )
25
+ expect( episodes["data"] ).to be_a_kind_of( Array )
26
+ expect( episodes["data"].length > 1 ).to be( true )
27
+ end
28
+ end
29
+
30
+ context 'Querying' do
31
+ it "should be able to query episodes for a series" do
32
+ expect( subject ).to respond_to( :query )
33
+ end
34
+
35
+ it "should return results that match the query" do
36
+ expect{ subject.query( params: { airedSeason: 15 } ) }.not_to raise_error
37
+ query = subject.query( params: { airedSeason: 15 } )
38
+
39
+ expect( query["data"][-1]["airedSeason"] ).to eq( "15" )
40
+ end
41
+
42
+ it "should return parameters to query by" do
43
+ expect( subject.query_params["data"] ).to be_a_kind_of( Array )
44
+ expect( subject.query_params["data"][0] ).to eq( "airedSeason" )
45
+ end
46
+ end
47
+
48
+ context 'Summary' do
49
+ it "should return a summary of episodes for the series" do
50
+ expect( subject.summary["data"]["airedSeasons"].length ).to eq( 17 )
51
+ end
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe "TVDB::Series" do
5
+ include_context "Series Subclass"
6
+
7
+ let( :init_opts ) {
8
+ series_opts[:params] = { :keys => "seriesName" }
9
+
10
+ series_opts
11
+ }
12
+
13
+ subject { TVDB::Series::Filter.new( init_opts ) }
14
+
15
+ describe "Initialization" do
16
+ it "should create an instance of TVDB::Series" do
17
+ expect( subject ).to be_a_kind_of( TVDB::Series::Filter )
18
+ end
19
+
20
+ it "should set a connection and a series ID" do
21
+ expect( subject.connection ).to be_a_kind_of( TVDB::Connection )
22
+ expect( subject.series_id ).to eq( '76703' )
23
+ end
24
+ end
25
+
26
+ describe "Filter for a Series" do
27
+ it "should filter the keys returned from a /series GET" do
28
+ expect( subject.list ).to be_a_kind_of( Hash )
29
+ expect( subject.list["data"] ).to have_key( "seriesName" )
30
+ expect( subject.list["data"].length ).to eq( 1 )
31
+ end
32
+
33
+ it "should return a list of keys to filter by" do
34
+ response = subject.params["data"]["params"]
35
+
36
+ expect( response ).to be_a_kind_of( Array )
37
+ expect( response.length > 1 ).to be( true )
38
+ end
39
+
40
+ it "should not respond to query_params" do
41
+ expect { subject.query_params }.to raise_error( NotImplementedError )
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe "TVDB::Series" do
5
+ include_context "Series Subclass"
6
+
7
+ subject { TVDB::Series::Images.new( series_opts ) }
8
+
9
+ describe "Initialization" do
10
+ it "should create an instance of TVDB::Series" do
11
+ expect( subject ).to be_a_kind_of( TVDB::Series::Images )
12
+ end
13
+
14
+ it "should set a connection and a series ID" do
15
+ expect( subject.connection ).to be_a_kind_of( TVDB::Connection )
16
+ expect( subject.series_id ).to eq( '76703' )
17
+ end
18
+ end
19
+
20
+ describe "Images for a Series" do
21
+ it "should return a summary of images for the given series" do
22
+ images = subject.list
23
+
24
+ expect( images ).to be_a_kind_of( Hash )
25
+ ["fanart", "poster", "season", "seasonwide", "series"].each do |type|
26
+ expect( images["data"] ).to have_key( type )
27
+ end
28
+ end
29
+
30
+ it "should return a user query" do
31
+ results = subject.query( :keyType => "fanart" )
32
+
33
+ expect( results["data"][0]["keyType"] ).to eq( "fanart" )
34
+ end
35
+
36
+ it "should list the parameters available to query by" do
37
+ results = subject.query_params
38
+
39
+ expect( results["data"].length > 1 ).to be( true )
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe "TVDB::Series" do
5
+ include_context "Authentication"
6
+
7
+ before( :each ) do
8
+ authenticate_connection
9
+ end
10
+
11
+ let( :series_id ) { '76703' }
12
+
13
+ subject { TVDB::Series.new( connection, series_id ) }
14
+
15
+ describe "Initialization" do
16
+ it "should create an instance of TVDB::Series" do
17
+ expect( subject ).to be_a_kind_of( TVDB::Series )
18
+ end
19
+
20
+ it "should set a connection accessor" do
21
+ expect( subject.connection ).to be_a_kind_of( TVDB::Connection )
22
+ end
23
+
24
+ it "should return series data" do
25
+ expect( subject.data ).to be_a_kind_of( Hash )
26
+ expect( subject.data["data"]["id"] ).to eq( 76703 )
27
+ end
28
+
29
+ it "should handle series that do not exist" do
30
+ bad_series = TVDB::Series.new( connection, '773747' )
31
+ expect( bad_series.data["Error"] ).to eq( "ID: 773747 not found" )
32
+ end
33
+ end
34
+
35
+ describe "Series Episodes" do
36
+ it "should return episodes in a series" do
37
+ expect( subject.episodes.list["data"] ).to be_a_kind_of( Array )
38
+ expect( subject.episodes.list["links"]["next"] ).to eq( 2 )
39
+ end
40
+
41
+ it "should return the 2nd page of results" do
42
+ result = subject.episodes( page: 2 ).list
43
+ expect( result["links"]["next"] ).to eq( nil )
44
+ end
45
+
46
+ it "should be able to return all episodes for a series" do
47
+ page1 = subject.episodes( page: 1 ).list["data"]
48
+ page2 = subject.episodes( page: 2 ).list["data"]
49
+
50
+ combined_pages = [page1, page2].flatten
51
+
52
+ expect( subject.all_episodes.length ).to eq( combined_pages.length )
53
+ end
54
+ end
55
+
56
+ describe "Series Images" do
57
+ it "should return images for a series" do
58
+ expect( subject.images ).to be_a_kind_of( TVDB::Series::Images )
59
+ end
60
+ end
61
+
62
+ describe "Series Filter" do
63
+ it "should return filtered results for a series" do
64
+ expect( subject.filter( :keys => "seriesName" ) ).to be_a_kind_of( TVDB::Series::Filter )
65
+ expect( subject.filter( :keys => "seriesName" ).list.length ).to eq( 1 )
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe "TVDB::Service::Threading" do
5
+ include_context "Authentication"
6
+
7
+ let(:init_options) {
8
+ {
9
+ connection: connection,
10
+ pool_size: 10
11
+ }
12
+ }
13
+
14
+ subject { TVDB::Service::Threading::ThreadedRequest.new( init_options ) }
15
+
16
+ describe "Initialization" do
17
+ it "should take arguments and set attrs" do
18
+ expect( subject.connection ).to be_a_kind_of( TVDB::Connection )
19
+ expect( subject.pool_size ).to be_a_kind_of( Integer )
20
+ end
21
+
22
+ it "should default to a pool size of 10" do
23
+ opts = { connection: connection }
24
+
25
+ tr = TVDB::Service::Threading::ThreadedRequest.new( opts )
26
+ expect( tr.pool_size ).to eq( 10 )
27
+ end
28
+ end
29
+
30
+ describe "Requests" do
31
+ before( :each ) do
32
+ authenticate_connection
33
+ end
34
+
35
+ it "should be able to make a request" do
36
+ expect( subject ).to respond_to( :make_request )
37
+ end
38
+
39
+ it "should return an array of results" do
40
+ response = subject.make_request( "/series/99999/episodes" )
41
+
42
+ expect( response ).to be_a_kind_of( Array )
43
+ expect( response.length > 0 ).to be( true )
44
+ end
45
+
46
+ it "should bail if the route doesn't return a 200 response" do
47
+ expect( subject.make_request( "/series/12345/episodes" ).code ).to eq( 404 )
48
+ end
49
+
50
+ it "should limit connections to the pool size" do
51
+ skip "Not sure how to test this one yet"
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe "TVDB::Version" do
5
+
6
+ describe "version" do
7
+ it "should return the version of the API client" do
8
+ expect( TVDB::VERSION ).to be_a_kind_of( String )
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,102 @@
1
+ namespace :version do
2
+
3
+ desc "Bumps up the version number by the patch level"
4
+ task :patch do
5
+ bump_version( "patch" )
6
+ end
7
+
8
+ desc "Bumps up the version number by a minor release level"
9
+ task :minor do
10
+ bump_version( "minor" )
11
+ end
12
+
13
+ desc "Bumps up the version number by a major release level"
14
+ task :major do
15
+ bump_version( "major" )
16
+ end
17
+
18
+ desc "TVDB's current version"
19
+ task :current do
20
+ puts TVDB::VERSION
21
+ end
22
+
23
+ desc "Bypass incremental bumping and set the version to whatever you specify in the format: #.#.#"
24
+ task :set, [:version] do |t, args|
25
+ raise "Version must match the following format: #.#.#" unless args[:version].match( /^[0-9].[0-9].[0-9]$/ )
26
+ write_version_file( args[:version] )
27
+ end
28
+
29
+ def bump_version( version_level )
30
+ current_version = Semantic::Version.new( TVDB::VERSION )
31
+
32
+ case version_level
33
+ when "patch"
34
+ current_version.patch += 1
35
+ when "minor"
36
+ current_version.minor += 1
37
+ current_version.patch = 0
38
+ when "major"
39
+ current_version.major += 1
40
+ current_version.minor = 0
41
+ current_version.patch = 0
42
+
43
+ end
44
+
45
+ write_version_file( current_version )
46
+ end
47
+
48
+ def write_version_file( version )
49
+ yes_or_no = ask( "You are about to change tvdb_client to version: #{version}. Continue? [y/n]" )
50
+
51
+ continue?( yes_or_no )
52
+ create_new_version_file( version )
53
+ add_entry_to_changelog( version )
54
+ end
55
+
56
+ def continue?( yes_or_no )
57
+ case yes_or_no
58
+ when "y"
59
+ puts 'Continuing...'
60
+ when "n"
61
+ abort( 'Looks like you changed your mind. Exiting!' )
62
+ else
63
+ puts "Please respond with either 'y' or 'n'."
64
+ end
65
+ end
66
+
67
+ def create_new_version_file( version )
68
+ @new_version = version
69
+ template = File.expand_path( "../../templates/version.rb.erb", __FILE__ )
70
+
71
+ erb = ERB.new( File.read( template ) )
72
+ file_output = erb.result(binding)
73
+ file_output_path = File.expand_path( '../../lib/tvdb_client/version.rb', __FILE__ )
74
+
75
+ File.open( file_output_path, 'w' ) { |f| f.write( file_output ) }
76
+
77
+ message = [
78
+ "\nTVDB has been updated to version: #{version}!",
79
+ "A new entry has appeared in the CHANGELOG!",
80
+ " ",
81
+ "Please edit the new CHANGELOG entry and add it along with version.rb to the repo."
82
+ ].join( "\n" )
83
+
84
+ puts message
85
+ end
86
+
87
+ def add_entry_to_changelog( version )
88
+ @new_version = version
89
+ chlg_temp = "../../templates/changelog_entry_template.md.erb"
90
+ template = File.expand_path( chlg_temp, __FILE__ )
91
+
92
+ erb = ERB.new( File.read( template ) )
93
+ file_output = erb.result(binding)
94
+ changelog = File.expand_path( '../../CHANGELOG.md', __FILE__ )
95
+
96
+ new_changelog = File.read( changelog ).lines.insert(2, file_output)
97
+
98
+ File.open( changelog, 'w' ) { |f| f.write( new_changelog.join('') ) }
99
+ end
100
+
101
+
102
+ end
@@ -0,0 +1,3 @@
1
+ ## <%= @new_version %>
2
+ Add your notes here!
3
+
@@ -0,0 +1,3 @@
1
+ module TVDB
2
+ VERSION = "<%= @new_version %>"
3
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tvdb_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tvdb_client"
8
+ spec.version = TVDB::VERSION
9
+ spec.authors = ["Aaron Lunsford"]
10
+ spec.email = ["awlunsfo@gmail.com"]
11
+ spec.summary = %q{Ruby client for the TVDB API}
12
+ spec.description = %q{Ruby library for interacting with the TVDB's REST API}
13
+ spec.homepage = "https://github.com/awlunsfo/tvdb_client.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.add_dependency 'siliconsalad-settingslogic', '~> 2.0'
21
+ spec.add_dependency 'multi_json', '~> 1.10'
22
+ spec.add_dependency 'faraday', '~> 0.9'
23
+ spec.add_dependency 'rake', '~> 10.1'
24
+ spec.add_dependency 'semantic', '~> 1.3'
25
+ spec.add_dependency 'highline', '~> 1.7'
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.7"
28
+ spec.add_development_dependency 'guard', '~> 2.6'
29
+ spec.add_development_dependency 'guard-rspec', '~> 4.3'
30
+ spec.add_development_dependency 'terminal-notifier', '~> 1.6'
31
+ spec.add_development_dependency 'terminal-notifier-guard', '~> 1.6'
32
+ spec.add_development_dependency 'rb-readline', '~> 0.5'
33
+ spec.add_development_dependency 'pry-byebug', '~> 3.2'
34
+ spec.add_development_dependency 'guard-spork', '~> 2.1'
35
+ spec.add_development_dependency 'spork', '~> 0.9'
36
+ spec.add_development_dependency 'yard', '~> 0.8'
37
+ spec.add_development_dependency 'rspec', '~> 3.1'
38
+ spec.add_development_dependency 'simplecov', '~> 0.9'
39
+ spec.add_development_dependency 'webmock', '~> 1.18'
40
+ spec.add_development_dependency 'sinatra', '~> 1.4'
41
+ end