nicoquery 0.0.2.4 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81ac089c860870da51b14e2e9f852a23bd3314e2
4
- data.tar.gz: 63dcef0f7b49cead8df352afdbfc1d51ca3e68e4
3
+ metadata.gz: bce8798710bea5f5abebc2d7aeb1bc6256a82fe6
4
+ data.tar.gz: fffd05d8efd7d3ed0c62a5ff5049a3606ddd262d
5
5
  SHA512:
6
- metadata.gz: 1d6b1ccf1315bc232109657ca2c8f7d0a13f7509837384b18c409cabbf0142d71a879419f31833c0b57b5ac4e82e4fe964e9e75c558c056cf164f35e935c1b18
7
- data.tar.gz: d089b1b6b92025c96f5f1b39a4c5095736edfaa301fcf36e4723f18bbc5eeb1af6cdf7aa302b1887440b30b59c11cf3cd92152ba0c94a2f84a96524f8ba84a48
6
+ metadata.gz: e4cca4072ed5a0e1f01acee683de6f77143004f210a0ab1a8429188392444a92a5acba844e420146875464d7a09c9e0091f2de3e1831a751617c29549503b91e
7
+ data.tar.gz: f1290e333fc053d9a989ea5aeeba403a90553145ef73ea94d7e0d85703ef4abe32177a277fb9c21106332ed33ed4f9d592462dba23e9b5a1ea6ac68f8cea9f2f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nicoquery (0.0.2.4)
4
+ nicoquery (0.0.3)
5
5
  activesupport (~> 4.0.0)
6
6
  i18n
7
7
  nicoapi
@@ -18,10 +18,29 @@ GEM
18
18
  multi_json (~> 1.3)
19
19
  thread_safe (~> 0.1)
20
20
  tzinfo (~> 0.3.37)
21
+ addressable (2.3.5)
21
22
  atomic (1.1.13)
22
23
  coderay (1.0.9)
24
+ crack (0.4.1)
25
+ safe_yaml (~> 0.9.0)
23
26
  diff-lcs (1.2.4)
27
+ ffi (1.9.0)
28
+ formatador (0.2.4)
29
+ guard (1.8.2)
30
+ formatador (>= 0.2.4)
31
+ listen (>= 1.0.0)
32
+ lumberjack (>= 1.0.2)
33
+ pry (>= 0.9.10)
34
+ thor (>= 0.14.6)
35
+ guard-rspec (3.0.2)
36
+ guard (>= 1.8)
37
+ rspec (~> 2.13)
24
38
  i18n (0.6.5)
39
+ listen (1.3.0)
40
+ rb-fsevent (>= 0.9.3)
41
+ rb-inotify (>= 0.9)
42
+ rb-kqueue (>= 0.2)
43
+ lumberjack (1.0.4)
25
44
  method_source (0.8.2)
26
45
  mime-types (1.24)
27
46
  mini_portile (0.5.1)
@@ -39,6 +58,11 @@ GEM
39
58
  method_source (~> 0.8)
40
59
  slop (~> 3.4)
41
60
  rake (10.1.0)
61
+ rb-fsevent (0.9.3)
62
+ rb-inotify (0.9.1)
63
+ ffi (>= 0.5.0)
64
+ rb-kqueue (0.2.0)
65
+ ffi (>= 0.5.0)
42
66
  rest-client (1.6.7)
43
67
  mime-types (>= 1.16)
44
68
  rspec (2.14.1)
@@ -49,19 +73,27 @@ GEM
49
73
  rspec-expectations (2.14.2)
50
74
  diff-lcs (>= 1.1.3, < 2.0)
51
75
  rspec-mocks (2.14.3)
76
+ safe_yaml (0.9.5)
52
77
  slop (3.4.6)
78
+ thor (0.18.1)
53
79
  thread_safe (0.1.2)
54
80
  atomic
55
81
  tzinfo (0.3.37)
56
82
  watchr (0.7)
83
+ webmock (1.13.0)
84
+ addressable (>= 2.2.7)
85
+ crack (>= 0.3.2)
57
86
 
58
87
  PLATFORMS
59
88
  ruby
60
89
 
61
90
  DEPENDENCIES
62
91
  bundler (~> 1.3)
92
+ guard
93
+ guard-rspec
63
94
  nicoquery!
64
95
  pry
65
96
  rake
66
97
  rspec
