nicoquery 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/nicoquery/api/base.rb +7 -1
- data/lib/nicoquery/api/mylist_rss.rb +4 -0
- data/lib/nicoquery/object/mylist.rb +10 -3
- data/lib/nicoquery/object_mapper/mylist_rss.rb +22 -6
- data/lib/nicoquery/version.rb +1 -1
- data/spec/object/mylist_spec.rb +73 -29
- data/spec/spec_helper.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 468c589049232e4268150e999a970d8e812145e3
|
4
|
+
data.tar.gz: 88775876e1ba25744db70c6ca01fccf970afd1d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea35f1f24febbeec5aa5c4805394058254b03ac211003818cc1ab096b38e2c02ba1df9d61246621cea4f40060961751ca7cd8735289fe440e4871bf56ff47dbc
|
7
|
+
data.tar.gz: 17189a95674986b03b9eaf1dd6cea57445cdb825612730acd320984324266d2c5a00c417ad18a3de3878e896625710a97ec1af2349b2b7c58ca33b68181c4a3b
|
data/Gemfile.lock
CHANGED
data/lib/nicoquery/api/base.rb
CHANGED
@@ -5,6 +5,8 @@ require 'active_support/all'
|
|
5
5
|
module NicoQuery
|
6
6
|
module Api
|
7
7
|
class Base
|
8
|
+
attr_reader :forbidden
|
9
|
+
|
8
10
|
def scheme
|
9
11
|
'http'
|
10
12
|
end
|
@@ -29,7 +31,11 @@ module NicoQuery
|
|
29
31
|
def get
|
30
32
|
RestClient.get uri.to_s do |response, request, result, &block|
|
31
33
|
case response.code
|
32
|
-
when 200
|
34
|
+
when 200
|
35
|
+
@forbidden = false
|
36
|
+
response
|
37
|
+
when 403
|
38
|
+
@forbidden = true
|
33
39
|
response
|
34
40
|
end
|
35
41
|
end
|
@@ -24,9 +24,8 @@ module NicoQuery
|
|
24
24
|
def initialize(mylist_id)
|
25
25
|
@movies = []
|
26
26
|
@mylist_id = mylist_id
|
27
|
-
source =
|
28
|
-
|
29
|
-
@hash = NicoQuery::ObjectMapper::MylistRSS.new source
|
27
|
+
@source = NicoQuery::Api::MylistRSS.new mylist_id
|
28
|
+
@hash = NicoQuery::ObjectMapper::MylistRSS.new @source.get
|
30
29
|
|
31
30
|
return if @hash.items.nil?
|
32
31
|
@hash.items.map do |item|
|
@@ -35,6 +34,14 @@ module NicoQuery
|
|
35
34
|
@movies.push movie
|
36
35
|
end
|
37
36
|
end
|
37
|
+
|
38
|
+
def available?
|
39
|
+
[!forbidden?].all?
|
40
|
+
end
|
41
|
+
|
42
|
+
def forbidden?
|
43
|
+
@source.forbidden
|
44
|
+
end
|
38
45
|
end
|
39
46
|
end
|
40
47
|
end
|
@@ -7,9 +7,9 @@ module NicoQuery
|
|
7
7
|
attr_reader :meta, :items
|
8
8
|
|
9
9
|
def initialize(xml)
|
10
|
-
parser = Nori.new
|
11
|
-
parsed_xml = parser.parse xml
|
12
|
-
entire = parsed_xml['rss']['channel']
|
10
|
+
@parser = Nori.new
|
11
|
+
@parsed_xml = @parser.parse xml
|
12
|
+
entire = @parsed_xml['rss']['channel']
|
13
13
|
|
14
14
|
@meta = Meta.new entire, title_prefix
|
15
15
|
if entire['item'].is_a? Array
|
@@ -35,8 +35,7 @@ module NicoQuery
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def title
|
38
|
-
@hash['title']
|
39
|
-
.scan(/(?<=#{@title_prefix}\s).+(?=\‐ニコニコ動画)/)[0].split(' ')[0]
|
38
|
+
@hash['title'].scan(/(?<=#{@title_prefix}\s).+(?=\‐ニコニコ動画)/)[0].split(' ')[0]
|
40
39
|
# .force_encoding('utf-8')
|
41
40
|
end
|
42
41
|
|
@@ -45,26 +44,32 @@ module NicoQuery
|
|
45
44
|
end
|
46
45
|
|
47
46
|
def link
|
48
|
-
@hash['link']
|
47
|
+
@hash['link'].presence
|
49
48
|
end
|
50
49
|
|
51
50
|
def mylist_id
|
51
|
+
return nil unless @hash['link'].present?
|
52
52
|
@hash['link'].scan(/(?<=mylist\/)\d{1,}/)[0].to_i
|
53
53
|
end
|
54
54
|
|
55
55
|
def description
|
56
|
+
return nil unless @hash['description'].present?
|
57
|
+
return nil if @hash['description'] == "このマイリストは非公開に設定されています。"
|
56
58
|
@hash['description']
|
57
59
|
end
|
58
60
|
|
59
61
|
def publish_date
|
62
|
+
return nil unless @hash['publish_date'].present?
|
60
63
|
Time.parse @hash['publish_date']
|
61
64
|
end
|
62
65
|
|
63
66
|
def last_build_date
|
67
|
+
return nil unless @hash['lastBuildDate'].present?
|
64
68
|
Time.parse @hash['lastBuildDate']
|
65
69
|
end
|
66
70
|
|
67
71
|
def creator
|
72
|
+
return nil unless @hash['dc:creator'].present?
|
68
73
|
@hash['dc:creator']
|
69
74
|
end
|
70
75
|
end
|
@@ -75,47 +80,58 @@ module NicoQuery
|
|
75
80
|
end
|
76
81
|
|
77
82
|
def title
|
83
|
+
return nil if @hash == nil
|
78
84
|
@hash['title']
|
79
85
|
end
|
80
86
|
|
81
87
|
def video_id
|
88
|
+
return nil if @hash == nil
|
82
89
|
(url.scan(/((sm|nm)\d{1,})/).map {|e| e[0]})[0]
|
83
90
|
end
|
84
91
|
|
85
92
|
def url
|
93
|
+
return nil if @hash == nil
|
86
94
|
@hash['link']
|
87
95
|
end
|
88
96
|
|
89
97
|
def thread_id
|
98
|
+
return nil if @hash == nil
|
90
99
|
@hash['guid'].scan(/(?<=watch\/)\d{1,}$/)[0].to_i
|
91
100
|
end
|
92
101
|
|
93
102
|
def publish_date
|
103
|
+
return nil if @hash == nil
|
94
104
|
Time.parse @hash['pubDate']
|
95
105
|
end
|
96
106
|
|
97
107
|
def thumbnail_url
|
108
|
+
return nil if @hash == nil
|
98
109
|
description.raw_text.scan(/(?<=src\=\").{1,}(?=\"\swidth)/)[0]
|
99
110
|
$&
|
100
111
|
end
|
101
112
|
|
102
113
|
def view_counter
|
114
|
+
return nil if @hash == nil
|
103
115
|
description.raw_text.scan(/(?<=nico-numbers-view\">)[0-9,]{1,}(?=\<\/strong)/)[0].delete(',').to_i
|
104
116
|
end
|
105
117
|
|
106
118
|
def comment_num
|
119
|
+
return nil if @hash == nil
|
107
120
|
description.raw_text.scan(/(?<=nico-numbers-res\">)[0-9,]{1,}(?=\<\/strong)/)[0].delete(',').to_i
|
108
121
|
end
|
109
122
|
|
110
123
|
def mylist_counter
|
124
|
+
return nil if @hash == nil
|
111
125
|
description.raw_text.scan(/(?<=nico-numbers-mylist\">)[0-9,]{1,}(?=\<\/strong)/)[0].delete(',').to_i
|
112
126
|
end
|
113
127
|
|
114
128
|
def description
|
129
|
+
return nil if @hash == nil
|
115
130
|
@_description ||= Description.new @hash['description']
|
116
131
|
end
|
117
132
|
|
118
133
|
def length
|
134
|
+
return nil if @hash == nil
|
119
135
|
description.raw_text.scan(/(?<=class\=\"nico\-info\-length\"\>)\d{1,}\:\d{1,2}(?=\<\/strong\>)/)
|
120
136
|
length_string = $&.to_s.split(':')
|
121
137
|
length_string[0].to_i * 60 + length_string[1].to_i
|
data/lib/nicoquery/version.rb
CHANGED
data/spec/object/mylist_spec.rb
CHANGED
@@ -1,47 +1,91 @@
|
|
1
1
|
require "nicoquery/object/mylist"
|
2
|
+
require "fixture/mylist_rss_403"
|
2
3
|
|
3
4
|
|
4
5
|
describe "NicoQuery::Object::Mylist" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
context "when specified mylist exists and is public" do
|
7
|
+
before do
|
8
|
+
# mylist:38369702 はテスト用に作ったマイリスト。以下の動画を含んでいる。
|
9
|
+
# sm9 新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師
|
10
|
+
# sm1097445 【初音ミク】みくみくにしてあげる♪【してやんよ】
|
11
|
+
@mylist = NicoQuery::Object::Mylist.new(38369702)
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
describe "movies" do
|
15
|
+
it "returns movie instances" do
|
16
|
+
expect(@mylist.movies).to be_an_instance_of Array
|
17
|
+
expect(@mylist.movies[0]).to be_an_instance_of NicoQuery::Object::Movie
|
18
|
+
end
|
16
19
|
end
|
17
|
-
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
describe "title" do
|
22
|
+
subject { @mylist }
|
23
|
+
it "returns string of title" do
|
24
|
+
expect(subject.title).to eq "to_test"
|
25
|
+
end
|
23
26
|
end
|
24
|
-
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
describe "url" do
|
29
|
+
subject { @mylist }
|
30
|
+
it "returns string of url" do
|
31
|
+
expect(subject.url).to eq "http://www.nicovideo.jp/mylist/38369702"
|
32
|
+
end
|
30
33
|
end
|
31
|
-
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
describe "mylist_id" do
|
36
|
+
subject { @mylist }
|
37
|
+
it "returns number of mylist_id" do
|
38
|
+
expect(subject.mylist_id).to eq 38369702
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "description" do
|
43
|
+
subject { @mylist }
|
44
|
+
it "returns string of title" do
|
45
|
+
# mylistのrssでは、descriptionの全文取得はできず、頭から256文字までしか取得できない。
|
46
|
+
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 "
|
47
|
+
end
|
37
48
|
end
|
38
49
|
end
|
39
50
|
|
40
|
-
|
51
|
+
context "when access for specified mylist is forbidden" do
|
52
|
+
before do
|
53
|
+
WebMock.enable!
|
54
|
+
WebMock.stub_request(:get, "http://www.nicovideo.jp/mylist/999999?rss=2.0&numbers=1").
|
55
|
+
to_return(:status => 403, :body => Fixture.mylist_rss_403, :headers => {})
|
56
|
+
|
57
|
+
@mylist = NicoQuery::Object::Mylist.new(999999)
|
58
|
+
end
|
59
|
+
|
60
|
+
after do
|
61
|
+
WebMock.disable!
|
62
|
+
end
|
63
|
+
|
41
64
|
subject { @mylist }
|
42
|
-
|
43
|
-
|
44
|
-
|
65
|
+
|
66
|
+
describe "#forbidden?" do
|
67
|
+
it "returns true" do
|
68
|
+
expect(subject.forbidden?).to be_true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#available?" do
|
73
|
+
it "returns false" do
|
74
|
+
expect(subject.available?).to be_false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "getter methods" do
|
79
|
+
specify "all returns nil" do
|
80
|
+
# タイトルだけは非公開でも取得できる?
|
81
|
+
# expect(subject.title).to be_nil
|
82
|
+
# expect(subject.url).to be_nil
|
83
|
+
# expect(subject.link).to be_nil
|
84
|
+
expect(subject.description).to be_nil
|
85
|
+
expect(subject.publish_date).to be_nil
|
86
|
+
expect(subject.last_build_date).to be_nil
|
87
|
+
expect(subject.creator).to be_nil
|
88
|
+
end
|
45
89
|
end
|
46
90
|
end
|
47
91
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
# loaded once.
|
5
5
|
#
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require "webmock"
|
8
|
+
require "pry"
|
9
|
+
|
7
10
|
RSpec.configure do |config|
|
8
11
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
12
|
config.run_all_when_everything_filtered = true
|