wtforum 0.0.1 → 0.1.0
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/.rspec +1 -0
- data/README.md +31 -31
- data/lib/wtforum/session.rb +1 -1
- data/lib/wtforum/user.rb +24 -0
- data/lib/wtforum/version.rb +1 -1
- data/spec/integration/wtforum_user_spec.rb +1 -1
- data/wtforum.gemspec +1 -0
- metadata +21 -4
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--debug -c
|
data/README.md
CHANGED
@@ -21,49 +21,49 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Features
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
user.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
WTForum has the following features:
|
25
|
+
|
26
|
+
### CRUD (create, read, update, & delete) user accounts
|
27
|
+
|
28
|
+
# modeled after ActiveRecord API
|
29
|
+
WTForum::User.count
|
30
|
+
user = WTForum::User.create username: "wtforum_test_user", email: "wtforum_test_user@example.com"
|
31
|
+
user = WTForum::User.find(user.id)
|
32
|
+
user = WTForum::User.find_by_username(user.username)
|
33
|
+
user.update_attributes! username: "wtforum_test_user_2", email: "wtforum_test_user_2@example.com"
|
34
|
+
user.destroy
|
35
|
+
|
36
|
+
### Log in your user via their Single Sign On (SSO) API
|
37
|
+
|
38
|
+
session = WTForum::Session.create(user.id)
|
39
|
+
session.token # => REiB6U5SkxB
|
40
40
|
|
41
41
|
## Configuration
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
Before using WTForum, you need to give it administrator credentials. It
|
44
|
+
needs four pieces of information:
|
45
|
+
|
46
|
+
1. Where the forum is hosted.
|
47
|
+
2. The API key that Website Toolbox provides.
|
48
|
+
3. Username of an admin account.
|
49
|
+
4. Password for said admin account.
|
50
|
+
|
51
|
+
Example Rails config:
|
49
52
|
|
50
|
-
Example Rails config:
|
51
|
-
```ruby
|
52
53
|
# config/initializers/wtforum_credentials.rb
|
53
54
|
WTForum.domain = "forum.example.com"
|
54
55
|
WTForum.api_key = "TEgPYR4Zapz"
|
55
56
|
WTForum.admin_username = "__admin_api_dont_delete__"
|
56
57
|
WTForum.admin_password = "s0m3p4ssw0rd"
|
57
|
-
```
|
58
58
|
|
59
59
|
## Why do we need to specify an admin user account in the credentials?
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
Unfortunately, Website Toolbox's Forum API is missing some functionality.
|
62
|
+
Specifically, you can only create a new forum user account. Need to read,
|
63
|
+
update, or delete an existing user via the API? You're out of luck! As a
|
64
|
+
workaround, this library uses an admin account and Mechanize to sign into
|
65
|
+
the website and manually fill out forms and screenscrape the results. I hope
|
66
|
+
that the API's breadth of functionality improves in the future.
|
67
67
|
|
68
68
|
## Contributing
|
69
69
|
|
data/lib/wtforum/session.rb
CHANGED
data/lib/wtforum/user.rb
CHANGED
@@ -31,6 +31,23 @@ module WTForum
|
|
31
31
|
new(attributes)
|
32
32
|
end
|
33
33
|
|
34
|
+
def self.find_by_username username
|
35
|
+
page = authorized_agent.get(find_by_username_uri(username))
|
36
|
+
body = Nokogiri::HTML.parse(page.body)
|
37
|
+
|
38
|
+
# scrape markup: <a href="/profile/1234567" title="View profile">username\t\n</a>
|
39
|
+
# search returns partial matches :( so find the exact match.
|
40
|
+
# hopefully there aren't more than 50 matches!
|
41
|
+
link = body.css("a[title='View profile']:contains('#{username}')").find do |a|
|
42
|
+
a.text.strip == username
|
43
|
+
end
|
44
|
+
|
45
|
+
link or raise NotFound
|
46
|
+
|
47
|
+
id = link["href"].split("/").last
|
48
|
+
find id
|
49
|
+
end
|
50
|
+
|
34
51
|
def self.update user_id, attributes
|
35
52
|
find(user_id).update_attributes!(attributes)
|
36
53
|
end
|
@@ -123,6 +140,13 @@ module WTForum
|
|
123
140
|
uri
|
124
141
|
end
|
125
142
|
|
143
|
+
def self.find_by_username_uri username
|
144
|
+
uri = WTForum.base_uri
|
145
|
+
uri.path = "/register"
|
146
|
+
uri.query = "action=members&search=true&s_username=#{username}"
|
147
|
+
uri
|
148
|
+
end
|
149
|
+
|
126
150
|
def self.edit_username_uri user_id
|
127
151
|
uri = WTForum.base_uri
|
128
152
|
uri.path = "/register/edit_username"
|
data/lib/wtforum/version.rb
CHANGED
@@ -17,7 +17,7 @@ describe WTForum::User do
|
|
17
17
|
|
18
18
|
user.update_attributes! username: "wtforum_test_user_2", email: "wtforum_test_user_2@example.com"
|
19
19
|
|
20
|
-
user = WTForum::User.
|
20
|
+
user = WTForum::User.find_by_username("wtforum_test_user_2")
|
21
21
|
user.username.should == "wtforum_test_user_2"
|
22
22
|
user.email.should == "wtforum_test_user_2@example.com"
|
23
23
|
|
data/wtforum.gemspec
CHANGED
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: wtforum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Micah Geisel
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
type: :runtime
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
none: false
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
name: debugger
|
114
|
+
version_requirements: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
none: false
|
120
|
+
requirement: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
none: false
|
110
126
|
description: Ruby library that wraps Website Toolbox's forum API.
|
111
127
|
email:
|
112
128
|
- micah@botandrose.com
|
@@ -115,6 +131,7 @@ extensions: []
|
|
115
131
|
extra_rdoc_files: []
|
116
132
|
files:
|
117
133
|
- .gitignore
|
134
|
+
- .rspec
|
118
135
|
- Gemfile
|
119
136
|
- LICENSE.txt
|
120
137
|
- README.md
|
@@ -138,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
155
|
requirements:
|
139
156
|
- - ! '>='
|
140
157
|
- !ruby/object:Gem::Version
|
141
|
-
hash:
|
158
|
+
hash: 4273963902836204732
|
142
159
|
segments:
|
143
160
|
- 0
|
144
161
|
version: '0'
|
@@ -147,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
164
|
requirements:
|
148
165
|
- - ! '>='
|
149
166
|
- !ruby/object:Gem::Version
|
150
|
-
hash:
|
167
|
+
hash: 4273963902836204732
|
151
168
|
segments:
|
152
169
|
- 0
|
153
170
|
version: '0'
|