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 +4 -0
- data/README.md +1 -1
- data/lib/sosowa/scheme.rb +55 -10
- data/lib/sosowa/version.rb +1 -1
- data/lib/sosowa.rb +9 -3
- metadata +3 -3
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
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
|
-
|
85
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
data/lib/sosowa/version.rb
CHANGED
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
|
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])}"}
|
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
|
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.
|
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: -
|
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: -
|
80
|
+
hash: -489654790334797899
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
83
|
rubygems_version: 1.8.24
|