Class: ShoutMouthCommunicator

Inherits:
Object
  • Object
show all
Defined in:
lib/shout-mouth-communicator/shout-mouth-communicator.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, path, port, blogid, username, password) ⇒ ShoutMouthCommunicator

Returns a new instance of ShoutMouthCommunicator.



8
9
10
11
12
13
14
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 8

def initialize(url, path, port, blogid, username, password)
  @client = Rapuncel::Client.new :host => url, :port => port, :path => path
  @blogid = blogid
  @username = username
  @password = password
  @errors = []
end

Instance Method Details

#add_user(email, password, firstname, lastname) ⇒ Object



220
221
222
223
224
225
226
227
228
229
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 220

def add_user email, password, firstname, lastname
  user = {
    :email => email,
    :password => password,
    :firstname => firstname,
    :lastname => lastname
  }
  self.response = @client.call('shoutmouth.addUser', @blogid, @username, @password, user).result
  self.response
end

#authorized?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 50

def authorized?
  begin
   self.response = @client.call('blogger.getUserInfo', @blogid, @username, @password).result
   true
  rescue NotAuthenticatedError
    return false
  end
end

#categoriesObject



73
74
75
76
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 73

def categories
  self.response = @client.call('wp.getCategories', @blogid, @username, @password).result
  self.response
end

#clientObject



16
17
18
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 16

def client
  @client
end

#comments(status = "active") ⇒ Object

status list = active, spam or hold



175
176
177
178
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 175

def comments status = "active"
  self.response = @client.call('wp.getComments', @blogid, @username, @password, { :status => status }).result
  self.response
end

#comments_for_post(post_id, status = "active") ⇒ Object

status list = active, spam or hold



181
182
183
184
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 181

def comments_for_post post_id, status = "active"
  self.response = @client.call('wp.getComments', @blogid, @username, @password, { :post_id => post_id, :status => status }).result
  self.response
end

#current_userObject



215
216
217
218
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 215

def current_user
  self.response = @client.call('blogger.getUserInfo', @blogid, @username, @password).result
  self.response
end

#delete_page(page_id) ⇒ Object



169
170
171
172
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 169

def delete_page page_id 
  self.response = @client.call('wp.deletePage', @blogid, @username, @password, page_id).result
  self.response
end

#delete_post(post_id) ⇒ Object



129
130
131
132
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 129

def delete_post post_id
  self.response = @client.call('blogger.deletePost', @blogid, post_id, @username, @password, true).result
  self.response
end

#delete_user(user_id) ⇒ Object



243
244
245
246
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 243

def delete_user user_id
  self.response = @client.call('shoutmouth.deleteUser', @blogid, @username, @password, user_id).result
  self.response
end

#edit_category(category_id, name) ⇒ Object



84
85
86
87
88
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 84

def edit_category category_id, name 
  category = {:category_id => category_id, :category => name}
  self.response = @client.call('shoutmouth.editCategory', @blogid, @username, @password, category).result
  self.response
end

#edit_comment(comment_id, content, author, author_url, author_email, status) ⇒ Object

status list = approve, spam or inactive



187
188
189
190
191
192
193
194
195
196
197
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 187

def edit_comment comment_id, content, author, author_url, author_email, status
  comment = {
    :content => content,
    :author => author,
    :author_url => author_url,
    :author_email => author_email,
    :status => status
  }
  self.response = @client.call('wp.editComment', @blogid, @username, @password, comment_id, comment).result
  self.response
end

#edit_page(page_id, title, body, status, order, parent_id) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 156

def edit_page page_id, title, body, status, order, parent_id
  page = {
    :postid => page_id,
    :title => title,
    :description => body,
    :page_status => status,
    :wp_page_order => order,
    :wp_page_parent_id => parent_id
  }
  self.response = @client.call('wp.newPage', @blogid, @username, @password, page).result.to_i
  self.response
end

#edit_post(post_id, title, description, categories, status, created, tags) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 115

def edit_post post_id, title, description, categories, status, created, tags
  post = {
   :title => title, 
   :description => description,
   :categories => categories.split(","),
   :post_status => status,
   :dateCreated => created,
   :mt_keywords => tags
  }

  self.response = @client.call('metaweblog.editPost', post_id, @username, @password, post).result
  self.response
