nicoquery 0.0.1.4 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ require "nicoquery/object/mylist"
2
+
3
+
4
+ describe "NicoQuery::Object::Mylist" do
5
+ before do
6
+ # mylist:38369702 はテスト用に作ったマイリスト。以下の動画を含んでいる。
7
+ # sm9 新・豪血寺一族 -煩悩解放 - レッツゴー!陰陽師
8
+ # sm1097445 【初音ミク】みくみくにしてあげる♪【してやんよ】
9
+ @mylist = NicoQuery::Object::Mylist.new('38369702')
10
+ end
11
+
12
+ describe "movies" do
13
+ it "returns movie instances" do
14
+ expect(@mylist.movies).to be_an_instance_of Array
15
+ expect(@mylist.movies[0]).to be_an_instance_of NicoQuery::Object::Movie
16
+ end
17
+ end
18
+
19
+ describe "title" do
20
+ subject { @mylist }
21
+ it "returns string of title" do
22
+ expect(subject.title).to eq "to_test"
23
+ end
24
+ end
25
+
26
+ describe "url" do
27
+ subject { @mylist }
28
+ it "returns string of url" do
29
+ expect(subject.url).to eq "http://www.nicovideo.jp/mylist/38369702"
30
+ end
31
+ end
32
+
33
+ describe "mylist_id" do
34
+ subject { @mylist }
35
+ it "returns number of mylist_id" do
36
+ expect(subject.mylist_id).to eq 38369702
37
+ end
38
+ end
39
+
40
+ describe "description" do
41
+ subject { @mylist }
42
+ it "returns string of title" do
43
+ # mylistのrssでは、descriptionの全文取得はできず、頭から256文字までしか取得できない。
44
+ 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 "
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,26 @@
1
+ require "nicoquery/object/tag_search"
2
+
3
+
4
+ describe "NicoQuery::Object::TagSearch" do
5
+ before do
6
+ @tag_search_result = NicoQuery::Object::TagSearch.new( tag: "ゆっくり実況プレイ",
7
+ sort: :published_at,
8
+ order: :asc,
9
+ page: 1 )
10
+ end
11
+
12
+ subject { @tag_search_result }
13
+
14
+ describe "title" do
15
+ it "returns string of title" do
16
+ expect(subject.title).to eq "ゆっくり実況プレイ"
17
+ end
18
+ end
19
+
20
+ describe "movies" do
21
+ it "returns movie instances" do
22
+ expect(subject.movies).to be_an_instance_of Array
23
+ expect(subject.movies[0]).to be_an_instance_of NicoQuery::Object::Movie
24
+ end
25
+ end
26
+ end
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.0.1.4
4
+ version: 0.0.2
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-08-08 00:00:00.000000000 Z
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -181,16 +181,34 @@ files:
181
181
  - Rakefile
182
182
  - autorun.rb
183
183
  - lib/nicoquery.rb
184
- - lib/nicoquery/crawler.rb
184
+ - lib/nicoquery/api/base.rb
185
+ - lib/nicoquery/api/getthumbinfo.rb
186
+ - lib/nicoquery/api/mylist_rss.rb
187
+ - lib/nicoquery/api/tag_search_rss.rb
188
+ - lib/nicoquery/api/video_array.rb
185
189
  - lib/nicoquery/crawler/tag_search.rb
186
- - lib/nicoquery/parser.rb
187
- - lib/nicoquery/parser/tag_search.rb
190
+ - lib/nicoquery/object/movie.rb
191
+ - lib/nicoquery/object/mylist.rb
192
+ - lib/nicoquery/object/tag_search.rb
193
+ - lib/nicoquery/object_mapper/getthumbinfo.rb
194
+ - lib/nicoquery/object_mapper/mylist_rss.rb
195
+ - lib/nicoquery/object_mapper/tag_search_rss.rb
188
196
  - lib/nicoquery/version.rb
189
197
  - nicoquery.gemspec
198
+ - spec/api/getthumbinfo_spec.rb
199
+ - spec/api/mylist_rss_spec.rb
200
+ - spec/api/spec_helper.rb
201
+ - spec/api/tag_search_spec.rb
202
+ - spec/api/video_array_spec.rb
190
203
  - spec/crawler/spec_helper.rb
191
204
  - spec/crawler/tag_search_spec.rb
