memo_rage 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ module MemoRage
6
6
  end
7
7
 
8
8
  def parse
9
- parse_content @content
9
+ parse_content
10
10
  end
11
11
 
12
12
  def form_array(entry)
@@ -6,14 +6,12 @@ module MemoRage
6
6
  end
7
7
 
8
8
  def method_missing(sym, *args)
9
- @entry.elements.map { |e| e.has_name?(sym.to_s) }.include?(true) ? @entry.elements[sym.to_s].text : ""
9
+ @entry.at(sym.to_s).try(:text)
10
10
  end
11
11
 
12
12
  def to_array(name)
13
- return [] unless @entry.elements[name.to_s]
14
- @entry.elements[name.to_s].elements.collect do |text|
15
- text.text
16
- end
13
+ return [] unless record = @entry.at(name.to_s)
14
+ record.elements.map(&:text)
17
15
  end
18
16
  end
19
17
  end
@@ -1,43 +1,30 @@
1
1
  module MemoRage
2
2
  module Parser
3
3
  class EpisodeList < Base
4
- def parse_content(content)
5
- doc = REXML::Document.new(content.body)
6
- list = doc.elements["Show"]
7
-
8
- unless list == "0"
9
- parse_entry(list)
10
- end
11
- end
12
-
13
- def parse_entry(entry)
14
- episodes = []
15
-
16
- if entry.elements["Episodelist"]
17
- entry.elements["Episodelist"].elements.each("Season") do |season|
18
- season.elements.each("episode") do |episode|
19
- episode = MemoRage::Parser::Entry.new(episode)
20
- episodes << MemoRage::Episode.new(
21
- :id => episode.link.match(/[0-9]+$/).to_a.first.to_i,
22
- :num => episode.epnum,
23
- :season => season.attributes["no"].to_i,
24
- :season_num => episode.seasonnum,
25
- :prod_num => episode.prodnum,
26
- :airdate => episode.airdate,
27
- :link => episode.link,
28
- :title => episode.title,
29
- :rating => episode.rating,
30
- :image => episode.screencap
31
- )
32
- end
33
- end
4
+ def parse_content
5
+ @episodes = []
6
+ doc = Nokogiri::XML(@content.body)
7
+ doc.xpath('//Show//Episodelist//Season//episode').each do |record|
8
+ season = record.parent.at("@no").text.to_i
9
+ episode = Entry.new(record)
10
+ @episodes << MemoRage::Episode.new(
11
+ :id => episode.link.match(/[0-9]+$/).to_a.first.to_i,
12
+ :num => episode.epnum,
13
+ :season => season,
14
+ :season_num => episode.seasonnum.try(:to_i),
15
+ :prod_num => episode.prodnum,
16
+ :airdate => episode.airdate,
17
+ :link => episode.link,
18
+ :title => episode.title,
19
+ :rating => episode.rating,
20
+ :image => episode.screencap
21
+ )
34
22
  end
35
23
 
36
- entry = MemoRage::Parser::Entry.new(entry)
37
24
  MemoRage::Show.new(
38
- :name => entry.name,
39
- :seasons => entry.totalseasons.to_i,
40
- :episodes => episodes
25
+ :name => doc.at('//Show//name').text,
26
+ :seasons => doc.at('//Show//totalseasons').text.to_i,
27
+ :episodes => @episodes
41
28
  )
42
29
  end
43
30
  end
@@ -1,18 +1,13 @@
1
1
  module MemoRage
2
2
  module Parser
3
3
  class ShowInfo < Base
