tvrage_api 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -13
  3. data/lib/tvrage_api/base.rb +25 -6
  4. data/lib/tvrage_api/client.rb +13 -0
  5. data/lib/tvrage_api/search.rb +9 -0
  6. data/lib/tvrage_api/show.rb +14 -19
  7. data/lib/tvrage_api/update.rb +5 -0
  8. data/lib/tvrage_api/version.rb +1 -1
  9. data/lib/tvrage_api.rb +3 -7
  10. data/spec/integrations/client_spec.rb +55 -0
  11. data/spec/integrations/search_spec.rb +7 -7
  12. data/spec/integrations/show_spec.rb +12 -12
  13. data/spec/integrations/update_spec.rb +5 -6
  14. data/spec/tvrage_api/base_spec.rb +56 -0
  15. data/spec/tvrage_api/client_spec.rb +23 -0
  16. data/spec/tvrage_api/search_spec.rb +22 -0
  17. data/spec/tvrage_api/show_spec.rb +18 -59
  18. data/spec/tvrage_api/update_spec.rb +14 -0
  19. data/tvrage_api.gemspec +1 -2
  20. metadata +15 -53
  21. data/lib/tvrage_api/element.rb +0 -3
  22. data/lib/tvrage_api/episode.rb +0 -9
  23. data/lib/tvrage_api/request/base.rb +0 -57
  24. data/lib/tvrage_api/request/search.rb +0 -13
  25. data/lib/tvrage_api/request/show.rb +0 -37
  26. data/lib/tvrage_api/request/update.rb +0 -13
  27. data/lib/tvrage_api/utility/aka_array.rb +0 -9
  28. data/lib/tvrage_api/utility/date.rb +0 -9
  29. data/lib/tvrage_api/utility/date_or_integer.rb +0 -11
  30. data/lib/tvrage_api/utility/episode_array.rb +0 -15
  31. data/lib/tvrage_api/utility/genre_array.rb +0 -9
  32. data/lib/tvrage_api/utility/hashie/extensions/key_replace.rb +0 -42
  33. data/lib/tvrage_api/utility/integer.rb +0 -5
  34. data/lib/tvrage_api/utility/string.rb +0 -11
  35. data/lib/tvrage_api/utility.rb +0 -8
  36. data/spec/tvrage_api/episode_spec.rb +0 -51
  37. data/spec/tvrage_api/request/base_spec.rb +0 -113
  38. data/spec/tvrage_api/request/search_spec.rb +0 -30
  39. data/spec/tvrage_api/request/show_spec.rb +0 -71
  40. data/spec/tvrage_api/request/update_spec.rb +0 -28
  41. data/spec/tvrage_api/utility/aka_array_spec.rb +0 -17
  42. data/spec/tvrage_api/utility/date_or_integer_spec.rb +0 -13
  43. data/spec/tvrage_api/utility/date_spec.rb +0 -13
  44. data/spec/tvrage_api/utility/genre_array_spec.rb +0 -17
  45. data/spec/tvrage_api/utility/integer_spec.rb +0 -9
  46. data/spec/tvrage_api/utility/string_spec.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 113bc0f11f6442f79fc786189fefb52e634c4367
4
- data.tar.gz: 440b7e8e641d79ac98f4a6fd850e142e4d3db3d3
3
+ metadata.gz: 62f7f9d558b9cd8fe834e83c4349bcdf5665d4bf
4
+ data.tar.gz: 5c079055971ba0d4b341e3099c30c3d09e5d080b
5
5
  SHA512:
6
- metadata.gz: 741105dc9cb02c567a3dce94f680fcc00d5246002f477bf3e34f0f9d48fad3ee8b5fbb034bc58400c8a9a553f44619bb52851ca6064eeeeddc00723608da2fac
7
- data.tar.gz: 59f45cbc2c174ebd517c3a30ba06bbe63c6795e64302913273ae06c6aedbd0712ecda47f97f721ae90463dab8cc8dc46778b390d6b54bfeb2e41e0bba704f088
6
+ metadata.gz: 54736a76669139e2e0cb92c85d472d5a68978f2a86ab03359a3d6bd957e02c934a91d5d8e7c7c461e59d29c27c411c4575f093ca04af06919a9eb97f9ebeaf6b
7
+ data.tar.gz: 173775ab0e8a14ae56c73b18744dca37950ff84c632ff249c16b7842134daa90d21a7064a67512fc2ee800b463e1c75e76fee718be02eeff2fff66b36a0d162e
data/README.md CHANGED
@@ -19,23 +19,36 @@ Run the bundle command to install it.
19
19
 