end

#edit_settings(settings) ⇒ Object

=> “Hello World!”, “blog_tagline” => “tagg!”



205
206
207
208
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 205

def edit_settings settings
  self.response = @client.call('wp.setOptions', @blogid, @username, @password, settings).result
  self.response
end

#edit_tag(tag_id, name) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 64

def edit_tag tag_id, name
  tag = {
    :tag_id => tag_id,
    :name => name
  }
  self.response = @client.call('shoutmouth.editTag', @blogid, @username, @password, tag).result
  self.response
end

#edit_user(user_id, email, password, firstname, lastname) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 231

def edit_user user_id, email, password, firstname, lastname
  user = {
    :user_id => user_id,
    :email => email,
    :password => password,
    :firstname => firstname,
    :lastname => lastname
  }
  self.response = @client.call('shoutmouth.editUser', @blogid, @username, @password, user).result
  self.response
end

#errorsObject



24
25
26
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 24

def errors
  @errors
end

#has_errors?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 20

def has_errors?
  @errors.count > 0
end

#new_category(name, description) ⇒ Object



78
79
80
81
82
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 78

def new_category name, description
  category = {:name => name, :slug => "not relevant", :parent_id => "0", :description => description}
  self.response = @client.call('wp.newCategory', @blogid, @username, @password, category).result
  self.response
end

#new_page(title, body, status, order, parent_id) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 144

def new_page title, body, status, order, parent_id
  page = {
    :title => title,
    :description => body,
    :page_status => status,
    :wp_page_order => order,
    :wp_page_parent_id => parent_id
  }
  self.response = @client.call('wp.newPage', @blogid, @username, @password, page).result.to_i
  self.response
end

#new_post(title, description, categories, status, created, tags) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 100

def new_post title, description, categories, status, created, tags
  post = {
   :title => title, 
   :description => description,
   :categories => categories.split(","),
   :post_status => status,
   :dateCreated => created,
   :mt_keywords => tags
  }

  self.response = @client.call('metaweblog.newPost', @blogid, @username, @password, post).result
  self.response
end

#page(page_id) ⇒ Object



139
140
141
142
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 139

def page page_id
  self.response = @client.call('wp.getPage', @blogid, page_id, @username, @password).result
  self.response
end

#pages(limit = 10000000) ⇒ Object



134
135
136
137
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 134

def pages limit = 10000000
  self.response = @client.call('wp.getPages', @blogid, @username, @password, limit).result
  self.response
end

#post(post_id) ⇒ Object



95
96
97
98
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 95

def post post_id
  self.response = @client.call('metaweblog.getPost', post_id, @username, @password, 2).result
  self.response 
end

#posts(limit = 0) ⇒ Object



90
91
92
93
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 90

def posts limit = 0
  self.response = @client.call('metaweblog.getRecentPosts', @blogid, @username, @password, limit).result
  self.response
end

#responseObject



28
29
30
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 28

def response
  @response
end

#response=(value) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 32

def response=(value)
  if value.is_a?(Hash) && value.has_key?(:fault)
    case value[:fault][:faultCode]
      when 4003
       @errors = error_parser(value[:fault][:faultString])
      when 403
        raise NotAuthenticatedError
      when -32700
        raise XmlParseError 
      when -32601
        raise NoMethodError 
      else
        raise StandardError
     end
  end
  @response = value
end

#settingsObject



199
200
201
202
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 199

def settings
  self.response = @client.call('wp.getOptions', @blogid, @username, @password).result
  self.response
end

#tagsObject



59
60
61
62
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 59

def tags
  self.response = @client.call('wp.getTags', @blogid, @username, @password).result
  self.response
end

#upload_file(name, bits) ⇒ Object



248
249
250
251
252
253
254
255
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 248

def upload_file name, bits
  file = {
    :bits => bits,
    :name => name
  }
  self.response = @client.call('metaweblog.newMediaObject', @blogid, @username, @password, file).result
  self.response
end

#usersObject



210
211
212
213
# File 'lib/shout-mouth-communicator/shout-mouth-communicator.rb', line 210

def users
  self.response = @client.call('wp.getAuthors', @blogid, @username, @password).result
  self.response
end