digu 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +2 -0
- data/README.rdoc +22 -0
- data/lib/digu.rb +129 -0
- metadata +66 -0
data/ChangeLog
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
== Description
|
2
|
+
|
3
|
+
This is a client library of digu.com for post messages, will add more features later...
|
4
|
+
|
5
|
+
== Example
|
6
|
+
|
7
|
+
digu = Digu.new.login 'user', 'pass'
|
8
|
+
if digu.login?
|
9
|
+
if digu.post 'I like this'
|
10
|
+
puts "Your message has posted to digu.com"
|
11
|
+
end
|
12
|
+
digu.logout
|
13
|
+
end
|
14
|
+
|
15
|
+
== Version
|
16
|
+
|
17
|
+
v0.1
|
18
|
+
|
19
|
+
== Author
|
20
|
+
|
21
|
+
xianhua.zhou<xianhua.zhou@gmail.com>
|
22
|
+
|
data/lib/digu.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# == Description
|
4
|
+
#
|
5
|
+
# This is a client library of digu.com for post messages, will add more features later...
|
6
|
+
#
|
7
|
+
# == Example
|
8
|
+
#
|
9
|
+
# digu = Digu.new.login 'user', 'pass'
|
10
|
+
# if digu.login?
|
11
|
+
# if digu.post 'I like this'
|
12
|
+
# puts "Your message has posted to digu.com"
|
13
|
+
# end
|
14
|
+
# digu.logout
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# == Version
|
18
|
+
#
|
19
|
+
# v0.1
|
20
|
+
#
|
21
|
+
# == Author
|
22
|
+
#
|
23
|
+
# xianhua.zhou<xianhua.zhou@gmail.com>
|
24
|
+
#
|
25
|
+
#
|
26
|
+
|
27
|
+
require 'rubygems'
|
28
|
+
require 'http_request'
|
29
|
+
|
30
|
+
class Digu
|
31
|
+
VERSION = '0.1'
|
32
|
+
BASE_DIGU_URL = 'http://digu.com'
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@http = http.get home_url
|
36
|
+
end
|
37
|
+
|
38
|
+
def login(username, password, change_account = false)
|
39
|
+
if login?
|
40
|
+
if change_account
|
41
|
+
logout
|
42
|
+
else
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
@username, @password = username, password
|
47
|
+
@http = http.post(
|
48
|
+
:url => login_url,
|
49
|
+
:parameters => {
|
50
|
+
:backActionId => '/home',
|
51
|
+
:action => 1,
|
52
|
+
:userName => @username,
|
53
|
+
:password => @password
|
54
|
+
},
|
55
|
+
:cookies => @http.cookies
|
56
|
+
)
|
57
|
+
login?
|
58
|
+
end
|
59
|
+
|
60
|
+
def login?
|
61
|
+
@http.body.include?('isLogin:true') and @http.body.include?(@username)
|
62
|
+
end
|
63
|
+
|
64
|
+
def post(message)
|
65
|
+
@http = http.get(:url => home_url, :cookies => @http.cookies)
|
66
|
+
|
67
|
+
@http.body.scan(/name="type"\svalue="([0-9]+)"/)
|
68
|
+
type = $1
|
69
|
+
|
70
|
+
@http.body.scan(/name="cookieId"\svalue="([0-9]+)"/)
|
71
|
+
cookie_id = $1
|
72
|
+
|
73
|
+
#@http.body.scan(/name="postLawless"\svalue="(.+?)"/)
|
74
|
+
#post_law_less = $1
|
75
|
+
|
76
|
+
@http.body.scan(/name="groupId"\svalue="([0-9]+)"/)
|
77
|
+
group_id = $1
|
78
|
+
|
79
|
+
#@http.body.scan(/name="writeSloganTitle"\svalue="(.+?)"/)
|
80
|
+
#wrie_slogan_title = $1
|
81
|
+
|
82
|
+
@http = http.post(:url => post_message_url,
|
83
|
+
:parameters => {
|
84
|
+
:cookieId => cookie_id,
|
85
|
+
:type => type,
|
86
|
+
:group_id => group_id,
|
87
|
+
:text => message
|
88
|
+
},
|
89
|
+
:cookies => http.cookies
|
90
|
+
)
|
91
|
+
@http.body.include? 'success'
|
92
|
+
end
|
93
|
+
|
94
|
+
def logout
|
95
|
+
http.get logout_url
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def url(path)
|
101
|
+
"#{BASE_DIGU_URL}/#{path}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def login_url
|
105
|
+
url "login"
|
106
|
+
end
|
107
|
+
|
108
|
+
def logout_url
|
109
|
+
url "logout"
|
110
|
+
end
|
111
|
+
|
112
|
+
def home_url
|
113
|
+
url "home"
|
114
|
+
end
|
115
|
+
|
116
|
+
def post_message_url
|
117
|
+
url "/jump?aid=addLekuData"
|
118
|
+
end
|
119
|
+
|
120
|
+
def http
|
121
|
+
::HttpRequest
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
if __FILE__ == $0
|
126
|
+
digu = Digu.new
|
127
|
+
puts digu.post 'What is the best thing in the world?' if digu.login 'username', 'password'
|
128
|
+
digu.logout if digu.login?
|
129
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: digu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zhou Xianhua
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-12 00:00:00 +08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: http_request.rb
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.1"
|
24
|
+
version:
|
25
|
+
description: This is a client library of digu.com for post messages and ...
|
26
|
+
email: xianhua.zhou@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/digu.rb
|
35
|
+
- README.rdoc
|
36
|
+
- ChangeLog
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://my.cnzxh.net/
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project: digu
|
61
|
+
rubygems_version: 1.3.5
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Client library of digu.com
|
65
|
+
test_files: []
|
66
|
+
|