nicoquery 0.1.7 → 0.1.8

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: 892894c341bcd1e2a22b5483cdd92a4fa403e04c
4
- data.tar.gz: aac4c5d4c0922f346d6edb4952b0361eabb71bf1
3
+ metadata.gz: 1d97bc8ec57f8b66e8c9ea690e626108d4623e93
4
+ data.tar.gz: 83772ec763bc93b2f188101582fda451d4b1b6eb
5
5
  SHA512:
6
- metadata.gz: b307defe02cbee30fe4e253bfbf67c6a320a5507e8ae9ec700008c1d81a88207de01a0cdd55d38a7fccddc5fbbd51bbd9ddb88bd4846d260fcb39a7b27a8aa60
7
- data.tar.gz: fa01f1f31a6b5200d74be4612c46ca2cc65ed7ab785c725d09ad5d19ecaa738e0bd59145329042d2f3a72a8051356411ab96691c98851b9fbfffe737adc998c4
6
+ metadata.gz: 8ea629c1510df67bf7932eeca3787f79bd3b827e3e9864a6e9134d8c04cbb51a65466e75a6c62735c114231c4c8dc194bd4c42e5955eeb1c114096a251b4e05d
7
+ data.tar.gz: eddde06634911d353a717a9fc7c93f13e4cffb7dcd8a8843a85187688ea5896b988317b0bf6d19dea5916ada42e274e4341e4c3ff517c37df321783af90fedea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nicoquery (0.1.7)
4
+ nicoquery (0.1.8)
5
5
  activesupport (~> 4.0.0)
6
6
  i18n
7
7
  nicoapi
@@ -18,21 +18,21 @@ module NicoQuery
18
18
  'last_build_date',
19
19
  'creator',
20
20
  ].each do |field_name|
21
- define_method(field_name) { @hash.meta.send field_name }
21
+ define_method(field_name) do
22
+ if available?
23
+ @source_object.meta.send field_name
24
+ else
25
+ nil
26
+ end
27
+ end
22
28
  end
23
29
 
24
30
  def initialize(mylist_id)
25
31
  @movies = []
26
32
  @mylist_id = mylist_id
27
- @response = (NicoQuery::Api::MylistRSS.new mylist_id).get
28
- @hash = NicoQuery::ObjectMapper::MylistRSS.new @response[:body]
29
-
30
- return if @hash.items.nil?
31
- @hash.items.map do |item|
32
- movie = NicoQuery::Object::Movie.new item.video_id.presence || item.thread_id
33
- movie.set_mylist_rss_source item
34
- @movies.push movie
35
- end
33
+ @response_xml = (NicoQuery::Api::MylistRSS.new mylist_id).get
34
+ @source_object = source_object
35
+ set_hash_items
36
36
  end
37
37
 
38
38
  def available?
@@ -40,11 +40,48 @@ module NicoQuery
40
40
  end
41
41
 
42
42
  def forbidden?
43
- @response[:status_code] == 403
43
+ @response_xml[:status_code] == 403
44
44
  end
45
45
 
46
46
  def exist?
47
- @response[:status_code] != 404
47
+ @response_xml[:status_code] != 404
48
+ end
49
+
50
+ private
51
+
52
+ def source_object
53
+ NicoQuery::ObjectMapper::MylistRSS.new @response_xml[:body].presence || null_response_xml
54
+ end
55
+
56
+ def set_hash_items
57
+ @source_object.items.each do |item|
58
+ movie = NicoQuery::Object::Movie.new item.video_id.presence || item.thread_id
59
+ movie.set_mylist_rss_source item
60
+ @movies.push movie
61
+ end
62
+ end
63
+
64
+ def null_response_xml
65
+ <<-EOS
66
+ <?xml version="1.0" encoding="utf-8"?>
67
+ <rss version="2.0"
68
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
69
+ xmlns:atom="http://www.w3.org/2005/Atom">
70
+ <channel>
71
+ <title></title>
72
+ <link></link>
73
+ <atom:link rel="self" type="application/rss+xml" href="http://www.nicovideo.jp/mylist/38350049?rss=2.0"/>
74
+ <description></description>
75
+ <pubDate></pubDate>
76
+ <lastBuildDate></lastBuildDate>
77
+ <generator></generator>
78
+ <dc:creator></dc:creator>
79
+ <language></language>
80
+ <copyright></copyright>
81
+ <docs></docs>
82
+ </channel>
83
+ </rss>
84
+ EOS
48
85
  end
