nicoquery 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3814f14a25adbb1ee71f0844c0b61029fa8f477
4
- data.tar.gz: e73736c6c8399eccd015fa1299ecc209d2cfe363
3
+ metadata.gz: 5c8448da8f6c085baf596a84b21f9f1f72fbbc24
4
+ data.tar.gz: f99938d2cfd1c46c4d7e357d03b4b1cdff03fc3b
5
5
  SHA512:
6
- metadata.gz: 40ec35c5bfab9edb7617ca03f8f7c32e22c1aec168b632e9759b23a8274b337eb219d20fabe46c5a5cd297609ae0028a5724e8b9f470e183f2189003f058b988
7
- data.tar.gz: 1f3506b3b00bc3e14be66335ce884d7efb05b23580bbe0a30f30c4a0c7b9bdfafeec4881fde7a42cb22736110509feecad51374105282870e9e8f99fb581d0a1
6
+ metadata.gz: d294a9c3a541503f24680d42e5c261158b1e21ef06d22366a74dfbe1f4d75dcc6a79ed3424524746661aab15c19264ca0cf9d81be3a4a72b31d45ddc9aa9b823
7
+ data.tar.gz: 666e1083cdf82fc3427180c0b8aaf6e98ec24d55c729adb7779c122b4cfafc0173b9d6ae655ad8fe0a8a3f3b49dd6e8f77c3dce230d76c0287ca93ebd9ea57cd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nicoquery (0.1.3)
4
+ nicoquery (0.1.4)
5
5
  activesupport (~> 4.0.0)
6
6
  i18n
7
7
  nicoapi
@@ -8,6 +8,8 @@ module NicoQuery
8
8
  attr_reader :video_id
9
9
 