20
20
  ## How to use
21
21
 
22
- All request class return instance where result method contain object or collection.
22
+ There is one entry point:
23
23
 
24
- For example:
25
- ```console
26
- series = TvrageApi::Request::Show.find('buffy')
27
- series.result
28
- => #<TvrageApi::Show ...>
24
+ ```ruby
25
+ client = TvrageApi::Client.new
26
+ ```
27
+
28
+ Search show by name:
29
+
30
+ ```ruby
31
+ client = TvrageApi::Client.new
32
+ client.search.by_name('buffy') # return pure Hash
33
+ client.search.full_by_name('buffy') # return pure Hash
29
34
  ```
30
35
 
31
- * TvrageApi::Request::Search.find(show_name) - return collection of show
32
- * TvrageApi::Request::Search.find_full(show_name) - return collection of show with more details
33
- * TvrageApi::Request::Show.find(show_id) - return show
34
- * TvrageApi::Request::Show.find_full(show_id) - return show with more details
35
- * TvrageApi::Request::Show.episodes(show_id) - return simple show information with all episodes
36
- * TvrageApi::Request::Show.episode(show_id, season, episode) - return simple show information with specific episode
37
- * TvrageApi::Request::Update.all - return all shows (simple information: id, name)
36
+ Search show by id:
38
37
 
38
+ ```ruby
39
+ client = TvrageApi::Client.new
40
+ client.show.find('123') # return pure Hash
41
+ client.show.find_full('123') # return pure Hash
42
+ client.show.episodes('123') # return pure Hash, with all episodes
43
+ client.show.episode('123', season, episode) # return pure Hash, with specific episode
44
+ ```
45
+
46
+ Search all show ids:
47
+
48
+ ```ruby
49
+ client = TvrageApi::Client.new
50
+ client.update.all # return pure Hash
51
+ ```
39
52
 
40
53
  ## Contributing
41
54
 
@@ -1,7 +1,26 @@
1
- require 'hashie'
1
+ require 'httparty'
2
2
 
3
- class TvrageApi::Base < Hashie::Mash
4
- include Hashie::Extensions::MethodAccess
5
- include Hashie::Extensions::KeyReplace
6
- include Hashie::Extensions::Coercion
7
- end
3
+ class TvrageApi::Base
4
+ include HTTParty
5
+
6
+ attr_reader :uri, :options
7
+
8
+ def get(uri, options = {})
9
+ @uri = uri
10
+ @options = options
11
+
12
+ self
13
+ end
14
+
15
+ def response
16
+ response = self.class.get(uri, request_options(options))
17
+ response.code == 200 ? response.parsed_response : nil
18
+ end
19
+
20
+ def request_options(options = {})
21
+ {
22
+ query: options,
23
+ base_uri: 'http://services.tvrage.com/feeds/'
24
+ }
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ class TvrageApi::Client
2
+ def search
3
+ @search ||= TvrageApi::Search.new
4
+ end
5
+
6
+ def show
7
+ @show ||= TvrageApi::Show.new
8
+ end
9
+
10
+ def update
11
+ @show ||= TvrageApi::Update.new
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class TvrageApi::Search < TvrageApi::Base
2
+ def by_name(name)
3
+ get('search.php', show: name).response
4
+ end
5
+
6
+ def full_by_name(name)
7
+ get('full_search.php', show: name).response
8
+ end
9
+ end
@@ -1,22 +1,17 @@
1
1
  class TvrageApi::Show < TvrageApi::Base
2
- replace_key :Episodelist, :episode_list
3
- replace_key :latestepisode, :latest_episode
4
- replace_key :showid, :show_id
5
- replace_key :totalseasons, :total_seasons
2
+ def find(id)
3
+ get('showinfo.php', sid: id).response
4
+ end
6
5
 
7
- coerce_key :id, Integer
8
- coerce_key :akas, AkaArray
9
- coerce_key :ended, DateOrInteger
10
- coerce_key :episode, TvrageApi::Episode
11
- coerce_key :episode_list, EpisodeArray
12
- coerce_key :genres, GenreArray
13
- coerce_key :latest_episode, TvrageApi::Episode
14
- coerce_key :network, TvrageApi::Element
15
- coerce_key :runtime, Integer
16
- coerce_key :seasons, Integer
17
- coerce_key :show_id, Integer
18
- coerce_key :startdate, Date
19
- coerce_key :started, Integer
20
- coerce_key :status, Integer
21
- coerce_key :total_seasons, Integer
6
+ def find_full(id)
7
+ get('full_show_info.php', sid: id).response
8
+ end
9
+
10
+ def episodes(show_id)
11
+ get('episode_list.php', sid: show_id).response
12
+ end
13
+
14
+ def episode(series_id, season, episode)
15
+ get('episodeinfo.php', sid: series_id, ep: "#{season}x#{episode}").response
16
+ end
22
17
  end
@@ -0,0 +1,5 @@
1
+ class TvrageApi::Update < TvrageApi::Base
2
+ def all
3
+ get('show_list.php').response
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module TvrageApi
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/tvrage_api.rb CHANGED
@@ -3,12 +3,8 @@ module TvrageApi
3
3
  end
4
4
 
5
5
  require 'tvrage_api/version'
6
- require 'tvrage_api/utility'
6
+ require 'tvrage_api/client'
7
7
  require 'tvrage_api/base'
8
- require 'tvrage_api/element'
9
- require 'tvrage_api/episode'
8
+ require 'tvrage_api/search'
10
9
  require 'tvrage_api/show'
11
- require 'tvrage_api/request/base'
12
- require 'tvrage_api/request/search'
13
- require 'tvrage_api/request/show'
14
- require 'tvrage_api/request/update'
10
+ require 'tvrage_api/update'
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Client do
4
+ let(:client) { TvrageApi::Client.new }
5
+
6
+ describe 'real request' do
7
+ describe '.search' do
8
+ describe '.by_name' do
9
+ it 'should return Hash class' do
10
+ client.search.by_name('buffy').class.should == Hash
11
+ end
12
+ end
13
+
14
+ describe '.full_by_name' do
15
+ it 'should return show class' do
16
+ client.search.full_by_name('buffy').class.should == Hash
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '.show' do
22
+ describe '.find' do
23
+ it 'should return Hash class' do
24
+ client.show.find('2930').class.should == Hash
25
+ end
26
+ end
27
+
28
+ describe '.find_full' do
29
+ it 'should return Hash class' do
30
+ client.show.find_full('2930').class.should == Hash
31
+ end
32
+ end
33
+
34
+ describe '.episodes' do
35
+ it 'should return show class' do
36
+ client.show.episodes('2930').class.should == Hash
37
+ end
38
+ end
39
+
40
+ describe '.episode' do
41
+ it 'should return show class' do
42
+ client.show.episode('2930', '2', '4').class.should == Hash
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '.update' do
48
+ describe '.all' do
49
+ it 'should return Hash class' do
50
+ client.update.all.class.should == Hash
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe TvrageApi::Request::Search do
4
- let(:klass) { TvrageApi::Request::Search }
3
+ describe TvrageApi::Search do
4
+ let(:model) { TvrageApi::Search.new }
5
5
 
6
6
  describe 'real request' do
7
- describe '#find' do
8
- it 'should return show class' do
9
- klass.find('buffy').result.class.should == Array
7
+ describe '.by_name' do
8
+ it 'should return Hash class' do
9
+ model.by_name('buffy').class.should == Hash
10
10
  end
11
11
  end
12
12
 
13
- describe '#find_full' do
13
+ describe '.full_by_name' do
14
14
  it 'should return show class' do
15
- klass.find_full('buffy').result.class.should == Array
15
+ model.full_by_name('buffy').class.should == Hash
16
16
  end
17
17
  end
18
18
  end
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe TvrageApi::Request::Show do
4
- let(:klass) { TvrageApi::Request::Show }
3
+ describe TvrageApi::Show do
4
+ let(:model) { TvrageApi::Show.new }
5
5
 
6
6
  describe 'real request' do
7
- describe '#find' do
8
- it 'should return show class' do
9
- klass.find('2930').result.class.should == TvrageApi::Show
7
+ describe '.find' do
8
+ it 'should return Hash class' do
9
+ model.find('2930').class.should == Hash
10
10
  end
11
11
  end
12
12
 
13
- describe '#find_full' do
14
- it 'should return show class' do
15
- klass.find_full('2930').result.class.should == TvrageApi::Show
13
+ describe '.find_full' do
14
+ it 'should return Hash class' do
15
+ model.find_full('2930').class.should == Hash
16
16
  end
17
17
  end
18
18
 
19
- describe '#episodes' do
19
+ describe '.episodes' do
20
20
  it 'should return show class' do
21
- klass.episodes('2930').result.class.should == TvrageApi::Show
21
+ model.episodes('2930').class.should == Hash
22
22
  end
23
23
  end
24
24
 
25
- describe '#episode' do
25
+ describe '.episode' do
26
26
  it 'should return show class' do
27
- klass.episode('2930', '2', '4').result.class.should == TvrageApi::Show
27
+ model.episode('2930', '2', '4').class.should == Hash
28
28
  end
29
29
  end
30
30
  end
@@ -1,13 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe TvrageApi::Request::Update do
4
- let(:klass) { TvrageApi::Request::Update }
3
+ describe TvrageApi::Update do
4
+ let(:model) { TvrageApi::Update.new }
5
5
 
6
6
  describe 'real request' do
7
- describe '#find' do
8
- it 'should return show class' do
9
- puts klass.all.result.inspect
10
- # klass.all.result.class.should == Array
7
+ describe '.all' do
8
+ it 'should return Hash class' do
9
+ model.all.class.should == Hash
11
10
  end
12
11
  end
13
12
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ class ExampleRequestClass < TvrageApi::Base
4
+ end
5
+
6
+ describe TvrageApi::Base do
7
+ let(:klass) { ExampleRequestClass }
8
+ let(:model) { klass.new }
9
+
10
+ describe '.get' do
11
+ it 'should set uri' do
12
+ model.get('http://example.com')
13
+
14
+ model.uri.should == 'http://example.com'
15
+ end
16
+
17
+ it 'should set options' do
18
+ model.get('http://example.com', sample_options: true)
19
+
20
+ model.options.should == { sample_options: true }
21
+ end
22
+
23
+ it 'should return self' do
24
+ model.get('http://example.com').should == model
25
+ end
26
+ end
27
+
28
+ describe '.response' do
29
+ it 'should call get klass method' do
30
+ klass.should_receive(:get).and_return(double(code: 200, parsed_response: {}))
31
+ model.stub(:request_options).and_return({})
32
+
33
+ model.response
34
+ end
35
+
36
+ it 'should return Hash' do
37
+ klass.should_receive(:get).and_return(double(code: 200, parsed_response: {}))
38
+ model.stub(:request_options).and_return({})
39
+
40
+ model.response.class.should == Hash
41
+ end
42
+
43
+ it 'should return nil' do
44
+ klass.should_receive(:get).and_return(double(code: 400))
45
+ model.stub(:request_options).and_return({})
46
+
47
+ model.response.should be_nil
48
+ end
49
+ end
50
+
51
+ describe '.request_options' do
52
+ it 'should return correct keys' do
53
+ model.request_options.keys.sort.should == [:query, :base_uri].sort
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Client do
4
+ let(:klass) { TvrageApi::Client }
5
+
6
+ describe '.search' do
7
+ it 'should return search class' do
8
+ klass.new.search.class.should == TvrageApi::Search
9
+ end
10
+ end
11
+
12
+ describe '.show' do
13
+ it 'should return show class' do
14
+ klass.new.show.class.should == TvrageApi::Show
15
+ end
16
+ end
17
+
18
+ describe '.update' do
19
+ it 'should return update class' do
20
+ klass.new.update.class.should == TvrageApi::Update
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Search do
4
+ let(:klass) { TvrageApi::Search }
5
+ let(:model) { klass.new }
6
+
7
+ describe '#find' do
8
+ it 'should call new with specific params' do
9
+ model.should_receive(:get).with('search.php', show: 'buffy').and_return(double(response: true))
10
+
11
+ model.by_name('buffy')
12
+ end
13
+ end
14
+
15
+ describe '#find_full' do
16
+ it 'should call new with specific params' do
17
+ model.should_receive(:get).with('full_search.php', show: 'buffy').and_return(double(response: true))
18
+
19
+ model.full_by_name('buffy')
20
+ end
21
+ end
22
+ end
@@ -2,78 +2,37 @@ require 'spec_helper'
2
2
 
3
3
  describe TvrageApi::Show do
4
4
  let(:klass) { TvrageApi::Show }
5
+ let(:model) { klass.new }
5
6
 
6
- shared_examples 'mapping' do |field, field_mapped|
7
- it "should save as #{field_mapped}" do
8
- klass.new(field => '123').send(field_mapped).should_not == nil
9
- end
10
- end
11
-
12
- shared_examples 'integer mapping' do |field|
13
- it 'should save as Integer' do
14
- klass.new(field => '123').send(field).should == 123
15
- end
16
- end
7
+ describe '#find' do
8
+ it 'should call new with specific params' do
9
+ model.should_receive(:get).with('showinfo.php', sid: 123).and_return(double(response: true))
17
10
 
18
- shared_examples 'date mapping' do |field|
19
- it 'should save as Date' do
20
- klass.new(field => '2000-01-01').send(field).should == Date.new(2000, 1, 1)
11
+ model.find(123)
21
12
  end
22
13
  end
23
14
 
24
- describe 'key mapping' do
25
- describe 'showid attribute' do
26
- include_examples 'mapping', :showid, :show_id
27
- end
28
- end
15
+ describe '#find_full' do
16
+ it 'should call new with specific params' do
17
+ model.should_receive(:get).with('full_show_info.php', sid: 123).and_return(double(response: true))
29
18
 
30
- describe 'key mapping' do
31
- describe 'Episodelist attribute' do
32
- it 'should mapping' do
33
- TvrageApi::Show.new(Episodelist: double(season: [double(episode: [double(to_hash: {})])])).send(:episode_list).should_not == nil
34
- end
35
- end
36
-
37
- describe 'showid attribute' do
38
- include_examples 'mapping', :showid, :show_id
39
- end
40
-
41
- describe 'totalseasons attribute' do
42
- include_examples 'mapping', :totalseasons, :total_seasons
19
+ model.find_full(123)
43
20
  end
44
21
  end
45
22
 
46
- describe 'ceorce' do
47
- describe 'id attribute' do
48
- include_examples 'integer mapping', :id
49
- end
50
-
51
- describe 'runtime attribute' do
52
- include_examples 'integer mapping', :runtime
53
- end
54
-
55
- describe 'seasons attribute' do
56
- include_examples 'integer mapping', :seasons
57
- end
58
-
59
- describe 'show_id attribute' do
60
- include_examples 'integer mapping', :show_id
61
- end
62
-
63
- describe 'startdate attribute' do
64
- include_examples 'date mapping', :startdate
65
- end
23
+ describe '#episodes' do
24
+ it 'should call new with specific params' do
25
+ model.should_receive(:get).with('episode_list.php', sid: 123).and_return(double(response: true))
66
26
 
67
- describe 'started attribute' do
68
- include_examples 'integer mapping', :started
27
+ model.episodes(123)
69
28
  end
29
+ end
70
30
 
71
- describe 'status attribute' do
72
- include_examples 'integer mapping', :status
73
- end
31
+ describe '#episode' do
32
+ it 'should call new with specific params' do
33
+ model.should_receive(:get).with('episodeinfo.php', sid: 123, ep: '1x2').and_return(double(response: true))
74
34
 
75
- describe 'total_seasons attribute' do
76
- include_examples 'integer mapping', :total_seasons
35
+ model.episode(123, 1, 2)
77
36
  end
78
37
  end
79
38
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Update do
4
+ let(:klass) { TvrageApi::Update }
5
+ let(:model) { klass.new }
6
+
7
+ describe '#all' do
8
+ it 'should call new with specific params' do
9
+ model.should_receive(:get).with('show_list.php').and_return(double(response: true))
10
+
11
+ model.all
12
+ end
13
+ end
14
+ end
data/tvrage_api.gemspec CHANGED
@@ -18,8 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'httparty', '>= 0.12.0'
22
- spec.add_runtime_dependency 'hashie', '>= 2.0.5'
21
+ spec.add_runtime_dependency 'httparty', '>= 0.12.0'
23
22
 
24
23
  spec.add_development_dependency 'bundler', '~> 1.3'
25
24
  spec.add_development_dependency 'rake'