sosowa 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.1
2
+
3
+ * コメント関連のバグを修成
4
+
1
5
  ## 1.0
2
6
 
3
7
  * created_at, updated_atで%Y/%m/%d %H:%M:%S形式で返すよう変更
data/README.md CHANGED
@@ -8,7 +8,7 @@ samples/に各種サンプルが入っています。
8
8
  ## Requirements
9
9
 
10
10
  * Ruby 1.9.x
11
- * mechanize gem
11
+ * Nokogiri gem
12
12
 
13
13
  ## Installation
14
14
 
data/lib/sosowa/scheme.rb CHANGED
@@ -21,6 +21,10 @@ module Sosowa
21
21
  end
22
22
 
23
23
  class Novel < Scheme
24
+ attr_reader :log
25
+ attr_reader :key
26
+ attr_reader :page
27
+
24
28
  def initialize(args)
25
29
  @log = args[:log] || 0
26
30
  @key = args[:key]
@@ -81,18 +85,59 @@ module Sosowa
81
85
  end
82
86
 
83
87
  def simple_rating(point)
84
- form = @page.forms[0]
85
- form.click_button(form.button_with(:value => point.to_s))
88
+ # Get cookie
89
+ get_params = Sosowa.serialize_parameter({
90
+ :mode => :read,
91
+ :key => @key,
92
+ :log => @log
93
+ })
94
+ http = Net::HTTP.new(BASE_URL.host, BASE_URL.port)
95
+ req = Net::HTTP::Get.new(BASE_URL.path)
96
+ req["User-Agent"] = "Sosowa Ruby Wrapper #{Sosowa::VERSION}"
97
+ res = http.request(req, get_params)
98
+ cookie = res["Set-Cookie"]
99
+
100
+ # Post Comment
101
+ post_uri_params = Sosowa.serialize_parameter({
102
+ :mode => :update,
103
+ :key => @key,
104
+ :log => @log,
105
+ :target => :res
106
+ })
107
+ post_params = Sosowa.serialize_parameter({:body => "#EMPTY#".tosjis, :point => point}), false)
108
+ req = Net::HTTP::Post.new(File.join(BASE_URL.path, post_uri_params))
109
+ req["Cookie"] = cookie
110
+ req["User-Agent"] = "Sosowa Ruby Wrapper #{Sosowa::VERSION}"
111
+ res = http.request(req, post_params)
112
+ return res
86
113
  end
87
114
 
88
- def comment(text, params)
89
- form = @page.forms[1]
90
- form.field_with(:name => "name").value = params[:name] || nil
91
- form.field_with(:name => "body").value = text
92
- form.field_with(:name => "pass").value = params[:pass] || nil
93
- form.field_with(:name => "mail").value = params[:mail] || nil
94
- form.field_with(:name => "point").option_with(:value => (params[:point].to_s || "0")).select
95
- form.click_button
115
+ def comment(text, params={})
116
+ # Get cookie
117
+ get_params = Sosowa.serialize_parameter({
118
+ :mode => :read,
119
+ :key => @key,
120
+ :log => @log
121
+ })
122
+ http = Net::HTTP.new(BASE_URL.host, BASE_URL.port)
123
+ req = Net::HTTP::Get.new(BASE_URL.path)
124
+ req["User-Agent"] = "Sosowa Ruby Wrapper #{Sosowa::VERSION}"
125
+ res = http.request(req, get_params)
126
+ cookie = res["Set-Cookie"]
127
+
128
+ # Post Comment
129
+ post_uri_params = Sosowa.serialize_parameter({
130
+ :mode => :update,
131
+ :key => @key,
132
+ :log => @log,
133
+ :target => :res
134
+ })
135
+ post_params = Sosowa.serialize_parameter({:body => text.tosjis}.update(params.map{|p| p.tosjis}), false)
136
+ req = Net::HTTP::Post.new(File.join(BASE_URL.path, post_uri_params))
137
+ req["Cookie"] = cookie
138
+ req["User-Agent"] = "Sosowa Ruby Wrapper #{Sosowa::VERSION}"
139
+ res = http.request(req, post_params)
140
+ return res
96
141
  end
97
142
 
98
143
  def plain
@@ -1,3 +1,3 @@
1
1
  module Sosowa
2
- VERSION = "1.0"
2
+ VERSION = "1.1"
3
3
  end
data/lib/sosowa.rb CHANGED
@@ -18,19 +18,25 @@ module Sosowa
18
18
 
19
19
  # @param [Hash] parameter
20
20
  # @return [String] URL Serialized parameters
21
- def self.serialize_parameter parameter
21
+ def self.serialize_parameter(parameter, add_prefix=true)
22
22
  return "" unless parameter.class == Hash
23
23
  ant = Hash.new
24
24
  parameter.each do |key, value|
25
25
  ant[key.to_sym] = value.to_s
26
26
  end
27
- param = ant.inject(""){|k,v|k+"&#{v[0]}=#{URI.escape(v[1])}"}.sub!(/^&/,"?")
27
+ param = ant.inject(""){|k,v|k+"&#{v[0]}=#{URI.escape(v[1])}"}
28
+ if add_prefix
29
+ param.sub!(/^&/,"?")
30
+ else
31
+ param.sub!(/^&/,"")
32
+ end
28
33
  return param ? param : ""
29
34
  end
30
35
 
31
36
  def self.send_req(args)
32
37
  params = serialize_parameter(args)
33
- path = BASE_URL.path.dup.concat(params)
38
+ path = File.join(BASE_URL.path, params)
39
+ pp path
34
40
 
35
41
  Net::HTTP.version_1_2
36
42
  Net::HTTP.start(BASE_URL.host, BASE_URL.port) do |http|
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: '1.0'
4
+ version: '1.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -68,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  segments:
70
70
  - 0
71
- hash: -142613809827686151
71
+ hash: -489654790334797899
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: -142613809827686151
80
+ hash: -489654790334797899
81
81
  requirements: []
82
82
  rubyforge_project:
83
83
  rubygems_version: 1.8.24