192
- - spec/parser/fixture.rb
193
- - spec/parser/tag_search_spec.rb
205
+ - spec/fixture/tag_search.rb
206
+ - spec/fixture/tag_search_item.rb
207
+ - spec/fixture/tag_search_meta.rb
208
+ - spec/nicoquery_spec.rb
209
+ - spec/object/movie_spec.rb
210
+ - spec/object/mylist_spec.rb
211
+ - spec/object/tag_search_rss_spec.rb
194
212
  - spec/spec_helper.rb
195
213
  homepage: ''
196
214
  licenses:
@@ -217,8 +235,18 @@ signing_key:
217
235
  specification_version: 4
218
236
  summary: niconico manipulator
219
237
  test_files:
238
+ - spec/api/getthumbinfo_spec.rb
239
+ - spec/api/mylist_rss_spec.rb
240
+ - spec/api/spec_helper.rb
241
+ - spec/api/tag_search_spec.rb
242
+ - spec/api/video_array_spec.rb
220
243
  - spec/crawler/spec_helper.rb
221
244
  - spec/crawler/tag_search_spec.rb
222
- - spec/parser/fixture.rb
223
- - spec/parser/tag_search_spec.rb
245
+ - spec/fixture/tag_search.rb
246
+ - spec/fixture/tag_search_item.rb
247
+ - spec/fixture/tag_search_meta.rb
248
+ - spec/nicoquery_spec.rb
249
+ - spec/object/movie_spec.rb
250
+ - spec/object/mylist_spec.rb
251
+ - spec/object/tag_search_rss_spec.rb
224
252
  - spec/spec_helper.rb