10
10
  [
11
+ 'deleted?',
12
+
11
13
  'title',
12
14
  'url',
13
15
  # 'thread_id',
@@ -7,16 +7,26 @@ module NicoQuery
7
7
  class GetThumbInfo
8
8
  def initialize(xml)
9
9
  @xml = xml
10
- parser = Nori.new
11
- parsed_xml = parser.parse xml
12
- @hash = parsed_xml['nicovideo_thumb_response']['thumb']
10
+ @parser = Nori.new
11
+ @parsed_xml = @parser.parse xml
12
+ @hash = @parsed_xml['nicovideo_thumb_response']['thumb']
13
+ end
14
+
15
+ def deleted?
16
+ if @parsed_xml['nicovideo_thumb_response']["error"].presence
17
+ @parsed_xml['nicovideo_thumb_response']["error"].presence["code"].presence == "DELETED"
18
+ else
19
+ false
20
+ end
13
21
  end
14
22
 
15
23
  def video_id
24
+ return nil if @hash == nil
16
25
  @hash['video_id']
17
26
  end
18
27
 
19
28
  def title
29
+ return nil if @hash == nil
20
30
  @hash['title']
21
31
  end
22
32
 
@@ -25,10 +35,12 @@ module NicoQuery
25
35
  end
26
36
 
27
37
  def thumbnail_url
38
+ return nil if @hash == nil
28
39
  @hash['thumbnail_url']
29
40
  end
30
41
 
31
42
  def first_retrieve
43
+ return nil if @hash == nil
32
44
  @hash['first_retrieve'].to_time
33
45
  end
34
46
 
@@ -37,59 +49,73 @@ module NicoQuery
37
49
  end
38
50
 
39
51
  def length
52
+ return nil if @hash == nil
40
53
  string = @hash['length'].split(':')
41
54
  string[0].to_i * 60 + string[1].to_i
42
55
  end
43
56
 
44
57
  def movie_type
58
+ return nil if @hash == nil
45
59
  @hash['movie_type']
46
60
  end
47
61
 
48
62
  def size_high
63
+ return nil if @hash == nil
49
64
  @hash['size_high'].to_i
50
65
  end
51
66
 
52
67
  def size_low
68
+ return nil if @hash == nil
53
69
  @hash['size_low'].to_i
54
70
  end
55
71
 
56
72
  def view_counter
73
+ return nil if @hash == nil
57
74
  @hash['view_counter'].to_i
58
75
  end
59
76
 
60
77
  def comment_num
78
+ return nil if @hash == nil
61
79
  @hash['comment_num'].to_i
62
80
  end
63
81
 
64
82
  def mylist_counter
83
+ return nil if @hash == nil
65
84
  @hash['mylist_counter'].to_i
66
85
  end
67
86
 
68
87
  def last_res_body
88
+ return nil if @hash == nil
69
89
  @hash['last_res_body']
70
90
  end
71
91
 
72
92
  def url
93
+ return nil if @hash == nil
73
94
  @hash['watch_url']
74
95
  end
75
96
 
76
97
  def watch_url
98
+ return nil if @hash == nil
77
99
  @hash['watch_url']
78
100
  end
79
101
 
80
102
  def thumb_type
103
+ return nil if @hash == nil
81
104
  @hash['thumb_type']
82
105
  end
83
106
 
84
107
  def embeddable
108
+ return nil if @hash == nil
85
109
  @hash['embeddable'] == 1
86
110
  end
87
111
 
88
112
  def no_live_play
113
+ return nil if @hash == nil
89
114
  @hash['no_live_play'] == 1
90
115
  end
91
116
 
92
117
  def tags
118
+ return nil if @hash == nil
93
119
  xml = @xml.scan(/\<tags domain=\"jp\">\n.+\n\<\/tags\>/m)[0]
94
120
  parsed = Nokogiri::XML xml
95
121
  parsed.xpath("//tag").map do |tag_object|
@@ -98,6 +124,7 @@ module NicoQuery
98
124
  end
99
125
 
100
126
  def user_id
127
+ return nil if @hash == nil
101
128
  @hash['user_id'].to_i
102
129
  end
103
130
 
@@ -1,3 +1,3 @@
1
1
  module NicoQuery
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1,7 @@
1
+ module Fixture
2
+ def self.getthumbinfo_deleted
3
+ <<-EOS
4
+ <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<nicovideo_thumb_response status=\"fail\">\n<error>\n<code>DELETED</code>\n<description>deleted</description>\n</error>\n</nicovideo_thumb_response>
5
+ EOS
6
+ end
7
+ end
@@ -1,52 +1,93 @@
1
- require "nicoquery/object/movie"
1
+ require 'nicoquery/object/movie'
2
+ require 'fixture/getthumbinfo_deleted'
3
+ require 'webmock/rspec'
2
4
 
3
5
 
4
6
  describe "NicoQuery::Object::Movie" do
5
- before do
6
- # mylist:38369702 はテスト用に作ったマイリスト。以下の動画を含んでいる。
7
- # sm9 新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師
8
- # sm1097445 【初音ミク】みくみくにしてあげる♪【してやんよ】
9
- @movie = NicoQuery::Object::Movie.new('sm9')
10
- end
7
+ context "when specified movie is exist" do
8
+ before do
9
+ # mylist:38369702 はテスト用に作ったマイリスト。以下の動画を含んでいる。
10
+ # sm9 新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師
11
+ # sm1097445 【初音ミク】みくみくにしてあげる♪【してやんよ】
12
+ @movie = NicoQuery::Object::Movie.new('sm9')
13
+ end
11
14
 
12
- subject { @movie }
15
+ subject { @movie }
13
16
 
14
- describe "title" do
15
- it "returns string of title" do
16
- expect(subject.title).to eq "新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師"
17
+ describe "#deleted?" do
18
+ subject { @movie.deleted? }
19
+
20
+ it "returns false" do
21
+ expect(subject).to be_false
22
+ end
17
23
  end
18
- end
19
24
 
20
- describe "url" do
21
- it "returns string of url" do
22
- expect(subject.url).to eq "http://www.nicovideo.jp/watch/sm9"
25
+ describe "title" do
26
+ it "returns string of title" do
27
+ expect(subject.title).to eq "新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師"
28
+ end
23
29
  end
24
- end
25
30
 
26
- describe "video_id" do
27
- it "returns number of mylist_id" do
28
- expect(subject.video_id).to eq "sm9"
31
+ describe "url" do
32
+ it "returns string of url" do
33
+ expect(subject.url).to eq "http://www.nicovideo.jp/watch/sm9"
34
+ end
35
+ end
36
+
37
+ describe "video_id" do
38
+ it "returns number of mylist_id" do
39
+ expect(subject.video_id).to eq "sm9"
40
+ end
41
+ end
42
+
43
+ # describe "description" do
44
+ # subject { @movie }
45
+ # it "returns string of title" do
46
+ # # mylistのrssでは、descriptionの全文取得はできず、頭から256文字までしか取得できない。
47
+ # expect(subject.description).to eq "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam. Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh. Duis "
48
+ # end
49
+ # end
50
+
51
+ describe "tags" do
52
+ subject { @movie.tags }
53
+
54
+ it "returns object array" do
55
+ expect(subject).to be_an_instance_of Array
56
+ end
57
+
58
+ specify "each object has text and lock key-value" do
59
+ expect(subject).to include(text: '陰陽師', lock: true)
60
+ end
29
61
  end
30
62
  end
31
63
 
32
- # describe "description" do
33
- # subject { @movie }
34
- # it "returns string of title" do
35
- # # mylistのrssでは、descriptionの全文取得はできず、頭から256文字までしか取得できない。
36
- # expect(subject.description).to eq "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam. Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh. Duis "
37
- # end
38
- # end
64
+ context "when specified movie is deleted" do
65
+ before do
66
+ WebMock.stub_request(:get, "http://ext.nicovideo.jp/api/getthumbinfo/sm999999?").
67
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
68
+ to_return(:status => 200, :body => Fixture.getthumbinfo_deleted, :headers => {})
39
69
 
40
- describe "tags" do
41
- subject { @movie.tags }
70
+ @movie = NicoQuery::Object::Movie.new('sm999999')
71
+ end
72
+
73
+ subject { @movie }
42
74
 
43
- it "returns object array" do
44
- expect(subject).to be_an_instance_of Array
75
+ describe "#deleted?" do
76
+ subject { @movie.deleted? }
77
+
78
+ it "returns true" do
79
+ expect(subject).to be_true
80
+ end
45
81
  end
46
82
 
47
- specify "each object has text and lock key-value" do
48
- expect(subject).to include(text: '陰陽師', lock: true)
83
+ describe "getter methods" do
84
+ specify "all returns nil" do
85
+ expect(subject.title).to be_nil
86
+ expect(subject.url).to be_nil
87
+ expect(subject.view_counter).to be_nil
88
+ expect(subject.tags).to be_nil
89
+ end
49
90
  end
91
+
50
92
  end
51
93
  end
52
- p
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nicoquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masami Yonehara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-14 00:00:00.000000000 Z
11
+ date: 2013-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -253,6 +253,7 @@ files:
253
253
  - spec/api/video_array_spec.rb
254
254
  - spec/crawler/bulk_scraping_spec.rb
255
255
  - spec/crawler/tag_search_spec.rb
256
+ - spec/fixture/getthumbinfo_deleted.rb
256
257
  - spec/fixture/getthumbinfo_sm20415650.rb
257
258
  - spec/fixture/mylist_rss_18266317.rb
258
259
  - spec/fixture/mylist_rss_403.rb
@@ -300,6 +301,7 @@ test_files:
300
301
  - spec/api/video_array_spec.rb
301
302
  - spec/crawler/bulk_scraping_spec.rb
302
303
  - spec/crawler/tag_search_spec.rb
304
+ - spec/fixture/getthumbinfo_deleted.rb
303
305
  - spec/fixture/getthumbinfo_sm20415650.rb
304
306
  - spec/fixture/mylist_rss_18266317.rb
305
307
  - spec/fixture/mylist_rss_403.rb