67
98
  watchr
99
+ webmock
data/Guardfile ADDED
@@ -0,0 +1,57 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
25
+
26
+ guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
27
+ watch('config/application.rb')
28
+ watch('config/environment.rb')
29
+ watch('config/environments/test.rb')
30
+ watch(%r{^config/initializers/.+\.rb$})
31
+ watch('Gemfile.lock')
32
+ watch('spec/spec_helper.rb') { :rspec }
33
+ watch('test/test_helper.rb') { :test_unit }
34
+ watch(%r{features/support/}) { :cucumber }
35
+ end
36
+
37
+ guard :rspec do
38
+ watch(%r{^spec/.+_spec\.rb$})
39
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
40
+ watch('spec/spec_helper.rb') { "spec" }
41
+
42
+ # Rails example
43
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
44
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
45
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
46
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
47
+ watch('config/routes.rb') { "spec/routing" }
48
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
49
+
50
+ # Capybara features specs
51
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
52
+
53
+ # Turnip features and steps
54
+ watch(%r{^spec/acceptance/(.+)\.feature$})
55
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
56
+ end
57
+
@@ -26,7 +26,12 @@ module NicoQuery
26
26
  end
27
27
 
28
28
  def get
29
- RestClient.get uri.to_s
29
+ RestClient.get uri.to_s do |response, request, result, &block|
30
+ case response.code
31
+ when 200 || 403
32
+ response
33
+ end
34
+ end
30
35
  end
31
36
  end
32
37
  end
@@ -21,7 +21,7 @@ module NicoQuery
21
21
  end
22
22
 
23
23
  def params_array
24
- [format]
24
+ [format, 'numbers=1']
25
25
  end
26
26
 
27
27
  def format
@@ -25,8 +25,10 @@ module NicoQuery
25
25
  @movies = []
26
26
  @mylist_id = mylist_id
27
27
  source = (NicoQuery::Api::MylistRSS.new mylist_id).get
28
+
28
29
  @hash = NicoQuery::ObjectMapper::MylistRSS.new source
29
30
 
31
+ return if @hash.items.nil?
30
32
  @hash.items.map do |item|
31
33
  movie = NicoQuery::Object::Movie.new item.video_id
32
34
  movie.set_mylist_rss_source item
@@ -20,7 +20,7 @@ module NicoQuery
20
20
  end
21
21
 
22
22
  def description
23
- @hash['description']
23
+ @_description ||= Description.new @hash['description']
24
24
  end
25
25
 
26
26
  def thumbnail_url
@@ -91,7 +91,7 @@ module NicoQuery
91
91
  def tags
92
92
  xml = @xml.scan(/\<tags domain=\"jp\">\n.+\n\<\/tags\>/m)[0]
93
93
  parsed = Nokogiri::XML xml
94
- parsed.xpath("//tag").map do |tag_object|
94
+ parsed.xpath("//tag").map do |tag_object|
95
95
  generate_tag_hash_by tag_object
96
96
  end
97
97
  end
@@ -100,6 +100,7 @@ module NicoQuery
100
100
  @hash['user_id'].to_i
101
101
  end
102
102
 
103
+ private
103
104
  def generate_tag_hash_by(nokogiri_xml)
104
105
  text = nokogiri_xml.text
105
106
 
@@ -111,6 +112,35 @@ module NicoQuery
111
112
 
112
113
  { text: text, lock: lock }
113
114
  end
115
+
116
+ class Description
117
+ attr_reader :raw_text
118
+
119
+ def initialize(raw_text)
120
+ @raw_text = raw_text.to_s
121
+ end
122
+
123
+ def text
124
+ @raw_text
125
+ end
126
+
127
+ def movie_references
128
+ # is this the high road?
129
+ text.scan(/((sm|nm)\d{1,})/).map {|e| e[0]}
130
+ end
131
+
132
+ def mylist_references
133
+ text.scan(/(?<=mylist\/)\d{1,}/).map(&:to_i)
134
+ end
135
+
136
+ def community_references
137
+ text.scan(/co\d{1,}/)
138
+ end
139
+
140
+ def seiga_references
141
+ text.scan(/im\d{1,}/)
142
+ end
143
+ end
114
144
  end
115
145
  end
116
146
  end
@@ -5,17 +5,21 @@ module NicoQuery
5
5
  module ObjectMapper
6
6
  class MylistRSS
7
7
  attr_reader :meta, :items
8
+
8
9
  def initialize(xml)
9
10
  parser = Nori.new
10
11
  parsed_xml = parser.parse xml
11
12
  entire = parsed_xml['rss']['channel']
12
13
 
13
- @meta = Meta.new entire, title_prefix # noriは子要素が複数の場合は配列に変換するが、1つの場合には配列にしない。
14
- # しかし、MylistRSSはitemsが配列であること前提にしているので、item要素が
15
- # 1つだけの場合にも配列に変換する。
14
+ @meta = Meta.new entire, title_prefix
16
15
  if entire['item'].is_a? Array
17
16
  @items = entire['item'].map { |item| Item.new item }
17
+ elsif entire['item'].nil?
18
+ @items = []
18
19
  else
20
+ # noriは子要素が複数の場合は配列に変換するが、1つの場合には配列にしない。
21
+ # しかし、MylistRSSはitemsが配列であること前提にしているので、item要素が
22
+ # 1つだけの場合にも配列に変換する必要がある。
19
23
  @items = [ Item.new(entire['item']) ]
20
24
  end
21
25
  end
@@ -66,15 +70,6 @@ module NicoQuery
66
70
  end
67
71
 
68
72
  class Item
69
-
70
- # <item>
71
- # <title>【初音ミク】みくみくにしてあげる♪【してやんよ】</title>
72
- # <link>http://www.nicovideo.jp/watch/sm1097445</link>
73
- # <guid isPermaLink="false">tag:nicovideo.jp,2007-09-20:/watch/1190218917</guid>
74
- # <pubDate>Sat, 17 Aug 2013 22:54:20 +0900</pubDate>
75
- # <description><![CDATA[<p class="nico-thumbnail"><img alt="【初音ミク】みくみくにしてあげる♪【してやんよ】" src="http://tn-skr2.smilevideo.jp/smile?i=1097445" width="94" height="70" border="0"/></p><p class="nico-description">おまえら、みっくみくにしてやんよ。歌詞はhttp://ikamo.hp.infoseek.co.jp/mikumiku.txt(9/20 1:55修正)。上げている他のもの→mylist/1450136</p><p class="nico-info"><small><strong class="nico-info-length">1:38</strong>|<strong class="nico-info-date">2007年09月20日 01:22:02</strong> 投稿</small></p><p class="nico-numbers"><small>再生:<strong class="nico-numbers-view">10,643,217</strong>&nbsp;&#x20;コメント:<strong class="nico-numbers-res">2,726,450</strong>&nbsp;&#x20;マイリスト:<strong class="nico-numbers-mylist">210,310</strong></small></p>]]></description>
76
- # </item>
77
-
78
73
  def initialize(parsed_xml)
79
74
  @hash = parsed_xml
80
75
  end
@@ -144,7 +139,7 @@ module NicoQuery
144
139
  end
145
140
 
146
141
  def mylist_references
147
- text.scan /(?<=mylist\/)\d{1,}/
142
+ text.scan(/(?<=mylist\/)\d{1,}/).map(&:to_i)
148
143
  end
149
144
 
150
145
  def community_references
@@ -1,3 +1,3 @@
1
1
  module NicoQuery
2
- VERSION = "0.0.2.4"
2
+ VERSION = "0.0.3"
3
3
  end
data/nicoquery.gemspec CHANGED
@@ -30,4 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rspec"
31
31
  spec.add_development_dependency "watchr"
32
32
  spec.add_development_dependency "pry"
33
+ spec.add_development_dependency "guard"
34
+ spec.add_development_dependency "guard-rspec"
35
+ spec.add_development_dependency "webmock"
33
36
  end
@@ -1,16 +1,39 @@
1
1
  require 'nicoquery/api/mylist_rss'
2
+ require 'fixture/mylist_rss_18266317'
3
+ require 'webmock/rspec'
2
4
 
3
5
 
4
6
  describe "mylist_rss" do
5
- before do
6
- @instance = NicoQuery::Api::MylistRSS.new 18266317
7
- end
7
+ describe "when access an existing and public mylist" do
8
+ before do
9
+ @mylist_id = 18266317
10
+ @uri = "http://www.nicovideo.jp/mylist/#{@mylist_id}?rss=2.0&numbers=1"
11
+ @instance = NicoQuery::Api::MylistRSS.new @mylist_id
12
+ WebMock.stub_request :get, @uri
13
+ # WebMock.reset!
14
+ end
15
+
16
+ after(:all) do
17
+ WebMock.disable!
18
+ end
19
+
20
+ describe "get" do
21
+ before do
22
+ @instance.get
23
+ end
8
24
 
9
- describe "uri" do
10
- subject { @instance.uri }
25
+ it "should GET mylist rss resource" do
26
+ WebMock.should have_requested :get, @uri
27
+ end
28
+ end
11
29
 
12
- specify { expect(subject).to match /http:\/\/www\.nicovideo\.jp\/mylist/ }
13
- specify { expect(subject).to match /18266317/ }
14
- specify { expect(subject).to match /rss\=2\.0/ }
30
+ describe "uri" do
31
+ subject { @instance.uri }
32
+
33
+ specify { expect(subject).to match /http:\/\/www\.nicovideo\.jp\/mylist/ }
34
+ specify { expect(subject).to match /18266317/ }
35
+ specify { expect(subject).to match /rss\=2\.0/ }
36
+ end
15
37
  end
16
- end
38
+ end
39
+
@@ -0,0 +1,42 @@
1
+ module Fixture
2
+ def self.getthumbinfo_sm20415650
3
+ <<-EOS
4
+ <?xml version="1.0" encoding="UTF-8"?>
5
+ <nicovideo_thumb_response status="ok">
6
+ <thumb>
7
+ <video_id>sm20415650</video_id>
8
+ <title>【Minecraft】まったりクラフター生活 ~最終日~【ゆっくり実況】</title>
9
+ <description>最終日。ひっそりまったり通常営業...かな?ついにきました最終日。最後に最長の尺...画質が悪いかもです><今まで本当にありがとうございました!最後にゆっくりまったりしていってね(*´ヮ`*)シード値:-2086770116使用MOD1.Opti Fine2.MinecraftIM3.PlayerFormLittleMaid4.Audiotori r25.littleMaidMob+りばいあ製MOD×2(らいちんぐすてっき・ゆかり&らいちロボ)sm20221817←29日目⇔新シリーズ→sm21615389シリーズまとめ→mylist/29017292他に作ったもの→mylist/29022355twitter⇒http://twitter.com/raichi_Jコミュco1590050いただいたイラストclip/577830ゆかりテクスチャim2807664moyuさん作・ゆかりさんと私のメイドモデルim2466837</description>
10
+ <thumbnail_url>http://tn-skr3.smilevideo.jp/smile?i=20415650</thumbnail_url>
11
+ <first_retrieve>2013-03-23T23:10:32+09:00</first_retrieve>
12
+ <length>24:29</length>
13
+ <movie_type>mp4</movie_type>
14
+ <size_high>102398723</size_high>
15
+ <size_low>77315257</size_low>
16
+ <view_counter>25027</view_counter>
17
+ <comment_num>2171</comment_num>
18
+ <mylist_counter>722</mylist_counter>
19
+ <last_res_body>宿さんw wwwwww うっかりww チェーンソーwww wwww by武藤遊戯 部屋の隅に積まれたゲ </last_res_body>
20
+ <watch_url>http://www.nicovideo.jp/watch/sm20415650</watch_url>
21
+ <thumb_type>video</thumb_type>
22
+ <embeddable>1</embeddable>
23
+ <no_live_play>0</no_live_play>
24
+ <tags domain="jp">
25
+ <tag category="1" lock="1">ゲーム</tag>
26
+ <tag lock="1">Minecraft</tag>
27
+ <tag lock="1">ゆっくり実況プレイ</tag>
28
+ <tag lock="1">VOICEROID+_結月ゆかり</tag>
29
+ <tag lock="1">VOICEROID+_民安ともえ</tag>
30
+ <tag lock="1">らいち♪</tag>
31
+ <tag>ゆっくり実況プレイ最終回リンク</tag>
32
+ <tag>ゆかりお母さん</tag>
33
+ <tag>納得の感動</tag>
34
+ <tag>ラストを飾る壮大なうっかり</tag>
35
+ <tag>ゆかりさんの中の人巡回済み</tag>
36
+ </tags>
37
+ <user_id>4957110</user_id>
38
+ </thumb>
39
+ </nicovideo_thumb_response>
40
+ EOS
41
+ end
42
+ end