sunflower 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/sunflower/core.rb +23 -18
- metadata +2 -2
data/README
CHANGED
data/lib/sunflower/core.rb
CHANGED
@@ -17,7 +17,7 @@ require 'cgi'
|
|
17
17
|
#
|
18
18
|
# You can use multiple Sunflowers at once, to work on multiple wikis.
|
19
19
|
class Sunflower
|
20
|
-
VERSION = '0.5.
|
20
|
+
VERSION = '0.5.4'
|
21
21
|
|
22
22
|
INVALID_CHARS = %w(# < > [ ] | { })
|
23
23
|
INVALID_CHARS_REGEX = Regexp.union *INVALID_CHARS
|
@@ -44,7 +44,7 @@ class Sunflower
|
|
44
44
|
# Whether to run #code_cleanup when calling #save.
|
45
45
|
attr_accessor :always_do_code_cleanup
|
46
46
|
# The URL this Sunflower works on, as provided as argument to #initialize.
|
47
|
-
attr_reader :wikiURL
|
47
|
+
attr_reader :wikiURL, :api_endpoint
|
48
48
|
# Siteinfo, as returned by API call.
|
49
49
|
attr_accessor :siteinfo
|
50
50
|
|
@@ -108,8 +108,16 @@ class Sunflower
|
|
108
108
|
return type_map[type].sub 'XX', lang
|
109
109
|
end
|
110
110
|
|
111
|
-
# Initialize a new Sunflower working on a wiki with given URL, for ex. "pl.wikipedia.org".
|
112
|
-
|
111
|
+
# Initialize a new Sunflower working on a wiki with given URL, for ex. "pl.wikipedia.org".
|
112
|
+
# url can also be a shorthand identifier such as "b:pl" - see Sunflower.resolve_wikimedia_id for details.
|
113
|
+
#
|
114
|
+
# There is currently one option available:
|
115
|
+
# * api_endpoint: full URL to your api.php, if different than http://<url>/w/api.php (standard for WMF wikis)
|
116
|
+
def initialize url=nil, opts={}
|
117
|
+
if url.is_a? Hash
|
118
|
+
url, opts = nil, url
|
119
|
+
end
|
120
|
+
|
113
121
|
if !url
|
114
122
|
userdata = Sunflower.read_userdata()
|
115
123
|
|
@@ -121,6 +129,7 @@ class Sunflower
|
|
121
129
|
end
|
122
130
|
|
123
131
|
@wikiURL = (url.include?('.') ? url : Sunflower.resolve_wikimedia_id(url))
|
132
|
+
@api_endpoint = opts[:api_endpoint] || 'http://'+@wikiURL+'/w/api.php'
|
124
133
|
|
125
134
|
@warnings = true
|
126
135
|
@log = false
|
@@ -172,7 +181,7 @@ class Sunflower
|
|
172
181
|
end
|
173
182
|
|
174
183
|
resp = RestClient.post(
|
175
|
-
|
184
|
+
@api_endpoint,
|
176
185
|
request,
|
177
186
|
{:user_agent => "Sunflower #{VERSION} alpha", :cookies => @cookies}
|
178
187
|
)
|
@@ -239,33 +248,29 @@ class Sunflower
|
|
239
248
|
|
240
249
|
# 1. get the login token
|
241
250
|
response = RestClient.post(
|
242
|
-
|
243
|
-
|
251
|
+
@api_endpoint,
|
252
|
+
"action=login&lgname=#{CGI.escape user}&lgpassword=#{CGI.escape password}&format=json",
|
244
253
|
{:user_agent => "Sunflower #{VERSION} alpha"}
|
245
254
|
)
|
246
255
|
|
247
256
|
@cookies = response.cookies
|
248
|
-
|
249
|
-
token, prefix = json['login']['token'], json['login']['cookieprefix']
|
257
|
+
raise Sunflower::Error, 'unable to log in (no cookies received)!' if !@cookies or @cookies.empty?
|
250
258
|
|
259
|
+
json = JSON.parse response.to_str
|
260
|
+
token, prefix = (json['login']['lgtoken']||json['login']['token']), json['login']['cookieprefix']
|
251
261
|
|
252
262
|
# 2. actually log in
|
253
263
|
response = RestClient.post(
|
254
|
-
|
255
|
-
|
264
|
+
@api_endpoint,
|
265
|
+
"action=login&lgname=#{CGI.escape user}&lgpassword=#{CGI.escape password}&lgtoken=#{token}&format=json",
|
256
266
|
{:user_agent => "Sunflower #{VERSION} alpha", :cookies => @cookies}
|
257
267
|
)
|
258
268
|
|
259
269
|
json = JSON.parse response.to_str
|
260
270
|
|
261
|
-
@cookies = @cookies.merge(response.cookies)
|
262
|
-
"#{prefix}UserName" => json['login']['lgusername'].to_s,
|
263
|
-
"#{prefix}UserID" => json['login']['lguserid'].to_s,
|
264
|
-
"#{prefix}Token" => json['login']['lgtoken'].to_s
|
265
|
-
})
|
266
|
-
|
271
|
+
@cookies = @cookies.merge(response.cookies)
|
267
272
|
|
268
|
-
raise Sunflower::Error, 'unable to log in (no cookies received)!' if !@cookies
|
273
|
+
raise Sunflower::Error, 'unable to log in (no cookies received)!' if !@cookies or @cookies.empty?
|
269
274
|
|
270
275
|
|
271
276
|
# 3. confirm you did log in by checking the watchlist.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunflower
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|