4
- def parse_content(content)
5
- doc = REXML::Document.new(content.body)
6
- showinfo = doc.elements["Showinfo"]
7
-
8
- unless showinfo == "0"
9
- parse_entry(showinfo)
10
- end
11
- end
12
-
13
- def parse_entry(entry)
14
- entry = MemoRage::Parser::Entry.new(entry)
15
- MemoRage::Show.new(
4
+ def parse_content
5
+ doc = Nokogiri::XML(@content.body)
6
+ result = doc.at("Showinfo")
7
+ return nil if result.blank? || result.text.blank?
8
+
9
+ entry = MemoRage::Parser::Entry.new(result)
10
+ show = MemoRage::Show.new(
16
11
  :id => entry.showid.to_i,
17
12
  :name => entry.showname,
18
13
  :link => entry.showlink,
@@ -30,7 +25,6 @@ module MemoRage
30
25
  :timezone => entry.timezone
31
26
  )
32
27
  end
33
-
34
28
  end
35
29
  end
36
30
  end
@@ -1,26 +1,15 @@
1
1
  module MemoRage
2
2
  module Parser
3
3
  class ShowSearch < Base
4
- def parse_content(content)
5
- doc = REXML::Document.new(content.body)
6
- results = doc.elements["Results"]
7
-
8
- shows = []
9
- unless results == "0"
10
- results.elements.each("show") do |show|
11
- shows << parse_entry(show)
12
- end
4
+ def parse_content
5
+ doc = Nokogiri::XML(@content.body)
6
+ doc.xpath("//Results//show").collect do |entry|
7
+ entry = MemoRage::Parser::Entry.new(entry)
8
+ MemoRage::Show.new(
9
+ :id => entry.showid.to_i,
10
+ :name => entry.name
11
+ )
13
12
  end
14
-
15
- shows
16
- end
17
-
18
- def parse_entry(entry)
19
- entry = MemoRage::Parser::Entry.new(entry)
20
- MemoRage::Show.new(
21
- :id => entry.showid.to_i,
22
- :name => entry.name
23
- )
24
13
  end
25
14
  end
26
15
  end
@@ -1,3 +1,3 @@
1
1
  module MemoRage
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/memo_rage.rb CHANGED
@@ -1,5 +1,8 @@
1
+ require "nokogiri"
1
2
  require "httpclient"
2
- require "rexml/document"
3
+ require "active_support/core_ext/object/try"
4
+ require "active_support/core_ext/object/blank"
5
+
3
6
  require "memo_rage/version"
4
7
 
5
8
  module MemoRage
data/memo_rage.gemspec CHANGED
@@ -17,10 +17,13 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
- s.add_runtime_dependency "httpclient", ">= 2.2.0.2"
21
- s.add_runtime_dependency "hashie", ">= 1.1.0"
22
- s.add_development_dependency "rake", ">= 0.8.7"
23
- s.add_development_dependency "rspec", ">= 2"
24
- s.add_development_dependency "webmock", ">= 1.6.2"
25
- s.add_development_dependency "timecop", ">= 0.3.5"
20
+
21
+ s.add_runtime_dependency "nokogiri", "~> 1.5"
22
+ s.add_runtime_dependency "httpclient", "~> 2.0"
23
+ s.add_runtime_dependency "activesupport", "~> 3.0"
24
+
25
+ s.add_development_dependency "pry"
26
+ s.add_development_dependency "rake"
27
+ s.add_development_dependency "rspec", "~> 2.0"
28
+ s.add_development_dependency "webmock", "~> 1.6"
26
29
  end
@@ -11,6 +11,7 @@ describe MemoRage::Parser::EpisodeList do
11
11
  list.episodes.last.tap do |episode|
12
12
  episode.id.should == 28220
13
13
  episode.season.should == 7
14
+ episode.season_num.should == 22
14
15
  end
15
16
  end
16
17
  end
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
-
3
2
  require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
4
3
 
5
4
  describe MemoRage::Parser::ShowInfo do
@@ -26,11 +25,18 @@ describe MemoRage::Parser::ShowInfo do
26
25
  end
27
26
  end
28
27
 
29
- it 'should handle empty/missing show info' do
30
- mock_api :get, 'showinfo', 'show_info_empty', :params => client.params.merge(:sid => "22303") do
28
+ it 'should handle incomplete show info' do
29
+ mock_api :get, 'showinfo', 'show_info_incomplete', :params => client.params.merge(:sid => "22303") do
31
30
  show = client.show_info("22303")
32
31
  show.genres.should == []
33
32
  end
34
33
  end
34
+
35
+ it 'should handle empty show info' do
36
+ mock_api :get, 'showinfo', 'show_info_empty', :params => client.params.merge(:sid => "9999999") do
37
+ show = client.show_info("9999999")
38
+ show.should be_nil
39
+ end
40
+ end
35
41
  end
36
42
 
@@ -10,4 +10,10 @@ describe MemoRage::Parser::ShowSearch do
10
10
  show.name.should == "Buffy the Vampire Slayer"
11
11
  end
12
12
  end
13
+
14
+ it 'should handle empty result set' do
15
+ mock_api :get, 'search', 'show_search_empty', :params => client.params.merge(:show => "yolo") do
16
+ client.search("yolo").should be_empty
17
+ end
18
+ end
13
19
  end
@@ -1,20 +1,5 @@
1
+
1
2
  <?xml version="1.0" encoding="UTF-8" ?>
2
3
 
3
4
  <Showinfo>
4
- <showid>22303</showid>
5
- <showname>Alcatraz: The Whole Shocking Story</showname>
6
- <showlink>http://www.tvrage.com/shows/id-22303</showlink>
7
- <seasons>1</seasons>
8
- <image>http://images.tvrage.com/shows/23/22303.jpg</image>
9
- <started>1980</started>
10
- <startdate>Nov/05/1980</startdate>
11
-
12
- <ended>Nov/06/1980</ended>
13
- <origin_country>US</origin_country>
14
- <status>Canceled/Ended</status>
15
- <classification>Mini-Series</classification>
16
- <runtime>240</runtime>
17
- <network country="US">NBC</network>
18
- <airtime>12:00</airtime>
19
- <timezone>GMT-5 +DST</timezone>
20
- </Showinfo>
5
+ </Showinfo>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+
3
+ <Showinfo>
4
+ <showid>22303</showid>
5
+ <showname>Alcatraz: The Whole Shocking Story</showname>
6
+ <showlink>http://www.tvrage.com/shows/id-22303</showlink>
7
+ <seasons>1</seasons>
8
+ <image>http://images.tvrage.com/shows/23/22303.jpg</image>
9
+ <started>1980</started>
10
+ <startdate>Nov/05/1980</startdate>
11
+
12
+ <ended>Nov/06/1980</ended>
13
+ <origin_country>US</origin_country>
14
+ <status>Canceled/Ended</status>
15
+ <classification>Mini-Series</classification>
16
+ <runtime>240</runtime>
17
+ <network country="US">NBC</network>
18
+ <airtime>12:00</airtime>
19
+ <timezone>GMT-5 +DST</timezone>
20
+ </Showinfo>
@@ -0,0 +1,4 @@
1
+
2
+ <?xml version="1.0" encoding="UTF-8" ?>
3
+
4
+ <Results>0</Results>
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
+ require 'pry'
4
5
  require 'rspec'
5
- require 'timecop'
6
6
  require 'memo_rage'
7
7
  require 'helpers/webmock_helper'
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.before(:each) do
11
- Timecop.return
11
+ # Do nothing
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memo_rage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,48 +10,64 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-22 00:00:00.000000000Z
13
+ date: 2012-06-12 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.5'
15
31
  - !ruby/object:Gem::Dependency
16
32
  name: httpclient
17
33
  requirement: !ruby/object:Gem::Requirement
18
34
  none: false
19
35
  requirements:
20
- - - ! '>='
36
+ - - ~>
21
37
  - !ruby/object:Gem::Version
22
- version: 2.2.0.2
38
+ version: '2.0'
23
39
  type: :runtime
24
40
  prerelease: false
25
41
  version_requirements: !ruby/object:Gem::Requirement
26
42
  none: false
27
43
  requirements:
28
- - - ! '>='
44
+ - - ~>
29
45
  - !ruby/object:Gem::Version
30
- version: 2.2.0.2
46
+ version: '2.0'
31
47
  - !ruby/object:Gem::Dependency
32
- name: hashie
48
+ name: activesupport
33
49
  requirement: !ruby/object:Gem::Requirement
34
50
  none: false
35
51
  requirements:
36
- - - ! '>='
52
+ - - ~>
37
53
  - !ruby/object:Gem::Version
38
- version: 1.1.0
54
+ version: '3.0'
39
55
  type: :runtime
40
56
  prerelease: false
41
57
  version_requirements: !ruby/object:Gem::Requirement
42
58
  none: false
43
59
  requirements:
44
- - - ! '>='
60
+ - - ~>
45
61
  - !ruby/object:Gem::Version
46
- version: 1.1.0
62
+ version: '3.0'
47
63
  - !ruby/object:Gem::Dependency
48
- name: rake
64
+ name: pry
49
65
  requirement: !ruby/object:Gem::Requirement
50
66
  none: false
51
67
  requirements:
52
68
  - - ! '>='
53
69
  - !ruby/object:Gem::Version
54
- version: 0.8.7
70
+ version: '0'
55
71
  type: :development
56
72
  prerelease: false
57
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -59,15 +75,15 @@ dependencies:
59
75
  requirements:
60
76
  - - ! '>='
61
77
  - !ruby/object:Gem::Version
62
- version: 0.8.7
78
+ version: '0'
63
79
  - !ruby/object:Gem::Dependency
64
- name: rspec
80
+ name: rake
65
81
  requirement: !ruby/object:Gem::Requirement
66
82
  none: false
67
83
  requirements:
68
84
  - - ! '>='
69
85
  - !ruby/object:Gem::Version
70
- version: '2'
86
+ version: '0'
71
87
  type: :development
72
88
  prerelease: false
73
89
  version_requirements: !ruby/object:Gem::Requirement
@@ -75,39 +91,39 @@ dependencies:
75
91
  requirements:
76
92
  - - ! '>='
77
93
  - !ruby/object:Gem::Version
78
- version: '2'
94
+ version: '0'
79
95
  - !ruby/object:Gem::Dependency
80
- name: webmock
96
+ name: rspec
81
97
  requirement: !ruby/object:Gem::Requirement
82
98
  none: false
83
99
  requirements:
84
- - - ! '>='
100
+ - - ~>
85
101
  - !ruby/object:Gem::Version
86
- version: 1.6.2
102
+ version: '2.0'
87
103
  type: :development
88
104
  prerelease: false
89
105
  version_requirements: !ruby/object:Gem::Requirement
90
106
  none: false
91
107
  requirements:
92
- - - ! '>='
108
+ - - ~>
93
109
  - !ruby/object:Gem::Version
94
- version: 1.6.2
110
+ version: '2.0'
95
111
  - !ruby/object:Gem::Dependency
96
- name: timecop
112
+ name: webmock
97
113
  requirement: !ruby/object:Gem::Requirement
98
114
  none: false
99
115
  requirements:
100
- - - ! '>='
116
+ - - ~>
101
117
  - !ruby/object:Gem::Version
102
- version: 0.3.5
118
+ version: '1.6'
103
119
  type: :development
104
120
  prerelease: false
105
121
  version_requirements: !ruby/object:Gem::Requirement
106
122
  none: false
107
123
  requirements:
108
- - - ! '>='
124
+ - - ~>
109
125
  - !ruby/object:Gem::Version
110
- version: 0.3.5
126
+ version: '1.6'
111
127
  description: An object-oriented Ruby wrapper for the TVRage API http://services.tvrage.com/
112
128
  email:
113
129
  - aganov@gmail.com
@@ -144,7 +160,9 @@ files:
144
160
  - spec/mock_xml/episode_list_empty.xml
145
161
  - spec/mock_xml/show_info.xml
146
162
  - spec/mock_xml/show_info_empty.xml
163
+ - spec/mock_xml/show_info_incomplete.xml
147
164
  - spec/mock_xml/show_search.xml
165
+ - spec/mock_xml/show_search_empty.xml
148
166
  - spec/spec_helper.rb
149
167
  homepage: http://github.com/appsbakery/memo_rage
150
168
  licenses: []
@@ -158,15 +176,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
176
  - - ! '>='
159
177
  - !ruby/object:Gem::Version
160
178
  version: '0'
179
+ segments:
180
+ - 0
181
+ hash: -67969453
161
182
  required_rubygems_version: !ruby/object:Gem::Requirement
162
183
  none: false
163
184
  requirements:
164
185
  - - ! '>='
165
186
  - !ruby/object:Gem::Version
166
187
  version: '0'
188
+ segments:
189
+ - 0
190
+ hash: -67969453
167
191
  requirements: []
168
192
  rubyforge_project: memo_rage
169
- rubygems_version: 1.8.19
193
+ rubygems_version: 1.8.24
170
194
  signing_key:
171
195
  specification_version: 3
172
196
  summary: Ruby wrapper for the TVRage API