tvrage_api 0.0.1

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +45 -0
  7. data/Rakefile +1 -0
  8. data/lib/tvrage_api/base.rb +7 -0
  9. data/lib/tvrage_api/element.rb +3 -0
  10. data/lib/tvrage_api/episode.rb +9 -0
  11. data/lib/tvrage_api/request/base.rb +57 -0
  12. data/lib/tvrage_api/request/search.rb +13 -0
  13. data/lib/tvrage_api/request/show.rb +37 -0
  14. data/lib/tvrage_api/request/update.rb +13 -0
  15. data/lib/tvrage_api/show.rb +22 -0
  16. data/lib/tvrage_api/utility/aka_array.rb +9 -0
  17. data/lib/tvrage_api/utility/date.rb +9 -0
  18. data/lib/tvrage_api/utility/date_or_integer.rb +11 -0
  19. data/lib/tvrage_api/utility/episode_array.rb +15 -0
  20. data/lib/tvrage_api/utility/genre_array.rb +9 -0
  21. data/lib/tvrage_api/utility/hashie/extensions/key_replace.rb +42 -0
  22. data/lib/tvrage_api/utility/integer.rb +5 -0
  23. data/lib/tvrage_api/utility/string.rb +11 -0
  24. data/lib/tvrage_api/utility.rb +8 -0
  25. data/lib/tvrage_api/version.rb +3 -0
  26. data/lib/tvrage_api.rb +14 -0
  27. data/spec/integrations/search_spec.rb +19 -0
  28. data/spec/integrations/show_spec.rb +31 -0
  29. data/spec/integrations/update_spec.rb +14 -0
  30. data/spec/spec_helper.rb +9 -0
  31. data/spec/tvrage_api/episode_spec.rb +51 -0
  32. data/spec/tvrage_api/request/base_spec.rb +113 -0
  33. data/spec/tvrage_api/request/search_spec.rb +30 -0
  34. data/spec/tvrage_api/request/show_spec.rb +71 -0
  35. data/spec/tvrage_api/request/update_spec.rb +28 -0
  36. data/spec/tvrage_api/show_spec.rb +79 -0
  37. data/spec/tvrage_api/utility/aka_array_spec.rb +17 -0
  38. data/spec/tvrage_api/utility/date_or_integer_spec.rb +13 -0
  39. data/spec/tvrage_api/utility/date_spec.rb +13 -0
  40. data/spec/tvrage_api/utility/genre_array_spec.rb +17 -0
  41. data/spec/tvrage_api/utility/integer_spec.rb +9 -0
  42. data/spec/tvrage_api/utility/string_spec.rb +9 -0
  43. data/tvrage_api.gemspec +27 -0
  44. metadata +186 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f7f3211a609b85becf30f672920d512d5b4dbe9
