pixiv 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a15fda5ed4b1295bc489807d64ed2af7c8fc84e0
4
+ data.tar.gz: df8d3d98c7bc4eb398f8b83b11828db630bba4e8
5
+ SHA512:
6
+ metadata.gz: 57e2290c398f7f287bf20d0bbe57c8062f516b292626088ede1b5d0efa640f8e0cdc5948749c123860c7acc060c0d770848d1f869065e7f8d5b0d7606a40d803
7
+ data.tar.gz: 7d370d9351429439a49f00de960812b699514c1c4fe5a63b1f94eaca6863bcc564e83653fea63d06ca818f43be0817ac6531300b732424b4ed8849eecd032ca3
data/Changelog.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 2013-09-01 0.0.9
4
+
5
+ - Updated for new pixiv layout and added tests (thanks @co-me!)
6
+ - Fixed broken xpaths for medium- and original-sized images
7
+ - Fixed a bug where `Pixiv::Client#work_list` would raise an error
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
data/README.md CHANGED
@@ -56,7 +56,7 @@ member.works.each do |illust|
56
56
  end
57
57
 
58
58
  me = pixiv.member
59
- me.bookmarks do |illust|
59
+ me.bookmarks.each do |illust|
60
60
  author = illust.member
61
61
  puts author.name
62
62
  puts author.works.count
@@ -7,7 +7,7 @@ module Pixiv
7
7
 
8
8
  # @return [Integer]
9
9
  lazy_attr_reader(:total_count) {
10
- node = at!('a[href="/bookmark.php?type=illust_all"]')
10
+ node = at!('.column-label .count-badge')
11
11
  node.inner_text[/\d+/].to_i
12
12
  }
13
13
  # @return [Array<Hash{Symbol=>Object}, nil>]
data/lib/pixiv/client.rb CHANGED
@@ -74,7 +74,7 @@ module Pixiv
74
74
  def work_list(member_or_id = member_id, page = 1)
75
75
  list = illust_list_with_class(WorkList, member_or_id, page)
76
76
  # Cheat; member_name will not found on your own work list.
77
- list.send(:set_attrs!, member_name: member_name) if list.owner_id == member_id
77
+ list.send(:set_attrs!, member_name: member.name) if list.owner_id == member_id
78
78
  list
79
79
  end
80
80
 
data/lib/pixiv/illust.rb CHANGED
@@ -15,9 +15,9 @@ module Pixiv
15
15
  # @return [String]
16
16
  lazy_attr_reader(:small_image_url) { at!('meta[property="og:image"]')['content'] }
17
17
  # @return [String]
18
- lazy_attr_reader(:medium_image_url) { image_url_components.join('_m') }
18
+ lazy_attr_reader(:medium_image_url) { at!('.works_display img')['src'] }
19
19
  # @return [String]
20
- lazy_attr_reader(:original_image_url) { illust? && image_url_components.join('') }
20
+ lazy_attr_reader(:original_image_url) { illust? ? image_url_components.join('') : nil }
21
21
  # @return [Array<String>]
