shout-mouth-communicator 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,7 +1,12 @@
1
+ ===Install the gem
2
+ gem install shout-mouth-communicator
3
+
1
4
  ===Shout Mouth Communicator
2
-
5
+ require 'shout-mouth-communicator'
6
+
3
7
  @shout_mouth_client = ShoutMouthCommunicator.new("http://0.0.0.0:4000/xmlrpc.php", "1", "correct", "password")
4
8
  @shout_mouth_client.authorized?
5
-
6
- Check out all the possible calls
7
- @shout_mouth_client.methods
9
+ #check out all the possible calls
10
+ @shout_mouth_client.methods
11
+
12
+ Now all somebody needs to to is start building cool clients for shout mouth. Hint Hint!
@@ -1,5 +1,8 @@
1
1
  require 'xmlrpc/client'
2
2
 
3
+ class XmlParseError < StandardError; end
4
+ class NotAuthenticatedError < StandardError; end
5
+
3
6
  class ShoutMouthCommunicator
4
7
 
5
8
  def initialize(server, blogid, username, password)
@@ -27,13 +30,30 @@ class ShoutMouthCommunicator
27
30
  end
28
31
 
29
32
  def response=(value)
30
- @errors = error_parser(value["fault"]["faultString"]) if value.is_a?(Hash) && value.has_key?("fault") && value["fault"]["faultCode"] == 4003
33
+ if value.is_a?(Hash) && value.has_key?("fault")
34
+ case value["fault"]["faultCode"]
35
+ when 4003
36
+ @errors = error_parser(value["fault"]["faultString"])
37
+ when 403
38
+ raise NotAuthenticatedError
39
+ when -32700
40
+ raise XmlParseError
41
+ when -32601
42
+ raise NoMethodError
43
+ else
44
+ raise StandardError
45
+ end
46
+ end
31
47
  @response = value
32
48
  end
33
49
 
34
50
  def authorized?
35
- self.response = @client.call('blogger.getUserInfo', "1", @username, @password)
36
- !self.response.key?("fault")
51
+ begin
52
+ self.response = @client.call('blogger.getUserInfo', "1", @username, @password)
53
+ true
54
+ rescue NotAuthenticatedError
55
+ return false
56
+ end
37
57
  end
38
58
 
39
59
  def tags
@@ -238,4 +258,4 @@ class ShoutMouthCommunicator
238
258
  def error_parser string
239
259
  string.gsub("[","").gsub("]","").gsub("\"", "").split(",")
240
260
  end
241
- end
261
+ end
@@ -1,7 +1,7 @@
1
1
  module Shout
2
2
  module Mouth
3
3
  module Communicator
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
6
6
  end
7
7
  end
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
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_development_dependency('racksh')
23
22
  s.add_development_dependency('thin')
24
23
  s.add_development_dependency('rspec')
25
24
  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.0
5
+ version: 1.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan Watson
@@ -14,7 +14,7 @@ date: 2011-05-24 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: racksh
17
+ name: thin
18
18
  prerelease: false
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
@@ -25,7 +25,7 @@ dependencies:
25
25
  type: :development
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: thin
28
+ name: rspec
29
29
  prerelease: false
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
31
  none: false
@@ -35,17 +35,6 @@ 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
49
38
  description: An xmlrpc client that allows administration of the Shout Mouth blog engine"
50
39
  email:
51
40
  - dan@dotnetguy.co.uk
@@ -97,7 +86,6 @@ files:
97
86
  - specs/fakes/xmlrpc_server_responses/set_options.xml
98
87
  - specs/fakes/xmlrpc_server_responses/validation_error.xml
99
88
  - specs/helpers/spec_helper.rb
100
- - specs/shout_mout_client_specification.rb
101
89
  has_rdoc: true
102
90
  homepage: https://github.com/dotnetguyuk/shout-mouth-communicator
103
91
  licenses: []
@@ -158,4 +146,3 @@ test_files:
158
146
  - specs/fakes/xmlrpc_server_responses/set_options.xml
159
147
  - specs/fakes/xmlrpc_server_responses/validation_error.xml
160
148
  - specs/helpers/spec_helper.rb
161
- - specs/shout_mout_client_specification.rb
@@ -1,172 +0,0 @@
1
- require File.expand_path('../helpers/spec_helper', __FILE__)
2
- require File.expand_path('../../lib/shout-mouth-communicator', __FILE__)
3
-
4
- describe "Shout Mouth RPC API" do
5
-
6
- before(:all) do
7
- @shout_mouth_client = ShoutMouthCommunicator.new("http://0.0.0.0:4000/xmlrpc.php", "1", "correct", "password")
8
- end
9
-
10
- after(:each) do
11
- @shout_mouth_client.client.http_header_extra = nil
12
- end
13
-
14
- it "should disallow authorization to the system when credentials are incorrect" do
15
- shout_mouth_client = ShoutMouthCommunicator.new("http://0.0.0.0:4000/xmlrpc.php", "1", "wrong", "password")
16
- shout_mouth_client.authorized?.should be_false
17
- end
18
-
19
- it "should allow authorization to the system when the credentails are correct" do
20
- @shout_mouth_client.authorized?.should be_true
21
- end
22
-
23
- it "should return a list of correct tags" do
24
- tags = @shout_mouth_client.tags
25
- tags[0].should include "tag_id"=>"1"
26
- tags[1].should include "tag_id"=>"2"
27
- tags[2].should include "tag_id"=>"3"
28
- tags[3].should include "tag_id"=>"4"
29
- end
30
-
31
- it "should return the correct response when a tag is edited" do
32
- response = @shout_mouth_client.edit_tag 1, "Boooooommmmmmm!"
33
- response.should be_true
34
- end
35
-
36
- it "should return a list of correct categories" do
37
- categories = @shout_mouth_client.categories
38
- categories[0].should include "categoryId"=> "1"
39
- categories[1].should include "categoryId"=> "2"
40
- categories[2].should include "categoryId"=> "3"
41
- categories[3].should include "categoryId"=> "4"
42
- end
43
-
44
- it "should return the correct response when a category has been created" do
45
- response = @shout_mouth_client.new_category("Category123", "Category123 Description")
46
- response.should == 5
47
- end
48
-
49
- it "should return the correct response when a category is edited" do
50
- response = @shout_mouth_client.edit_category(5, "edited")
51
- response.should be_true
52
- end
53
-
54
- it "should return a correct list of posts" do
55
- posts = @shout_mouth_client.posts
56
- posts.count.should == 2
57
- posts[0]["title"].should == "This is how we roll"
58
- posts[1]["title"].should == "New Post 1"
59
- end
60
-
61
- it "should return a post when the get_post method is called" do
62
- post = @shout_mouth_client.post 1
63
- post["title"].should == "This is how we roll"
64
- end
65
-
66
- it "should return a correct response when a new post is added" do
67
- response = @shout_mouth_client.new_post "title", "description", "category1,category2", "publish", DateTime.now, "tag1,tag2"
68
- response.should == 4
69
- end
70
-
71
- it "should return a correct response when a post is edited" do
72
- response = @shout_mouth_client.edit_post 4, "title_edit", "description_edit", "category9,category10", "publish", DateTime.now, "tag9,tag10"
73
- response.should be_true
74
- end
75
-
76
- it "should return a correct response when the delete post method is called" do
77
- response = @shout_mouth_client.delete_post 4
78
- response.should be_true
79
- end
80
-
81
- it "should return a correct list of pages when the pages method is called" do
82
- pages = @shout_mouth_client.pages
83
- pages.first["title"].should == "bang"
84
- end
85
-
86
- it "should return a correct page when the page method is called" do
87
- page = @shout_mouth_client.page 8
88
- page["title"].should == "bang"
89
- end
90
-
91
- it "should return a correct response when the new post method is called" do
92
- response = @shout_mouth_client.new_page "new page 1", "body", "publish", 1, 0
93
- response.should == 10
94
- end
95
-
96
- it "should return a correct response when the edit page method is called" do
97
- @shout_mouth_client.client.http_header_extra = {"response_file" => "edit_page"}
98
- response = @shout_mouth_client.edit_page 10, "new page 123", "body", "publish", 1, 0
99
- response.should == 10
100
- end
101
-
102
- it "should return a correct response when the delete page method is called" do
103
- response = @shout_mouth_client.delete_page 10
104
- response.should be_true
105
- end
106
-
107
- it "should return comments for a post when the get post comments methods is called" do
108
- comments = @shout_mouth_client.comments_for_post 4
109
- comments.first["user_id"].should == "ham@ok.com"
110
- end
111
-
112
- 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.http_header_extra = {"response_file" => "get_comments_spam"}
114
- @shout_mouth_client.comments_for_post(4, "spam").should be_empty
115
- end
116
-
117
- it "should return all active comments when the comments method is called" do
118
- @shout_mouth_client.client.http_header_extra = {"response_file" => "get_comments_all"}
119
- comments = @shout_mouth_client.comments
120
- comments.count.should == 2
121
- end
122
-
123
- it "should return the correct response when the edit comment method is called" do
124
- response = @shout_mouth_client.edit_comment(1, "comment_changed", "content", "http://google.com", "dan@dan.com", "active")
125
- response.should be_true
126
- end
127
-
128
- it "should return a list of avaliable settings for the shout mouth instance when the settings method is called" do
129
- settings = @shout_mouth_client.settings
130
- settings["software_name"]["value"].should == "Shout Mouth Blog Engine"
131
- settings["administrator_email"]["value"].should == "admin@yourserver.com"
132
- end
133
-
134
- it "should return a setting when a settings is edited" do
135
- setting = @shout_mouth_client.edit_settings({"blog_title" => "ttle"})
136
- setting["blog_title"]["value"].should == "ttle"
137
- end
138
-
139
- it "should return all users when the user method is called" do
140
- users = @shout_mouth_client.users
141
- users.first["user_email"].should == "dan@shout_mouth.com"
142
- end
143
-
144
- it "should return information about the current user when the current user method is called" do
145
- user = @shout_mouth_client.current_user
146
- user["firstname"].should == "Daniel"
147
- user["lastname"].should == "Watson"
148
- end
149
-
150
- it "should return true when the add use method is called" do
151
- @shout_mouth_client.add_user("email@address.com", "password", "firstname", "lastname").should be_true
152
- end
153
-
154
- it "should return true when the edit user method is called" do
155
- @shout_mouth_client.edit_user("1", "email@address.com", "password", "firstname", "lastname").should be_true
156
- end
157
-
158
- it "should return true when the delete user method is called" do
159
- @shout_mouth_client.delete_user(1).should be_true
160
- end
161
-
162
- it "should return the correct url when a file is uploaded" do
163
- @shout_mouth_client.upload_file("Austria.gif", [])["url"].should == "http://0.0.0.0:4000/uploads/Austria.gif"
164
- end
165
-
166
- it "should have errors if the response contains validation errors" do
167
- @shout_mouth_client.client.http_header_extra = {"response_file" => "validation_error"}
168
- @shout_mouth_client.edit_user("1", "email@addess.com", "password", "", "")
169
- @shout_mouth_client.has_errors?.should be_true
170
- @shout_mouth_client.errors.count.should == 3
171
- end
172
- end