4
+ data.tar.gz: 8d33829ba09d1894e600ea6c95d3a3e65ead62c7
5
+ SHA512:
6
+ metadata.gz: 1bf0a45616930fb2cdde8e8e46f6d12618cbe215f0814a0bc560788a75a2f50ae500a0f5b8be334ea2bafcc2e09bedfc146df5b5f4a3200389b7f79d28bb912d
7
+ data.tar.gz: 6d78c3ece3316fd917727f135ed21f9beb061babe848544a5c8caa5e347289f904e1816f49e13208229ffbeae47a9e550f3a819a49a2d4ac0aa9144b776f877c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ script: 'bundle exec rspec spec/tvrage_api'
3
+ rvm:
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tvrage_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Krzysztof Wawer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ [![Build Status](https://travis-ci.org/wafcio/tvrage_api.png?branch=master)](https://travis-ci.org/wafcio/tvrage_api)
2
+ [![Dependency Status](https://gemnasium.com/wafcio/tvrage_api.png)](https://gemnasium.com/wafcio/tvrage_api)
3
+ [![Code Climate](https://codeclimate.com/github/wafcio/tvrage_api.png)](https://codeclimate.com/github/wafcio/tvrage_api)
4
+ [![Coverage Status](https://coveralls.io/repos/wafcio/tvrage_api/badge.png)](https://coveralls.io/r/wafcio/tvrage_api)
5
+
6
+ # TvrageApi
7
+
8
+ tvrage_api is a simple ruby client for accessing TV shows information from the tvrage.com API.
9
+
10
+ ## Getting started
11
+
12
+ You can add it to your Gemfile with:
13
+
14
+ ```ruby
15
+ gem 'tvrage_api'
16
+ ```
17
+ Run the bundle command to install it.
18
+
19
+ ## How to use
20
+
21
+ All request class return instance where result method contain object or collection.
22
+
23
+ For example:
24
+ ```console
25
+ series = TvrageApi::Request::Show.find('buffy')
26
+ series.result
27
+ => #<TvrageApi::Show ...>
28
+ ```
29
+
30
+ * ThetvdbApi::Request::Search.find(show_name) - return collection of show
31
+ * ThetvdbApi::Request::Search.find_full(show_name) - return collection of show with more details
32
+ * ThetvdbApi::Request::Show.find(show_id) - return show
33
+ * ThetvdbApi::Request::Show.find_full(show_id) - return show with more details
34
+ * ThetvdbApi::Request::Show.episodes(show_id) - return simple show information with all episodes
35
+ * ThetvdbApi::Request::Show.episode(show_id, season, episode) - return simple show information with specific episode
36
+ * ThetvdbApi::Request::Update.all - return all shows (simple information: id, name)
37
+
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ require 'hashie'
2
+
3
+ class TvrageApi::Base < Hashie::Mash
4
+ include Hashie::Extensions::MethodAccess
5
+ include Hashie::Extensions::KeyReplace
6
+ include Hashie::Extensions::Coercion
7
+ end
@@ -0,0 +1,3 @@
1
+ class TvrageApi::Element < TvrageApi::Base
2
+ replace_key :__content__, :content
3
+ end
@@ -0,0 +1,9 @@
1
+ class TvrageApi::Episode < TvrageApi::Base
2
+ replace_key :epnum, :episode_number
3
+ replace_key :seasonnum, :season_number
4
+ replace_key :prodnum, :production_number
5
+
6
+ coerce_key :airdate, Date
7
+ coerce_key :episode_number, Integer
8
+ coerce_key :season_number, Integer
9
+ end
@@ -0,0 +1,57 @@
1
+ require 'httparty'
2
+
3
+ class TvrageApi::Request::Base
4
+ include HTTParty
5
+
6
+ attr_reader :uri
7
+
8
+ def initialize(uri, options = {})
9
+ @uri = uri
10
+ @options = options
11
+ end
12
+
13
+ def response
14
+ @response ||= self.class.get(uri, request_options)
15
+ end
16
+
17
+ def request_options
18
+ {
19
+ query: @options,
20
+ base_uri: 'http://services.tvrage.com/feeds/'
21
+ }
22
+ end
23
+
24
+ def collection_response(key, klass)
25
+ response_condition? ? array_mapped(klass, key) : []
26
+ end
27
+
28
+ def object_response(key, klass)
29
+ response_condition? ? klass.new(data[key]) : nil
30
+ end
31
+
32
+ def response_condition?
33
+ response.code == 200 && data.is_a?(Hash)
34
+ end
35
+
36
+ def array_normalize(key)
37
+ dig(key).is_a?(Array) ? dig(key) : [dig(key)]
38
+ end
39
+
40
+ def array_mapped(klass, key)
41
+ array_normalize(key).map { |data| klass.new(data) }
42
+ end
43
+
44
+ def dig(key)
45
+ data[key]
46
+ end
47
+
48
+ def data
49
+ response[data_key]
50
+ end
51
+
52
+ private
53
+
54
+ def data_key
55
+ 'Results'
56
+ end
57
+ end
@@ -0,0 +1,13 @@
1
+ class TvrageApi::Request::Search < TvrageApi::Request::Base
2
+ def self.find(name)
3
+ new('search.php', show: name)
4
+ end
5
+
6
+ def self.find_full(name)
7
+ new('full_search.php', show: name)
8
+ end
9
+
10
+ def result
11
+ collection_response('show', TvrageApi::Show)
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ class TvrageApi::Request::Show < TvrageApi::Request::Base
2
+ def self.find(id)
3
+ new('showinfo.php', :simple, sid: id)
4
+ end
5
+
6
+ def self.find_full(id)
7
+ new('full_show_info.php', :full, sid: id)
8
+ end
9
+
10
+ def self.episodes(id)
11
+ new('episode_list.php', :full, sid: id)
12
+ end
13
+
14
+ def self.episode(series_id, season, episode)
15
+ new('episodeinfo.php', :episode, sid: series_id, ep: "#{season}x#{episode}")
16
+ end
17
+
18
+ def initialize(uri, kind, options = {})
19
+ @kind = kind
20
+ super(uri, options)
21
+ end
22
+
23
+ def result
24
+ @result ||= case @kind
25
+ when :simple
26
+ object_response('Showinfo', TvrageApi::Show)
27
+ when :full
28
+ object_response('Show', TvrageApi::Show)
29
+ when :episode
30
+ object_response('show', TvrageApi::Show)
31
+ end
32
+ end
33
+
34
+ def data
35
+ response
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ class TvrageApi::Request::Update < TvrageApi::Request::Base
2
+ def self.all
3
+ new('show_list.php')
4
+ end
5
+
6
+ def result
7
+ collection_response('show', TvrageApi::Show)
8
+ end
9
+
10
+ def data_key
11
+ 'shows'
12
+ end
13
+ end
@@ -0,0 +1,22 @@
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
6
+
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
22
+ end
@@ -0,0 +1,9 @@
1
+ class AkaArray
2
+ def self.coerce(value)
3
+ if value.is_a?(Array)
4
+ value
5
+ else
6
+ value.aka.map{ |aka| TvrageApi::Element.new(content: aka.__content__, country: aka.country) }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class Date
2
+ def self.coerce(value)
3
+ begin
4
+ Date.parse(value)
5
+ rescue => e
6
+ nil
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class DateOrInteger
2
+ def self.coerce(value)
3
+ if value.is_a?(String)
4
+ if value.match('/')
5
+ Date.parse(value)
6
+ else
7
+ value.to_i
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class EpisodeArray
2
+ def self.coerce(value)
3
+ episodes = []
4
+
5
+ if value.respond_to?(:season)
6
+ value.season.each do |season|
7
+ season.episode.each do |episode|
8
+ episodes << TvrageApi::Episode.new(episode.to_hash)
9
+ end
10
+ end
11
+ end
12
+
13
+ episodes
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class GenreArray
2
+ def self.coerce(value)
3
+ if value.is_a?(Array)
4
+ value
5
+ else
6
+ value.genre
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ module Hashie
2
+ module Extensions
3
+ module KeyReplace
4
+ def self.included(base)
5
+ base.send :extend, ClassMethods
6
+ end
7
+
8
+ def initialize(source_hash = nil, default = nil, &blk)
9
+ source_hash = replace_keys(source_hash)
10
+ super
11
+ end
12
+
13
+ def replace_keys(source_hash)
14
+ source_hash.keys.each do |key|
15
+ new_key = self.class.key_replace(key) || key.to_s.underscore
16
+
17
+ if new_key != key
18
+ source_hash[new_key] = source_hash[key]
19
+ source_hash.delete(key)
20
+ end
21
+ end
22
+ source_hash
23
+ end
24
+
25
+ module ClassMethods
26
+ def replace_key(*attrs)
27
+ @key_replaces ||= {}
28
+ into = attrs.pop
29
+ attrs.each { |key| @key_replaces[key] = into }
30
+ end
31
+
32
+ def key_replaces
33
+ @key_replaces || {}
34
+ end
35
+
36
+ def key_replace(key)
37
+ key_replaces[key.to_sym]
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def self.coerce(value)
3
+ value.to_i
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class String
2
+ def underscore
3
+ word = self.dup
4
+ word.gsub!(/::/, '/')
5
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
6
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
7
+ word.tr!("-", "_")
8
+ word.downcase!
9
+ word
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require 'tvrage_api/utility/aka_array'
2
+ require 'tvrage_api/utility/date'
3
+ require 'tvrage_api/utility/date_or_integer'
4
+ require 'tvrage_api/utility/episode_array'
5
+ require 'tvrage_api/utility/genre_array'
6
+ require 'tvrage_api/utility/integer'
7
+ require 'tvrage_api/utility/string'
8
+ require 'tvrage_api/utility/hashie/extensions/key_replace'
@@ -0,0 +1,3 @@
1
+ module TvrageApi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tvrage_api.rb ADDED
@@ -0,0 +1,14 @@
1
+ module TvrageApi
2
+ module Request; end
3
+ end
4
+
5
+ require 'tvrage_api/version'
6
+ require 'tvrage_api/utility'
7
+ require 'tvrage_api/base'
8
+ require 'tvrage_api/element'
9
+ require 'tvrage_api/episode'
10
+ 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'
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Request::Search do
4
+ let(:klass) { TvrageApi::Request::Search }
5
+
6
+ describe 'real request' do
7
+ describe '#find' do
8
+ it 'should return show class' do
9
+ klass.find('buffy').result.class.should == Array
10
+ end
11
+ end
12
+
13
+ describe '#find_full' do
14
+ it 'should return show class' do
15
+ klass.find_full('buffy').result.class.should == Array
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Request::Show do
4
+ let(:klass) { TvrageApi::Request::Show }
5
+
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
10
+ end
11
+ end
12
+
13
+ describe '#find_full' do
14
+ it 'should return show class' do
15
+ klass.find_full('2930').result.class.should == TvrageApi::Show
16
+ end
17
+ end
18
+
19
+ describe '#episodes' do
20
+ it 'should return show class' do
21
+ klass.episodes('2930').result.class.should == TvrageApi::Show
22
+ end
23
+ end
24
+
25
+ describe '#episode' do
26
+ it 'should return show class' do
27
+ klass.episode('2930', '2', '4').result.class.should == TvrageApi::Show
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Request::Update do
4
+ let(:klass) { TvrageApi::Request::Update }
5
+
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
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ require 'tvrage_api'
7
+
8
+ RSpec.configure do |config|
9
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Episode do
4
+ let(:klass) { TvrageApi::Episode }
5
+
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
17
+
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)
21
+ end
22
+ end
23
+
24
+ describe 'key mapping' do
25
+ describe 'epnum attribute' do
26
+ include_examples 'mapping', :epnum, :episode_number
27
+ end
28
+
29
+ describe 'seasonnum attribute' do
30
+ include_examples 'mapping', :seasonnum, :season_number
31
+ end
32
+
33
+ describe 'prodnum attribute' do
34
+ include_examples 'mapping', :prodnum, :production_number
35
+ end
36
+ end
37
+
38
+ describe 'ceorce' do
39
+ describe 'airdate attribute' do
40
+ include_examples 'date mapping', :airdate
41
+ end
42
+
43
+ describe 'episode_number attribute' do
44
+ include_examples 'integer mapping', :episode_number
45
+ end
46
+
47
+ describe 'season_number attribute' do
48
+ include_examples 'integer mapping', :season_number
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ class ExampleRequestClass < TvrageApi::Request::Base
4
+ end
5
+
6
+ describe TvrageApi::Request::Base do
7
+ let(:klass) { ExampleRequestClass }
8
+ let(:model) { klass.new('test') }
9
+
10
+ describe '#response' do
11
+ it 'should call get klass method' do
12
+ klass.should_receive(:get)
13
+ model.stub(:request_options).and_return({})
14
+
15
+ model.response
16
+ end
17
+ end
18
+
19
+ describe '#request_options' do
20
+ it 'should return correct keys' do
21
+ model.request_options.keys.sort.should == [:query, :base_uri].sort
22
+ end
23
+ end
24
+
25
+ describe '#collection_response' do
26
+ it 'should return filled array when condition is true' do
27
+ model.stub(:response_condition?).and_return(true)
28
+ model.stub(:array_mapped).and_return(['test'])
29
+
30
+ model.collection_response('Series', OpenStruct).should_not be_empty
31
+ end
32
+
33
+ it 'should return empty array when condition is false' do
34
+ model.stub(:response_condition?).and_return(false)
35
+
36
+ model.collection_response('Series', OpenStruct).should be_empty
37
+ end
38
+ end
39
+
40
+ describe '#object_response' do
41
+ it 'should return object when condition is true' do
42
+ model.stub(:response_condition?).and_return(true)
43
+ model.stub_chain(:response, :[]).and_return({})
44
+
45
+ model.object_response('Series', OpenStruct).class.should == OpenStruct
46
+ end
47
+
48
+ it 'should return nil when condition is false' do
49
+ model.stub(:response_condition?).and_return(false)
50
+
51
+ model.object_response('Series', OpenStruct).should be_nil
52
+ end
53
+ end
54
+
55
+ describe '#response_condition?' do
56
+ it 'should return true when code is 200 and return Data hash' do
57
+ model.stub_chain(:response, :code).and_return 200
58
+ model.stub_chain(:response, :[]).and_return({})
59
+
60
+ model.response_condition?.should be_true
61
+ end
62
+
63
+ it 'should return false when code is different than 200' do
64
+ model.stub_chain(:response, :code).and_return 400
65
+ model.stub_chain(:response, :[]).and_return({})
66
+
67
+ model.response_condition?.should be_false
68
+ end
69
+
70
+ it 'should return false when return blank response' do
71
+ model.stub_chain(:response, :code).and_return 200
72
+ model.stub_chain(:response, :[]).and_return('')
73
+
74
+ model.response_condition?.should be_false
75
+ end
76
+ end
77
+
78
+ describe '#array_normalize' do
79
+ it 'should return Array when dig return Array' do
80
+ model.stub(:dig).and_return(Array)
81
+ model.array_normalize('Series').class.should == Array
82
+ end
83
+
84
+ it 'should return Array when dig return Hash' do
85
+ model.stub(:dig).and_return(Hash)
86
+ model.array_normalize('Series').class.should == Array
87
+ end
88
+ end
89
+
90
+ describe '#array_mapped' do
91
+ it 'should map Array elements to objects' do
92
+ model.stub(:array_normalize).and_return([{ 'test' => 'value' }])
93
+ model.array_mapped(OpenStruct, 'Series').first.class.should == OpenStruct
94
+ end
95
+ end
96
+
97
+ describe '#dig' do
98
+ it 'should dig to correct hash' do
99
+ model.stub(:response).and_return({ 'Results' => { 'Series' => 'series value' } })
100
+
101
+ model.dig('Series').should == 'series value'
102
+ end
103
+ end
104
+
105
+ describe '#data' do
106
+ it 'should return correct value' do
107
+ model.stub(:response).and_return({ 'key' => 'value' })
108
+ model.stub(:data_key).and_return('key')
109
+
110
+ model.data.should == 'value'
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Request::Search do
4
+ let(:klass) { TvrageApi::Request::Search }
5
+ let(:model) { klass.new('http://example.com', name: 'buffy') }
6
+
7
+ describe '#find' do
8
+ it 'should call new with specific params' do
9
+ klass.should_receive(:new).with('search.php', show: 'buffy')
10
+
11
+ klass.find('buffy')
12
+ end
13
+ end
14
+
15
+ describe '#find_full' do
16
+ it 'should call new with specific params' do
17
+ klass.should_receive(:new).with('full_search.php', show: 'buffy')
18
+
19
+ klass.find_full('buffy')
20
+ end
21
+ end
22
+
23
+ describe '#result' do
24
+ it 'should call collection_response method' do
25
+ model.should_receive(:collection_response)
26
+
27
+ model.result
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Request::Show do
4
+ let(:klass) { TvrageApi::Request::Show }
5
+ let(:kind) { :simple }
6
+ let(:model) { klass.new('http://example.com', kind, sid: 123) }
7
+
8
+ describe '#find' do
9
+ it 'should call new with specific params' do
10
+ klass.should_receive(:new).with('showinfo.php', :simple, sid: 123)
11
+
12
+ klass.find(123)
13
+ end
14
+ end
15
+
16
+ describe '#find_full' do
17
+ it 'should call new with specific params' do
18
+ klass.should_receive(:new).with('full_show_info.php', :full, sid: 123)
19
+
20
+ klass.find_full(123)
21
+ end
22
+ end
23
+
24
+ describe '#episodes' do
25
+ it 'should call new with specific params' do
26
+ klass.should_receive(:new).with('episode_list.php', :full, sid: 123)
27
+
28
+ klass.episodes(123)
29
+ end
30
+ end
31
+
32
+ describe '#episode' do
33
+ it 'should call new with specific params' do
34
+ klass.should_receive(:new).with('episodeinfo.php', :episode, sid: 123, ep: '1x2')
35
+
36
+ klass.episode(123, 1, 2)
37
+ end
38
+ end
39
+
40
+ describe '#result' do
41
+ describe 'when kind is simple' do
42
+ let(:kind) { :simple }
43
+
44
+ it 'should call collection_response method' do
45
+ model.should_receive(:object_response).with('Showinfo', TvrageApi::Show)
46
+
47
+ model.result
48
+ end
49
+ end
50
+
51
+ describe 'when kind is full' do
52
+ let(:kind) { :full }
53
+
54
+ it 'should call collection_response method' do
55
+ model.should_receive(:object_response).with('Show', TvrageApi::Show)
56
+
57
+ model.result
58
+ end
59
+ end
60
+
61
+ describe 'when kind is episode' do
62
+ let(:kind) { :episode }
63
+
64
+ it 'should call collection_response method' do
65
+ model.should_receive(:object_response).with('show', TvrageApi::Show)
66
+
67
+ model.result
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Request::Update do
4
+ let(:klass) { TvrageApi::Request::Update }
5
+ let(:model) { klass.new('http://example.com') }
6
+
7
+ describe '#all' do
8
+ it 'should call new with specific params' do
9
+ klass.should_receive(:new).with('show_list.php')
10
+
11
+ klass.all
12
+ end
13
+ end
14
+
15
+ describe '#result' do
16
+ it 'should call collection_response method' do
17
+ model.should_receive(:collection_response)
18
+
19
+ model.result
20
+ end
21
+ end
22
+
23
+ describe '#data_key' do
24
+ it 'should return correct value' do
25
+ model.data_key.should == 'shows'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe TvrageApi::Show do
4
+ let(:klass) { TvrageApi::Show }
5
+
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
17
+
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)
21
+ end
22
+ end
23
+
24
+ describe 'key mapping' do
25
+ describe 'showid attribute' do
26
+ include_examples 'mapping', :showid, :show_id
27
+ end
28
+ end
29
+
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
43
+ end
44
+ end
45
+
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
66
+
67
+ describe 'started attribute' do
68
+ include_examples 'integer mapping', :started
69
+ end
70
+
71
+ describe 'status attribute' do
72
+ include_examples 'integer mapping', :status
73
+ end
74
+
75
+ describe 'total_seasons attribute' do
76
+ include_examples 'integer mapping', :total_seasons
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe AkaArray do
4
+ describe '#coerce' do
5
+ describe 'when value is Array' do
6
+ it 'should return Array' do
7
+ AkaArray.coerce([]).should == []
8
+ end
9
+ end
10
+
11
+ describe 'when value is not Array' do
12
+ it 'should return Array' do
13
+ AkaArray.coerce(double(aka: [double(country: 'EN', __content__: 'test')])).first.class.should == TvrageApi::Element
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe DateOrInteger do
4
+ describe '#coerce' do
5
+ it 'should convert string to date' do
6
+ DateOrInteger.coerce('2001/02/03').should == Date.new(2001, 2, 3)
7
+ end
8
+
9
+ it 'should return integer for no date string' do
10
+ DateOrInteger.coerce('2000').should == 2000
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Date do
4
+ describe '#coerce' do
5
+ it 'should convert string to date' do
6
+ Date.coerce('2001-02-03').should == Date.new(2001, 2, 3)
7
+ end
8
+
9
+ it 'should return nil for no date string' do
10
+ Date.coerce('test').should == nil
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe GenreArray do
4
+ describe '#coerce' do
5
+ describe 'when value is Array' do
6
+ it 'should return Array' do
7
+ GenreArray.coerce([]).should == []
8
+ end
9
+ end
10
+
11
+ describe 'when value is not Array' do
12
+ it 'should return Array' do
13
+ GenreArray.coerce(double(genre: 'Action')).should == 'Action'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Integer do
4
+ describe '#coerce' do
5
+ it 'should convert string to integer' do
6
+ Integer.coerce('1234').should == 1234
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+ describe '#underscore' do
5
+ it 'should convert camelCase to underscore' do
6
+ 'methodName'.underscore.should == 'method_name'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tvrage_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tvrage_api'
8
+ spec.version = TvrageApi::VERSION
9
+ spec.authors = ['Krzysztof Wawer']
10
+ spec.email = ['krzysztof.wawer@gmail.com']
11
+ spec.description = %q{Ruby client for accessing TV shows information from the tvrage.com API}
12
+ spec.summary = %q{Ruby client for tvrage.com API}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'httparty', '>= 0.12.0'
21
+ spec.add_runtime_dependency 'hashie', '>= 2.0.5'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec', '>= 2.14.1'
26
+ spec.add_development_dependency 'coveralls', '>= 0.7'
27
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tvrage_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Krzysztof Wawer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-06 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.12.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.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.14.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.14.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0.7'
97
+ description: Ruby client for accessing TV shows information from the tvrage.com API
98
+ email:
99
+ - krzysztof.wawer@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - lib/tvrage_api.rb
111
+ - lib/tvrage_api/base.rb
112
+ - lib/tvrage_api/element.rb
113
+ - lib/tvrage_api/episode.rb
114
+ - lib/tvrage_api/request/base.rb
115
+ - lib/tvrage_api/request/search.rb
116
+ - lib/tvrage_api/request/show.rb
117
+ - lib/tvrage_api/request/update.rb
118
+ - lib/tvrage_api/show.rb
119
+ - lib/tvrage_api/utility.rb
120
+ - lib/tvrage_api/utility/aka_array.rb
121
+ - lib/tvrage_api/utility/date.rb
122
+ - lib/tvrage_api/utility/date_or_integer.rb
123
+ - lib/tvrage_api/utility/episode_array.rb
124
+ - lib/tvrage_api/utility/genre_array.rb
125
+ - lib/tvrage_api/utility/hashie/extensions/key_replace.rb
126
+ - lib/tvrage_api/utility/integer.rb
127
+ - lib/tvrage_api/utility/string.rb
128
+ - lib/tvrage_api/version.rb
129
+ - spec/integrations/search_spec.rb
130
+ - spec/integrations/show_spec.rb
131
+ - spec/integrations/update_spec.rb
132
+ - spec/spec_helper.rb
133
+ - spec/tvrage_api/episode_spec.rb
134
+ - spec/tvrage_api/request/base_spec.rb
135
+ - spec/tvrage_api/request/search_spec.rb
136
+ - spec/tvrage_api/request/show_spec.rb
137
+ - spec/tvrage_api/request/update_spec.rb
138
+ - spec/tvrage_api/show_spec.rb
139
+ - spec/tvrage_api/utility/aka_array_spec.rb
140
+ - spec/tvrage_api/utility/date_or_integer_spec.rb
141
+ - spec/tvrage_api/utility/date_spec.rb
142
+ - spec/tvrage_api/utility/genre_array_spec.rb
143
+ - spec/tvrage_api/utility/integer_spec.rb
144
+ - spec/tvrage_api/utility/string_spec.rb
145
+ - tvrage_api.gemspec
146
+ homepage:
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.0.0
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Ruby client for tvrage.com API
170
+ test_files:
171
+ - spec/integrations/search_spec.rb
172
+ - spec/integrations/show_spec.rb
173
+ - spec/integrations/update_spec.rb
174
+ - spec/spec_helper.rb
175
+ - spec/tvrage_api/episode_spec.rb
176
+ - spec/tvrage_api/request/base_spec.rb
177
+ - spec/tvrage_api/request/search_spec.rb
178
+ - spec/tvrage_api/request/show_spec.rb
179
+ - spec/tvrage_api/request/update_spec.rb
180
+ - spec/tvrage_api/show_spec.rb
181
+ - spec/tvrage_api/utility/aka_array_spec.rb
182
+ - spec/tvrage_api/utility/date_or_integer_spec.rb
183
+ - spec/tvrage_api/utility/date_spec.rb
184
+ - spec/tvrage_api/utility/genre_array_spec.rb
185
+ - spec/tvrage_api/utility/integer_spec.rb
186
+ - spec/tvrage_api/utility/string_spec.rb