22
22
  lazy_attr_reader(:original_image_urls) {
23
23
  illust? ? [original_image_url]
@@ -68,15 +68,11 @@ module Pixiv
68
68
  def illust?; !manga? end
69
69
  # @return [Boolean]
70
70
  def manga?; !!num_pages end
71
- # @return [String]
72
- def medium_image_url; image_url_components.join('_m') end
73
- # @return [String]
74
- def original_image_url; image_url_components.join('') end
75
71
 
76
72
  private
77
73
 
78
74
  def image_url_components
79
- @image_url_components ||= small_image_url.match(%r{^(.+)_s(\.\w+(?:\?\d+)?)$}).to_a[1, 3]
75
+ @image_url_components ||= medium_image_url.match(%r{^(.+)_m(\.\w+(?:\?\d+)?)$}).to_a[1, 3]
80
76
  end
81
77
  end
82
78
 
@@ -20,11 +20,13 @@ module Pixiv
20
20
 
21
21
  # @return [Integer]
22
22
  lazy_attr_reader(:page) {
23
- at!('ul.page-list .current').inner_text.to_i
23
+ node = doc.at('ul.page-list .current')
24
+ node ? node.inner_text.to_i : 1
24
25
  }
25
26
  # @return [Boolean]
26
27
  lazy_attr_reader(:last?) {
27
- at!('ul.page-list .current').next_element.nil?
28
+ node = doc.at('ul.page-list .current')
29
+ node ? node.next_element.nil? : true
28
30
  }
29
31
  # @return [Integer]
30
32
  lazy_attr_reader(:member_id) {
@@ -71,4 +73,4 @@ module Pixiv
71
73
  # @!parse alias owner member
72
74
  def owner; member end
73
75
  end
74
- end
76
+ end
@@ -63,16 +63,17 @@ module Pixiv
63
63
  attr_reader :search_opts
64
64
 
65
65
  lazy_attr_reader(:page) {
66
- at!('.pager li.current').inner_text.to_i
66
+ node = doc.at('.page-list li.current')
67
+ node ? node.inner_text.to_i : 1
67
68
  }
68
69
  lazy_attr_reader(:last?) {
69
- doc.at('//nav[@class="pager"]//a[@rel="next"]').nil?
70
+ doc.at('//div[@class="pager-container"]//a[@rel="next"]').nil?
70
71
  }
71
72
  lazy_attr_reader(:total_count) {
72
- at!('.info > .count').inner_text.to_i
73
+ at!('.column-label > .count-badge').inner_text.to_i
73
74
  }
74
75
  lazy_attr_reader(:page_hashes) {
75
- search!('#search-result li.image').map {|n| hash_from_list_item(n) }
76
+ search!('.column-search-result li.image-item').map {|n| hash_from_list_item(n) }
76
77
  }
77
78
 
78
79
  def url
@@ -112,17 +113,17 @@ module Pixiv
112
113
  private
113
114
 
114
115
  def hash_from_list_item(node)
115
- member_node = node.at('p.user a')
116
- illust_node = node.at('a')
116
+ member_node = node.at('.user')
117
+ illust_node = node.at('.work')
117
118
  illust_id = illust_node['href'][/illust_id=(\d+)/, 1].to_i
118
119
  {
119
120
  url: Illust.url(illust_id),
120
121
  illust_id: illust_id,
121
- title: illust_node.at('h2').inner_text,
122
+ title: illust_node.at('h1').inner_text,
122
123
  member_id: member_node['href'][/\?id=(\d+)/, 1].to_i,
123
124
  member_name: member_node.inner_text,
124
125
  small_image_url: illust_node.at('img')['src'],
125
126
  }
126
127
  end
127
128
  end
128
- end
129
+ end
data/lib/pixiv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pixiv
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -7,14 +7,14 @@ module Pixiv
7
7
 
8
8
  # @return [Integer]
9
9
  lazy_attr_reader(:total_count) {
10
- node = at!('.layout-cell .count-badge')
10
+ node = at!('.manage-unit .count-badge')
11
11
  node.inner_text[/\d+/].to_i
12
12
  }
13
13
  # @return [String, nil] member_name
14
14
  # member_name == nil if this work list is your own
15
15
  lazy_attr_reader(:member_name) {
16
- node = doc.at('.profile_area a')
17
- node && node['title']
16
+ node = doc.at('.profile-unit h1')
17
+ node && node.inner_text
18
18
  }
19
19
  # @return [Array<Hash{Symbol=>Object}, nil>]
20
20
  lazy_attr_reader(:page_hashes) {
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Member #6 Bookmarks</title>
6
+ <script>
7
+ pixiv.context.userId = '6';
8
+ </script>
9
+ </head>
10
+ <body>
11
+ <div class="_unit action-unit">
12
+ <div class="column-label">
13
+ <span class="count-badge">1234件</span>
14
+ </div>
15
+ <nav class="column-order-menu">
16
+ <div class="pager-container">
17
+ <ul class="page-list">
18
+ <li>1</li>
19
+ <li class="current">2</li>
20
+ <li>3</li>
21
+ </ul>
22
+ <span class="next"><a rel="next"></a></span>
23
+ </div>
24
+ </nav>
25
+ <div class="display_works">
26
+ <ul>
27
+ <li id="li_98765">
28
+ <a href="/member_illust.php?illust_id=123" class="work"><img src="http://i1.pixiv.net/img1/img/hanako/123_s.jpg" />Illust #123</a>
29
+ <br>
30
+ <a href="member_illust.php?id=456">Hanako</a>
31
+ </li>
32
+ </ul>
33
+ </div>
34
+ </div>
35
+ <div class="_unit profile-unit">
36
+ <a href="/member.php?id=6">
37
+ <h1 class="user">Sayoko</h1>
38
+ </a>
39
+ </div>
40
+ </body>
41
+ </html>
@@ -0,0 +1,37 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Member #6 Works</title>
6
+ <script>
7
+ pixiv.context.userId = '6';
8
+ </script>
9
+ </head>
10
+ <body>
11
+ <div class="_unit manage-unit">
12
+ <span class="count-badge">123件</span>
13
+ <ul class="column-order-menu">
14
+ <div class="pager-container">
15
+ <ul class="page-list">
16
+ <li>1</li>
17
+ <li class="current">2</li>
18
+ <li>3</li>
19
+ </ul>
20
+ <span class="next"><a rel="next"></a></span>
21
+ </div>
22
+ </ul>
23
+ <div class="display_works">
24
+ <ul>
25
+ <li class="image-item">
26
+ <a href="/member_illust.php?illust_id=345" class="work"><img src="http://i1.pixiv.net/img1/img/sayoko/345_s.jpg" /><h1>Illust #345</h1></a>
27
+ </li>
28
+ </ul>
29
+ </div>
30
+ </div>
31
+ <div class="_unit profile-unit">
32
+ <a href="/member.php?id=6">
33
+ <h1 class="user">Sayoko</h1>
34
+ </a>
35
+ </div>
36
+ </body>
37
+ </html>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Search hoge</title>
6
+ </head>
7
+ <body>
8
+ <div class="_unit">
9
+ <div class="column-label">
10
+ <!-- total_count = 12345 -->
11
+ <span class="count-badge">12345件</span>
12
+ </div>
13
+ <div class="pager-container">
14
+ <ul class="page-list">
15
+ <li>1</li>
16
+ <!-- page = 2 -->
17
+ <li class="current">2</li>
18
+ <li>3</li>
19
+ </ul>
20
+ <!-- last? = false -->
21
+ <span class="next"><a rel="next"></a></span>
22
+ </div>
23
+
24
+ <!-- page_hashes -->
25
+ <section class="column-search-result">
26
+ <ul>
27
+ <li class="image-item">
28
+ <a href="/member_illust.php?illust_id=345" class="work">
29
+ <img src="http://i1.pixiv.net/img1/img/sayoko/345_s.jpg" />
30
+ <h1>Illust #345</h1>
31
+ </a>
32
+ <a href="/member_illust.php?id=6" class="user">Sayoko</a>
33
+ </li>
34
+ </ul>
35
+ </section>
36
+ </div>
37
+ </body>
38
+ </html>
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pixiv::BookmarkList do
4
+ describe '.new' do
5
+ before do
6
+ agent = Mechanize.new
7
+ @doc = agent.get(File.join('file://', fixture_path, 'member_6_bookmark_list.html'))
8
+ end
9
+ subject { Pixiv::BookmarkList.new(@doc) }
10
+ its(:total_count) { should == 1234 }
11
+ its(:page_hashes) {
12
+ should == [
13
+ { :url => 'http://www.pixiv.net/member_illust.php?mode=medium&illust_id=123',
14
+ :illust_id => 123,
15
+ :title => 'Illust #123',
16
+ :member_id => 456,
17
+ :member_name => 'Hanako',
18
+ :small_image_url => 'http://i1.pixiv.net/img1/img/hanako/123_s.jpg' }
19
+ ]
20
+ }
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pixiv::SearchResultList do
4
+ describe '.new' do
5
+ before do
6
+ @doc = fixture_as_doc('search_hoge.html')
7
+ @attrs = {
8
+ query: 'hoge',
9
+ search_opts: {}
10
+ }
11
+ end
12
+ subject { Pixiv::SearchResultList.new(@doc, @attrs) }
13
+ its(:page) { should == 2 }
14
+ its(:last?) { should == false }
15
+ its(:total_count) { should == 12345 }
16
+ its(:page_hashes) {
17
+ should == [
18
+ { :url => 'http://www.pixiv.net/member_illust.php?mode=medium&illust_id=345',
19
+ :illust_id => 345,
20
+ :title => 'Illust #345',
21
+ :member_id => 6,
22
+ :member_name => 'Sayoko',
23
+ :small_image_url => 'http://i1.pixiv.net/img1/img/sayoko/345_s.jpg' }
24
+ ]
25
+ }
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pixiv::WorkList do
4
+ describe '.new' do
5
+ before do
6
+ agent = Mechanize.new
7
+ @doc = agent.get(File.join('file://', fixture_path, 'member_6_work_list.html'))
8
+ end
9
+ subject { Pixiv::WorkList.new(@doc) }
10
+ its(:total_count) { should == 123 }
11
+ its(:member_name) { should == "Sayoko" }
12
+ its(:page_hashes) {
13
+ should == [
14
+ { :url => 'http://www.pixiv.net/member_illust.php?mode=medium&illust_id=345',
15
+ :illust_id => 345,
16
+ :title => 'Illust #345',
17
+ :member_id => 6,
18
+ :member_name => 'Sayoko',
19
+ :small_image_url => 'http://i1.pixiv.net/img1/img/sayoko/345_s.jpg' }
20
+ ]
21
+ }
22
+ end
23
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixiv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
5
- prerelease:
4
+ version: 0.0.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tomoki Aonuma
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
11
+ date: 2013-09-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mechanize
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,23 +27,20 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.8.7
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.8.7
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: webmock
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -84,6 +75,7 @@ extra_rdoc_files: []
84
75
  files:
85
76
  - .gitignore
86
77
  - .travis.yml
78
+ - Changelog.md
87
79
  - Gemfile
88
80
  - LICENSE.txt
89
81
  - README.md
@@ -106,40 +98,51 @@ files:
106
98
  - spec/fixtures/empty.html
107
99
  - spec/fixtures/illust_345.html
108
100
  - spec/fixtures/member_6.html
101
+ - spec/fixtures/member_6_bookmark_list.html
102
+ - spec/fixtures/member_6_work_list.html
103
+ - spec/fixtures/search_hoge.html
104
+ - spec/pixiv/bookmark_list_spec.rb
109
105
  - spec/pixiv/illust_spec.rb
110
106
  - spec/pixiv/member_spec.rb
111
107
  - spec/pixiv/page_spec.rb
108
+ - spec/pixiv/search_result_list_spec.rb
109
+ - spec/pixiv/work_list_spec.rb
112
110
  - spec/spec_helper.rb
113
111
  homepage: https://github.com/uasi/pixiv
114
112
  licenses: []
113
+ metadata: {}
115
114
  post_install_message:
116
115
  rdoc_options: []
117
116
  require_paths:
118
117
  - lib
119
118
  required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
119
  requirements:
122
- - - ! '>='
120
+ - - '>='
123
121
  - !ruby/object:Gem::Version
124
122
  version: '0'
125
123
  required_rubygems_version: !ruby/object:Gem::Requirement
126
- none: false
127
124
  requirements:
128
- - - ! '>='
125
+ - - '>='
129
126
  - !ruby/object:Gem::Version
130
127
  version: '0'
131
128
  requirements: []
132
129
  rubyforge_project:
133
- rubygems_version: 1.8.23
130
+ rubygems_version: 2.0.3
134
131
  signing_key:
135
- specification_version: 3
132
+ specification_version: 4
136
133
  summary: A client library for pixiv
137
134
  test_files:
138
135
  - spec/fixtures/empty.html
139
136
  - spec/fixtures/illust_345.html
140
137
  - spec/fixtures/member_6.html
138
+ - spec/fixtures/member_6_bookmark_list.html
139
+ - spec/fixtures/member_6_work_list.html
140
+ - spec/fixtures/search_hoge.html
141
+ - spec/pixiv/bookmark_list_spec.rb
141
142
  - spec/pixiv/illust_spec.rb
142
143
  - spec/pixiv/member_spec.rb
143
144
  - spec/pixiv/page_spec.rb
145
+ - spec/pixiv/search_result_list_spec.rb
146
+ - spec/pixiv/work_list_spec.rb
144
147
  - spec/spec_helper.rb
145
148
  has_rdoc: