shout-mouth-communicator 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'rapuncel'
|
2
2
|
|
3
3
|
class XmlParseError < StandardError; end
|
4
4
|
class NotAuthenticatedError < StandardError; end
|
5
5
|
|
6
6
|
class ShoutMouthCommunicator
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@client =
|
8
|
+
def initialize(url, path, port, blogid, username, password)
|
9
|
+
@client = Rapuncel::Client.new :host => url, :port => port, :path => path
|
10
10
|
@blogid = blogid
|
11
11
|
@username = username
|
12
12
|
@password = password
|
@@ -30,10 +30,10 @@ class ShoutMouthCommunicator
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def response=(value)
|
33
|
-
if value.is_a?(Hash) && value.has_key?(
|
34
|
-
case value[
|
33
|
+
if value.is_a?(Hash) && value.has_key?(:fault)
|
34
|
+
case value[:fault][:faultCode]
|
35
35
|
when 4003
|
36
|
-
@errors = error_parser(value[
|
36
|
+
@errors = error_parser(value[:fault][:faultString])
|
37
37
|
when 403
|
38
38
|
raise NotAuthenticatedError
|
39
39
|
when -32700
|
@@ -49,7 +49,7 @@ class ShoutMouthCommunicator
|
|
49
49
|
|
50
50
|
def authorized?
|
51
51
|
begin
|
52
|
-
self.response = @client.call('blogger.getUserInfo',
|
52
|
+
self.response = @client.call('blogger.getUserInfo', @blogid, @username, @password).result
|
53
53
|
true
|
54
54
|
rescue NotAuthenticatedError
|
55
55
|
return false
|
@@ -57,7 +57,7 @@ class ShoutMouthCommunicator
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def tags
|
60
|
-
self.response = @client.call('wp.getTags',
|
60
|
+
self.response = @client.call('wp.getTags', @blogid, @username, @password).result
|
61
61
|
self.response
|
62
62
|
end
|
63
63
|
|
@@ -66,34 +66,34 @@ class ShoutMouthCommunicator
|
|
66
66
|
:tag_id => tag_id,
|
67
67
|
:name => name
|
68
68
|
}
|
69
|
-
self.response = @client.call('shoutmouth.editTag',
|
69
|
+
self.response = @client.call('shoutmouth.editTag', @blogid, @username, @password, tag).result
|
70
70
|
self.response
|
71
71
|
end
|
72
72
|
|
73
73
|
def categories
|
74
|
-
self.response = @client.call('wp.getCategories',
|
74
|
+
self.response = @client.call('wp.getCategories', @blogid, @username, @password).result
|
75
75
|
self.response
|
76
76
|
end
|
77
77
|
|
78
78
|
def new_category name, description
|
79
79
|
category = {:name => name, :slug => "not relevant", :parent_id => "0", :description => description}
|
80
|
-
self.response = @client.call('wp.newCategory',
|
80
|
+
self.response = @client.call('wp.newCategory', @blogid, @username, @password, category).result
|
81
81
|
self.response
|
82
82
|
end
|
83
83
|
|
84
84
|
def edit_category category_id, name
|
85
85
|
category = {:category_id => category_id, :category => name}
|
86
|
-
self.response = @client.call('shoutmouth.editCategory',
|
86
|
+
self.response = @client.call('shoutmouth.editCategory', @blogid, @username, @password, category).result
|
87
87
|
self.response
|
88
88
|
end
|
89
89
|
|
90
90
|
def posts limit = 0
|
91
|
-
self.response = @client.call('metaweblog.getRecentPosts',
|
91
|
+
self.response = @client.call('metaweblog.getRecentPosts', @blogid, @username, @password, limit).result
|
92
92
|
self.response
|
93
93
|
end
|
94
94
|
|
95
95
|
def post post_id
|
96
|
-
self.response = @client.call('metaweblog.getPost', post_id, @username, @password, 2)
|
96
|
+
self.response = @client.call('metaweblog.getPost', post_id, @username, @password, 2).result
|
97
97
|
self.response
|
98
98
|
end
|
99
99
|
|
@@ -107,7 +107,7 @@ class ShoutMouthCommunicator
|
|
107
107
|
:mt_keywords => tags
|
108
108
|
}
|
109
109
|
|
110
|
-
self.response = @client.call('metaweblog.newPost',
|
110
|
+
self.response = @client.call('metaweblog.newPost', @blogid, @username, @password, post).result
|
111
111
|
self.response
|
112
112
|
end
|
113
113
|
|
@@ -122,22 +122,22 @@ class ShoutMouthCommunicator
|
|
122
122
|
:mt_keywords => tags
|
123
123
|
}
|
124
124
|
|
125
|
-
self.response = @client.call('metaweblog.editPost', post_id, @username, @password, post)
|
125
|
+
self.response = @client.call('metaweblog.editPost', post_id, @username, @password, post).result
|
126
126
|
self.response
|
127
127
|
end
|
128
128
|
|
129
129
|
def delete_post post_id
|
130
|
-
self.response = @client.call('blogger.deletePost',
|
130
|
+
self.response = @client.call('blogger.deletePost', @blogid, post_id, @username, @password, true).result
|
131
131
|
self.response
|
132
132
|
end
|
133
133
|
|
134
134
|
def pages limit = 10000000
|
135
|
-
self.response = @client.call('wp.getPages',
|
135
|
+
self.response = @client.call('wp.getPages', @blogid, @username, @password, limit).result
|
136
136
|
self.response
|
137
137
|
end
|
138
138
|
|
139
139
|
def page page_id
|
140
|
-
self.response = @client.call('wp.getPage',
|
140
|
+
self.response = @client.call('wp.getPage', @blogid, page_id, @username, @password).result
|
141
141
|
self.response
|
142
142
|
end
|
143
143
|
|
@@ -149,7 +149,7 @@ class ShoutMouthCommunicator
|
|
149
149
|
:wp_page_order => order,
|
150
150
|
:wp_page_parent_id => parent_id
|
151
151
|
}
|
152
|
-
self.response = @client.call('wp.newPage',
|
152
|
+
self.response = @client.call('wp.newPage', @blogid, @username, @password, page).result.to_i
|
153
153
|
self.response
|
154
154
|
end
|
155
155
|
|
@@ -162,24 +162,24 @@ class ShoutMouthCommunicator
|
|
162
162
|
:wp_page_order => order,
|
163
163
|
:wp_page_parent_id => parent_id
|
164
164
|
}
|
165
|
-
self.response = @client.call('wp.newPage',
|
165
|
+
self.response = @client.call('wp.newPage', @blogid, @username, @password, page).result.to_i
|
166
166
|
self.response
|
167
167
|
end
|
168
168
|
|
169
169
|
def delete_page page_id
|
170
|
-
self.response = @client.call('wp.deletePage',
|
170
|
+
self.response = @client.call('wp.deletePage', @blogid, @username, @password, page_id).result
|
171
171
|
self.response
|
172
172
|
end
|
173
173
|
|
174
174
|
#status list = active, spam or hold
|
175
175
|
def comments status = "active"
|
176
|
-
self.response = @client.call('wp.getComments',
|
176
|
+
self.response = @client.call('wp.getComments', @blogid, @username, @password, { :status => status }).result
|
177
177
|
self.response
|
178
178
|
end
|
179
179
|
|
180
180
|
#status list = active, spam or hold
|
181
181
|
def comments_for_post post_id, status = "active"
|
182
|
-
self.response = @client.call('wp.getComments',
|
182
|
+
self.response = @client.call('wp.getComments', @blogid, @username, @password, { :post_id => post_id, :status => status }).result
|
183
183
|
self.response
|
184
184
|
end
|
185
185
|
|
@@ -192,28 +192,28 @@ class ShoutMouthCommunicator
|
|
192
192
|
:author_email => author_email,
|
193
193
|
:status => status
|
194
194
|
}
|
195
|
-
self.response = @client.call('wp.editComment',
|
195
|
+
self.response = @client.call('wp.editComment', @blogid, @username, @password, comment_id, comment).result
|
196
196
|
self.response
|
197
197
|
end
|
198
198
|
|
199
199
|
def settings
|
200
|
-
self.response = @client.call('wp.getOptions',
|
200
|
+
self.response = @client.call('wp.getOptions', @blogid, @username, @password).result
|
201
201
|
self.response
|
202
202
|
end
|
203
203
|
|
204
204
|
#{"blog_title" => "Hello World!", "blog_tagline" => "tagg!"}
|
205
205
|
def edit_settings settings
|
206
|
-
self.response = @client.call('wp.setOptions',
|
206
|
+
self.response = @client.call('wp.setOptions', @blogid, @username, @password, settings).result
|
207
207
|
self.response
|
208
208
|
end
|
209
209
|
|
210
210
|
def users
|
211
|
-
self.response = @client.call('wp.getAuthors',
|
211
|
+
self.response = @client.call('wp.getAuthors', @blogid, @username, @password).result
|
212
212
|
self.response
|
213
213
|
end
|
214
214
|
|
215
215
|
def current_user
|
216
|
-
self.response = @client.call('blogger.getUserInfo',
|
216
|
+
self.response = @client.call('blogger.getUserInfo', @blogid, @username, @password).result
|
217
217
|
self.response
|
218
218
|
end
|
219
219
|
|
@@ -224,7 +224,7 @@ class ShoutMouthCommunicator
|
|
224
224
|
:firstname => firstname,
|
225
225
|
:lastname => lastname
|
226
226
|
}
|
227
|
-
self.response = @client.call('shoutmouth.addUser',
|
227
|
+
self.response = @client.call('shoutmouth.addUser', @blogid, @username, @password, user).result
|
228
228
|
self.response
|
229
229
|
end
|
230
230
|
|
@@ -236,12 +236,12 @@ class ShoutMouthCommunicator
|
|
236
236
|
:firstname => firstname,
|
237
237
|
:lastname => lastname
|
238
238
|
}
|
239
|
-
self.response = @client.call('shoutmouth.editUser',
|
239
|
+
self.response = @client.call('shoutmouth.editUser', @blogid, @username, @password, user).result
|
240
240
|
self.response
|
241
241
|
end
|
242
242
|
|
243
243
|
def delete_user user_id
|
244
|
-
self.response = @client.call('shoutmouth.deleteUser',
|
244
|
+
self.response = @client.call('shoutmouth.deleteUser', @blogid, @username, @password, user_id).result
|
245
245
|
self.response
|
246
246
|
end
|
247
247
|
|
@@ -250,7 +250,7 @@ class ShoutMouthCommunicator
|
|
250
250
|
:bits => bits,
|
251
251
|
:name => name
|
252
252
|
}
|
253
|
-
self.response = @client.call('metaweblog.newMediaObject',
|
253
|
+
self.response = @client.call('metaweblog.newMediaObject', @blogid, @username, @password, file).result
|
254
254
|
self.response
|
255
255
|
end
|
256
256
|
|
@@ -18,7 +18,9 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,specs,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
-
|
21
|
+
|
22
|
+
s.add_dependency('rapuncel')
|
23
|
+
|
22
24
|
s.add_development_dependency('thin')
|
23
25
|
s.add_development_dependency('rspec')
|
24
26
|
end
|
@@ -20,7 +20,7 @@ class XMLrpcServer
|
|
20
20
|
method = call[0].gsub(/(.*)\.(.*)/, '\2').gsub(/([A-Z])/, '_\1').downcase
|
21
21
|
# fake authentocation
|
22
22
|
does_not_need_authentication?(method) ? authenticated = true : authenticated = authenticated?(call)
|
23
|
-
# if the fake reponse header has been set overide the response file that will be sent back to the client
|
23
|
+
# if the fake reponse header has been set overide the response file that will be sent back to the client
|
24
24
|
method = env["HTTP_RESPONSE_FILE"] unless env["HTTP_RESPONSE_FILE"].nil?
|
25
25
|
#raise xmlrpc error response or get the xml response from the correct file
|
26
26
|
authenticated ? response = get_response_for(method) : response = get_response_for('bad_authentication')
|
@@ -3,16 +3,24 @@ require File.expand_path('../../lib/shout-mouth-communicator', __FILE__)
|
|
3
3
|
|
4
4
|
describe "Shout Mouth RPC API" do
|
5
5
|
|
6
|
+
HOST = "0.0.0.0"
|
7
|
+
PORT = "4000"
|
8
|
+
PATH = "/xmlrpc.php"
|
9
|
+
BLOGID = "1"
|
10
|
+
USERNAME = "correct"
|
11
|
+
PASSWORD = "password"
|
12
|
+
|
13
|
+
|
6
14
|
before(:all) do
|
7
|
-
@shout_mouth_client = ShoutMouthCommunicator.new(
|
15
|
+
@shout_mouth_client = ShoutMouthCommunicator.new(HOST, PATH, PORT, BLOGID, USERNAME, PASSWORD)
|
8
16
|
end
|
9
17
|
|
10
18
|
after(:each) do
|
11
|
-
@shout_mouth_client.client.
|
19
|
+
@shout_mouth_client.client.connection.headers = {}
|
12
20
|
end
|
13
21
|
|
14
22
|
it "should disallow authorization to the system when credentials are incorrect" do
|
15
|
-
shout_mouth_client = ShoutMouthCommunicator.new(
|
23
|
+
shout_mouth_client = ShoutMouthCommunicator.new(HOST, PATH, PORT, BLOGID, "wrong", PASSWORD)
|
16
24
|
shout_mouth_client.authorized?.should be_false
|
17
25
|
end
|
18
26
|
|
@@ -22,10 +30,10 @@ describe "Shout Mouth RPC API" do
|
|
22
30
|
|
23
31
|
it "should return a list of correct tags" do
|
24
32
|
tags = @shout_mouth_client.tags
|
25
|
-
tags[0].should include
|
26
|
-
tags[1].should include
|
27
|
-
tags[2].should include
|
28
|
-
tags[3].should include
|
33
|
+
tags[0].should include :tag_id => "1"
|
34
|
+
tags[1].should include :tag_id => "2"
|
35
|
+
tags[2].should include :tag_id => "3"
|
36
|
+
tags[3].should include :tag_id => "4"
|
29
37
|
end
|
30
38
|
|
31
39
|
it "should return the correct response when a tag is edited" do
|
@@ -35,10 +43,10 @@ describe "Shout Mouth RPC API" do
|
|
35
43
|
|
36
44
|
it "should return a list of correct categories" do
|
37
45
|
categories = @shout_mouth_client.categories
|
38
|
-
categories[0].should include
|
39
|
-
categories[1].should include
|
40
|
-
categories[2].should include
|
41
|
-
categories[3].should include
|
46
|
+
categories[0].should include :categoryId => "1"
|
47
|
+
categories[1].should include :categoryId => "2"
|
48
|
+
categories[2].should include :categoryId => "3"
|
49
|
+
categories[3].should include :categoryId => "4"
|
42
50
|
end
|
43
51
|
|
44
52
|
it "should return the correct response when a category has been created" do
|
@@ -54,13 +62,13 @@ describe "Shout Mouth RPC API" do
|
|
54
62
|
it "should return a correct list of posts" do
|
55
63
|
posts = @shout_mouth_client.posts
|
56
64
|
posts.count.should == 2
|
57
|
-
posts[0][
|
58
|
-
posts[1][
|
65
|
+
posts[0][:title].should == "This is how we roll"
|
66
|
+
posts[1][:title].should == "New Post 1"
|
59
67
|
end
|
60
68
|
|
61
69
|
it "should return a post when the get_post method is called" do
|
62
70
|
post = @shout_mouth_client.post 1
|
63
|
-
post[
|
71
|
+
post[:title].should == "This is how we roll"
|
64
72
|
end
|
65
73
|
|
66
74
|
it "should return a correct response when a new post is added" do
|
@@ -80,12 +88,12 @@ describe "Shout Mouth RPC API" do
|
|
80
88
|
|
81
89
|
it "should return a correct list of pages when the pages method is called" do
|
82
90
|
pages = @shout_mouth_client.pages
|
83
|
-
pages.first[
|
91
|
+
pages.first[:title].should == "bang"
|
84
92
|
end
|
85
93
|
|
86
94
|
it "should return a correct page when the page method is called" do
|
87
95
|
page = @shout_mouth_client.page 8
|
88
|
-
page[
|
96
|
+
page[:title].should == "bang"
|
89
97
|
end
|
90
98
|
|
91
99
|
it "should return a correct response when the new post method is called" do
|
@@ -94,7 +102,7 @@ describe "Shout Mouth RPC API" do
|
|
94
102
|
end
|
95
103
|
|
96
104
|
it "should return a correct response when the edit page method is called" do
|
97
|
-
@shout_mouth_client.client.
|
105
|
+
@shout_mouth_client.client.connection.headers = {"response_file" => "edit_page"}
|
98
106
|
response = @shout_mouth_client.edit_page 10, "new page 123", "body", "publish", 1, 0
|
99
107
|
response.should == 10
|
100
108
|
end
|
@@ -106,16 +114,16 @@ describe "Shout Mouth RPC API" do
|
|
106
114
|
|
107
115
|
it "should return comments for a post when the get post comments methods is called" do
|
108
116
|
comments = @shout_mouth_client.comments_for_post 4
|
109
|
-
comments.first[
|
117
|
+
comments.first[:user_id].should == "ham@ok.com"
|
110
118
|
end
|
111
119
|
|
112
120
|
it "should return no comments for a post when the get comments method is called with the spam flag" do
|
113
|
-
@shout_mouth_client.client.
|
121
|
+
@shout_mouth_client.client.connection.headers = {"response_file" => "get_comments_spam"}
|
114
122
|
@shout_mouth_client.comments_for_post(4, "spam").should be_empty
|
115
123
|
end
|
116
124
|
|
117
125
|
it "should return all active comments when the comments method is called" do
|
118
|
-
@shout_mouth_client.client.
|
126
|
+
@shout_mouth_client.client.connection.headers = {"response_file" => "get_comments_all"}
|
119
127
|
comments = @shout_mouth_client.comments
|
120
128
|
comments.count.should == 2
|
121
129
|
end
|
@@ -127,24 +135,24 @@ describe "Shout Mouth RPC API" do
|
|
127
135
|
|
128
136
|
it "should return a list of avaliable settings for the shout mouth instance when the settings method is called" do
|
129
137
|
settings = @shout_mouth_client.settings
|
130
|
-
settings[
|
131
|
-
settings[
|
138
|
+
settings[:software_name][:value].should == "Shout Mouth Blog Engine"
|
139
|
+
settings[:administrator_email][:value].should == "admin@yourserver.com"
|
132
140
|
end
|
133
141
|
|
134
142
|
it "should return a setting when a settings is edited" do
|
135
143
|
setting = @shout_mouth_client.edit_settings({"blog_title" => "ttle"})
|
136
|
-
setting[
|
144
|
+
setting[:blog_title][:value].should == "ttle"
|
137
145
|
end
|
138
146
|
|
139
147
|
it "should return all users when the user method is called" do
|
140
148
|
users = @shout_mouth_client.users
|
141
|
-
users.first[
|
149
|
+
users.first[:user_email].should == "dan@shout_mouth.com"
|
142
150
|
end
|
143
151
|
|
144
152
|
it "should return information about the current user when the current user method is called" do
|
145
153
|
user = @shout_mouth_client.current_user
|
146
|
-
user[
|
147
|
-
user[
|
154
|
+
user[:firstname].should == "Daniel"
|
155
|
+
user[:lastname].should == "Watson"
|
148
156
|
end
|
149
157
|
|
150
158
|
it "should return true when the add use method is called" do
|
@@ -160,23 +168,23 @@ describe "Shout Mouth RPC API" do
|
|
160
168
|
end
|
161
169
|
|
162
170
|
it "should return the correct url when a file is uploaded" do
|
163
|
-
@shout_mouth_client.upload_file("Austria.gif", [])[
|
171
|
+
@shout_mouth_client.upload_file("Austria.gif", [])[:url].should == "http://0.0.0.0:4000/uploads/Austria.gif"
|
164
172
|
end
|
165
173
|
|
166
174
|
it "should have errors if the response contains validation errors" do
|
167
|
-
@shout_mouth_client.client.
|
175
|
+
@shout_mouth_client.client.connection.headers = {"response_file" => "validation_error"}
|
168
176
|
@shout_mouth_client.edit_user("1", "email@addess.com", "password", "", "")
|
169
177
|
@shout_mouth_client.has_errors?.should be_true
|
170
178
|
@shout_mouth_client.errors.count.should == 3
|
171
179
|
end
|
172
180
|
|
173
181
|
it "should raise an XmlParseError if the xml passed is blank" do
|
174
|
-
@shout_mouth_client.client.
|
182
|
+
@shout_mouth_client.client.connection.headers = {"response_file" => "xml_parse_error"}
|
175
183
|
lambda{ @shout_mouth_client.upload_file("",[]) }.should raise_error(XmlParseError)
|
176
184
|
end
|
177
185
|
|
178
186
|
it "should raise an NoMethodError if there is a method called with no endpoint" do
|
179
|
-
@shout_mouth_client.client.
|
187
|
+
@shout_mouth_client.client.connection.headers = {"response_file" => "nomethod_error"}
|
180
188
|
lambda{ @shout_mouth_client.upload_file("",[])}.should raise_error(NoMethodError)
|
181
189
|
end
|
182
190
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: shout-mouth-communicator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0
|
5
|
+
version: 1.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan Watson
|
@@ -10,11 +10,11 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-26 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
17
|
+
name: rapuncel
|
18
18
|
prerelease: false
|
19
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: "0"
|
25
|
-
type: :
|
25
|
+
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: thin
|
29
29
|
prerelease: false
|
30
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
@@ -35,6 +35,17 @@ dependencies:
|
|
35
35
|
version: "0"
|
36
36
|
type: :development
|
37
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
38
49
|
description: An xmlrpc client that allows administration of the Shout Mouth blog engine"
|
39
50
|
email:
|
40
51
|
- dan@dotnetguy.co.uk
|