@@ -1,12 +0,0 @@
1
- require "nicoquery/crawler/tag_search"
2
-
3
-
4
- module NicoQuery
5
- module Crawler
6
- def tag_search(tag: tag, sort: sort, order: order, &block)
7
- NicoQuery::Crawler::TagSearch.execute(tag: tag, sort: sort, order: order, &block)
8
- end
9
-
10
- module_function :tag_search
11
- end
12
- end
@@ -1,106 +0,0 @@
1
- require "nori"
2
- require "nokogiri"
3
-
4
-
5
- module NicoQuery
6
- module Parser
7
- class TagSearch
8
- def initialize
9
- @parser = Nori.new
10
- end
11
-
12
- def parse(xml)
13
- @object = (@parser.parse xml)["rss"]["channel"]
14
-
15
- @items = @object["item"].map do |item_object|
16
- Item.new item_object
17
- end
18
- end
19
-
20
- def items
21
- @items
22
- end
23
-
24
- def tag
25
- @object["title"].scan(/(?<=タグ\s).+(?=\‐ニコニコ動画)/)[0].split(' ')
26
- end
27
-
28
- def publish_date
29
- Time.parse @object["pubDate"]
30
- end
31
-
32
- def last_build_date
33
- Time.parse @object["lastBuildDate"]
34
- end
35
-
36
- class Item
37
- def initialize(object)
38
- @object = object
39
- end
40
-
41
- def title
42
- @object["title"]
43
- end
44
-
45
- def video_id
46
- url.scan(/(sm|nm)\d{1,}\Z/)
47
- $&
48
- end
49
-
50
- def url
51
- @object["link"]
52
- end
53
-
54
- def publish_date
55
- Time.parse @object["pubDate"]
56
- end
57
-
58
- def thumbnail_url
59
- description.raw_text.scan(/(?<=src\=\").{1,}(?=\"\swidth)/)
60
- $&
61
- end
62
-
63
- def description
64
- @_description ||= Description.new @object["description"]
65
- end
66
-
67
- def length
68
- description.raw_text.scan(/(?<=class\=\"nico\-info\-length\"\>)\d{1,}\:\d{1,2}(?=\<\/strong\>)/)
69
- length_string = $&.to_s.split(':')
70
- length_string[0].to_i * 60 + length_string[1].to_i
71
- end
72
-
73
- class Description
74
- attr_reader :raw_text
75
-
76
- def initialize(raw_text)
77
- @raw_text = raw_text.to_s
78
- end
79
-
80
- def text
81
- @raw_text.scan /(?<=class\=\"nico\-description\"\>).{1,}(?=\<\/p\>)/
82
- $&
83
- end
84
-
85
- def movie_references
86
- # is this the high road?
87
- text.scan(/((sm|nm)\d{1,})/).map {|e| e[0]}
88
- end
89
-
90
- def mylist_references
91
- text.scan /(?<=mylist\/)\d{1,}/
92
- end
93
-
94
- def community_references
95
- text.scan /co\d{1,}/
96
- end
97
-
98
- def seiga_references
99
- text.scan /im\d{1,}/
100
- end
101
- end
102
- end
103
-
104
- end
105
- end
106
- end
@@ -1,8 +0,0 @@
1
- require "nicoquery/parser/tag_search"
2
-
3
-
4
- module NicoQuery
5
- module Parser
6
-
7
- end
8
- end
@@ -1,119 +0,0 @@
1
- require "spec_helper"
2
- require "./lib/nicoquery/parser/tag_search"
3
- require "./spec/parser/fixture"
4
-
5
-
6
- describe "NicoQuery::Parser" do
7
- describe "TagSearch" do
8
- before do
9
- @instance = NicoQuery::Parser::TagSearch.new
10
- @instance.parse Fixture.tag_search_rss
11
- end
12
-
13
- shared_examples "url string" do
14
- specify { expect(subject).to match /(http|https)\:\/\/.+/ }
15
- end
16
-
17
- describe "tag" do
18
- subject { @instance.tag }
19
- specify { expect(subject).to be }
20
- end
21
-
22
- describe "publish_date" do
23
- subject { @instance.publish_date }
24
- specify { expect(subject).to be_kind_of(Time) }
25
- end
26
-
27
- describe "last_build_date" do
28
- subject { @instance.last_build_date }
29
- specify { expect(subject).to be_kind_of(Time) }
30
- end
31
-
32
- describe "item" do
33
- subject { @instance.items }
34
- specify { expect(subject).to be_kind_of(Array) }
35
- end
36
-
37
- describe "each item" do
38
-
39
- describe "title" do
40
- subject { @instance.items[0].title }
41
- specify { expect(subject).to be }
42
- end
43
-
44
- describe "video_id" do
45
- subject { @instance.items[0].video_id }
46
- specify { expect(subject).to match /(sm|nm)\d{1,}/ }
47
- end
48
-
49
- describe "url" do
50
- subject { @instance.items[0].url }
51
- it_behaves_like "url string"
52
- end
53
-
54
- describe "publish_date" do
55
- subject { @instance.items[0].url }
56
- it_behaves_like "url string"
57
- end
58
-
59
- describe "thumbnail_url" do
60
- subject { @instance.items[0].thumbnail_url }
61
- it_behaves_like "url string"
62
- end
63
-
64
- describe "length" do
65
- subject { @instance.items[0].length }
66
- specify { expect(subject).to be_kind_of(Fixnum) }
67
- end
68
-
69
- describe "description" do
70
- subject { @instance.items[0].description }
71
- specify { expect(subject).to be_kind_of(Object) }
72
- end
73
-
74
- describe "Description" do
75
- describe "raw_text" do
76
- subject { @instance.items[0].description.raw_text }
77
- specify { expect(subject).to be_kind_of(String) }
78
- end
79
-
80
- describe "text" do
81
- subject { @instance.items[0].description.text }
82
- specify { expect(subject).to be_kind_of(String) }
83
- end
84
-
85
- # spec/fixture.rbを参照。
86
- describe "movie_references" do
87
- subject { @instance.items[5].description.movie_references }
88
- specify { expect(subject).to be_kind_of(Array) }
89
- specify { expect(subject.length).to eq 4 }
90
- specify { expect(subject[0]).to match /^(sm|nm)\d{1,}$/ }
91
- end
92
-
93
- # Fixtureの最初の動画では、'mylist/(数字)'の記載が2つある。
94
- describe "mylist_references" do
95
- subject { @instance.items[0].description.mylist_references }
96
- specify { expect(subject).to be_kind_of(Array) }
97
- specify { expect(subject.length).to eq 2 }
98
- specify { expect(subject[0]).to match /^\d{1,}$/ }
99
- end
100
-
101
- # Fixtureの3番目の動画では、'co(数字)'の記載が2つある。
102
- describe "community_references" do
103
- subject { @instance.items[2].description.community_references }
104
- specify { expect(subject).to be_kind_of(Array) }
105
- specify { expect(subject.length).to eq 1 }
106
- specify { expect(subject[0]).to match /^co\d{1,}$/ }
107
- end
108
-
109
- # Fixtureの3番目の動画では、'im(数字)'の記載が1つある。
110
- describe "seiga_references" do
111
- subject { @instance.items[3].description.seiga_references }
112
- specify { expect(subject).to be_kind_of(Array) }
113
- specify { expect(subject.length).to eq 1 }
114
- specify { expect(subject[0]).to match /^im\d{1,}$/ }
115
- end
116
- end
117
- end
118
- end
119
- end
File without changes