sosowa 0.7 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.8
2
+
3
+ * Mechanizeの代わりにNokogiriを使い始めました。
4
+ * バグ修正
5
+
1
6
  ## 0.7
2
7
 
3
8
  * 新板創想話レイアウトに対応
data/lib/sosowa/parser.rb CHANGED
@@ -1,21 +1,18 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Sosowa
4
- class Parser
5
-
4
+ class Parser
6
5
  def initialize
7
- @agent = Mechanize.new
8
- @agent.user_agent = "Sosowa Ruby #{Sosowa::VERSION}"
6
+
9
7
  end
10
8
 
11
9
  def search(query, args={})
12
- params = Sosowa.serialize_parameter({:mode => :search, :type => (args[:type] ? args[:type] : :insubject), :query => query.tosjis})
13
- parse_index(@agent.get(URI.join(Sosowa::BASE_URL, params)))
10
+ page = Sosowa.send_req({:mode => :search, :type => (args[:type] ? args[:type] : :insubject), :query => query.tosjis})
11
+ parse_index(page)
14
12
  end
15
13
 
16
14
  def fetch_index(log)
17
- params = Sosowa.serialize_parameter({:log => log})
18
- page = @agent.get(URI.join(Sosowa::BASE_URL, params))
15
+ page = Sosowa.send_req({:log => log})
19
16
  indexes = parse_index(page)
20
17
  abs_log_num = parse_absolute_log_number(page)
21
18
  Log.new(indexes, page, abs_log_num)
@@ -43,23 +40,20 @@ module Sosowa
43
40
  tr = tr[1, tr.size-1]
44
41
  num = 1
45
42
  tr.each do |tr|
46
- if (tr/%{td[@class="tags"]}).size > 0
47
- #tags = (tr/%{td[@class="tags"]})[0].inner_html.to_s.toutf8.strip.gsub(/^.+?: /, "").split(/\s/)
48
- #indexes[num-1] << tags
49
- else
50
- title = tr.search(%{td[@class="title cell_title"] > a}).inner_html.to_s.toutf8.strip
43
+ unless (tr/%{td[@class="tags"]}).size > 0
44
+ title = tr.search(%{td[@class="title cell_title"] > a})[0].children[0].text.strip
51
45
  tags = tr.search(%{td[@class="title cell_title"] > a})[0].attributes["title"].value.split(" / ").reject{|n| n == ""}
52
46
  log = parse_absolute_log_number(page)
53
47
  key = tr.search(%{td[@class="title cell_title"] > a})[0].attributes["href"].value.gsub(/^.+key=(.+?)&.+$/, '\1').to_i
54
- author = tr.search(%{td[@class="cell_author"]}).inner_html.to_s.toutf8.strip
55
- created_at = Time.parse(tr.search(%{td[@class="cell_created"]}).inner_html.to_s.toutf8.strip)
56
- updated_at = Time.parse(tr.search(%{td[@class="cell_lastup"]}).inner_html.to_s.toutf8.strip)
57
- eval = tr.search(%{td[@class="cell_eval"]}).inner_html.to_s.toutf8.strip.split("/")
48
+ author = tr.search(%{td[@class="cell_author"]})[0].inner_html.to_s.strip
49
+ created_at = Time.parse(tr.search(%{td[@class="cell_created"]})[0].inner_html.to_s.strip)
50
+ updated_at = Time.parse(tr.search(%{td[@class="cell_lastup"]})[0].inner_html.to_s.strip)
51
+ eval = tr.search(%{td[@class="cell_eval"]})[0].inner_html.to_s.strip.split("/")
58
52
  review_count = eval[1].to_i
59
53
  comment_count = eval[0].to_i
60
- point = tr.search(%{td[@class="cell_point"]}).inner_html.to_s.toutf8.strip.to_i
61
- rate = tr.search(%{td[@class="cell_rate"]}).inner_html.to_s.toutf8.strip.to_f
62
- size = tr.search(%{td[@class="cell_size"]}).inner_html.to_s.toutf8.strip
54
+ point = tr.search(%{td[@class="cell_point"]})[0].inner_html.to_s.strip.to_i
55
+ rate = tr.search(%{td[@class="cell_rate"]})[0].inner_html.to_s.strip.to_f
56
+ size = tr.search(%{td[@class="cell_size"]})[0].inner_html.to_s.strip
63
57
  url = tr.search(%{td[@class="title cell_title"] > a})[0].attributes["href"].value
64
58
  index = {
65
59
  :log => log,
data/lib/sosowa/scheme.rb CHANGED
@@ -24,14 +24,12 @@ module Sosowa
24
24
  def initialize(args)
25
25
  @log = args[:log] || 0
26
26
  @key = args[:key]
27
- @agent = Mechanize.new
28
27
  @page = nil
29
28
  super(fetch(@log, @key))
30
29
  end
31
30
 
32
31
  def fetch(log, key)
33
- params = Sosowa.serialize_parameter({:mode => :read, :log => log, :key => key})
34
- @page = @agent.get(URI.join(Sosowa::BASE_URL, params))
32
+ @page = Sosowa.send_req({:mode => :read, :log => log, :key => key})
35
33
  title = (@page/%{div[@class="header"] > h1})[0].inner_html.to_s.toutf8.strip
36
34
  tags = (@page/%{dl[@class="info"][1] > dd > a}).map{|t| t.inner_html.to_s.toutf8 }
37
35
  text = ""
@@ -1,3 +1,3 @@
1
1
  module Sosowa
2
- VERSION = "0.7"
2
+ VERSION = "0.8"
3
3
  end
data/lib/sosowa.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require "kconv"
4
- require "mechanize"
4
+ require "nokogiri"
5
+ require "net/http"
5
6
  require "time"
6
7
  require "uri"
7
8
 
@@ -11,7 +12,7 @@ require "sosowa/scheme"
11
12
  require "sosowa/parser"
12
13
 
13
14
  module Sosowa
14
- BASE_URL = "http://coolier.sytes.net:8080/sosowa/ssw_l/"
15
+ BASE_URL = URI.parse("http://coolier.sytes.net:8080/sosowa/ssw_l/")
15
16
 
16
17
  protected
17
18
 
@@ -27,6 +28,18 @@ module Sosowa
27
28
  return param ? param : ""
28
29
  end
29
30
 
31
+ def self.send_req(args)
32
+ params = serialize_parameter(args)
33
+ path = BASE_URL.path.dup.concat(params)
34
+
35
+ Net::HTTP.version_1_2
36
+ Net::HTTP.start(BASE_URL.host, BASE_URL.port) do |http|
37
+ response = http.get(path, 'User-Agent' => "Sosowa Ruby Wrapper #{Sosowa::VERSION}")
38
+ return Nokogiri::HTML(response.body.toutf8)
39
+ end
40
+ return false
41
+ end
42
+
30
43
  public
31
44
 
32
45
  def self.get(args={})
data/sosowa.gemspec CHANGED
@@ -14,5 +14,5 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "sosowa"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Sosowa::VERSION
17
- gem.add_dependency "mechanize"
17
+ gem.add_dependency "nokogiri"
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sosowa
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ cert_chain: []
12
12
  date: 2012-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: mechanize
15
+ name: nokogiri
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
@@ -68,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  segments:
70
70
  - 0
71
- hash: -181387724163016397
71
+ hash: 2832224330215287020
72
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  segments:
79
79
  - 0
80
- hash: -181387724163016397
80
+ hash: 2832224330215287020
81
81
  requirements: []
82
82
  rubyforge_project:
83
83
  rubygems_version: 1.8.24