49
86
  end
50
87
  end
@@ -1,3 +1,3 @@
1
1
  module NicoQuery
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -6,15 +6,14 @@ require 'webmock/rspec'
6
6
  describe "mylist_rss" do
7
7
  describe "when access an existing and public mylist" do
8
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!
9
+ WebMock.enable!
10
+ WebMock.stub_request(:get, "http://www.nicovideo.jp/mylist/18266317?numbers=1&rss=2.0").
11
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
12
+ to_return(:status => 200, :body => Fixture.mylist_rss_18266317, :headers => {})
13
+
14
+ mylist_id = 18266317
15
+ @uri = "http://www.nicovideo.jp/mylist/#{mylist_id}?rss=2.0&numbers=1"
16
+ @instance = NicoQuery::Api::MylistRSS.new mylist_id
18
17
  end
19
18
 
20
19
  describe "get" do
@@ -5,7 +5,7 @@ describe "NicoQuery::Crawler" do
5
5
  describe "VideoArray" do
6
6
  before do
7
7
  @acquired_movies = []
8
-
8
+ WebMock.disable! # TODO: WebMockを利用する。
9
9
  NicoQuery::Crawler::BulkScraping.execute(['sm20415650', 'sm9']) do |result|
10
10
  @acquired_movies.push result
11
11
  end
@@ -1,4 +1,6 @@
1
1
  require "nicoquery/crawler/tag_search"
2
+ require "fixture/tag_search_yukkuri_page1"
3
+ require "fixture/tag_search_yukkuri_page2"
2
4
 
3
5
 
4
6
  describe "NicoQuery:Crawler" do
@@ -7,6 +9,14 @@ describe "NicoQuery:Crawler" do
7
9
  counter = 0
8
10
  @acquired_movies = []
9
11
 
12
+ WebMock.stub_request(:get, "http://www.nicovideo.jp/tag/%E3%82%86%E3%81%A3%E3%81%8F%E3%82%8A%E5%AE%9F%E6%B3%81%E3%83%97%E3%83%AC%E3%82%A4?numbers=1&order=a&page=1&rss=2.0&sort=f").
13
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
14
+ to_return(:status => 200, :body => Fixture.tag_search_yukkuri_page1, :headers => {})
15
+
16
+ WebMock.stub_request(:get, "http://www.nicovideo.jp/tag/%E3%82%86%E3%81%A3%E3%81%8F%E3%82%8A%E5%AE%9F%E6%B3%81%E3%83%97%E3%83%AC%E3%82%A4?numbers=1&order=a&page=2&rss=2.0&sort=f").
17
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}).
18
+ to_return(:status => 200, :body => Fixture.tag_search_yukkuri_page2, :headers => {})
19
+
10
20
  NicoQuery::Crawler::TagSearch.execute( tag: "ゆっくり実況プレイ",
11
21
  sort: :published_at,
12
22
  order: :asc
@@ -17,6 +27,10 @@ describe "NicoQuery:Crawler" do
17
27
  end
18
28
  end
19
29
 
30
+ specify "it returns NicoQuery::Object::Movie instance in the block" do
31
+ expect(@acquired_movies[0]).to be_an_instance_of NicoQuery::Object::Movie
32
+ end
33
+
20
34
  it "should sorted by published date" do
21
35
  expect(@acquired_movies[0].publish_date).to be < @acquired_movies[1].publish_date
22
36
  end