Skip to content

Commit

Permalink
Plurk.add_plurk is now also under the command of a mechanize agent. A…
Browse files Browse the repository at this point in the history
…lgorithm to post a plurk remains unchanged.

Signed-off-by: xdite <xuite.joke@gmail.com>
  • Loading branch information
ecin authored and xdite committed Feb 24, 2009
1 parent bf68d59 commit a816e3a
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions lib/plurk.rb
@@ -1,5 +1,5 @@
require 'mechanize'
require 'hpricot'
require 'mechanize'

class Plurk
attr_reader :logged_in, :uid, :nickname, :friends, :cookies
Expand All @@ -8,7 +8,7 @@ def initialize
:http_base => "http://www.plurk.com",
:login => "/Users/login",
:get_completion => "/Users/getCompletion",
:plurk_add => "/TimeLine/addPlurk",
:plurk_add => "http://www.plurk.com/TimeLine/addPlurk",
:plurk_respond => "/Responses/add",
:plurk_get => "/TimeLine/getPlurks",
:plurk_get_responses => "/Responses/get2",
Expand Down Expand Up @@ -46,21 +46,28 @@ def login(nickname, password)

def add_plurk(content="", qualifier="says", limited_to=[], no_comments=false, lang="en")
if @logged_in
http = Net::HTTP.start(@plurk_paths[:http_base])
agent = WWW::Mechanize.new
agent.cookie_jar = @cookies
no_comments = no_comments ? 1 : 0

params = {
"posted" => Time.now.getgm.strftime("%Y-%m-%dT%H:%M:%S"),
"qualifier" => qualifier,
"content" => content[0...140],
"lang" => lang,
"uid" => @uid,
"no_comments" => no_comments
}
params["limited_to"] = "[#{limited_to.join(",")}]" unless limited_to.empty?
resp, data = http.request_post(@plurk_paths[:plurk_add],
hash_to_querystring(params),{"Cookie" => @cookie})
return data if /anti-flood|/.match(data)
content
:posted => Time.now.getgm.strftime("%Y-%m-%dT%H:%M:%S"),
:qualifier => qualifier,
:content => content[0...140],
:lang => lang,
:uid => @uid,
:no_comments => no_comments
}
params[:limited_to] = "[#{limited_to.join(",")}]" unless limited_to.empty?

agent.post(@plurk_paths[:plurk_add], params)

data = agent.current_page.body
return data if data =~ /anti-flood/
puts data
true
else
false
end
end

Expand Down

0 comments on commit a816e3a

Please sign in to comment.