wordpress-xmlrpc 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
data/lib/blog.rb CHANGED
@@ -28,26 +28,58 @@ module Wordpress
28
28
 
29
29
  def recent_posts(number_of_posts)
30
30
  blog_api_call("metaWeblog.getRecentPosts", number_of_posts).collect do |struct|
31
- Post.from_struct(struct)
31
+ Post.from_struct(:metaWeblog, struct)
32
32
  end
33
33
  end #recent_posts
34
34
 
35
- def publish(post)
36
- process_post_images(post)
37
- post.id = blog_api_call("metaWeblog.newPost", post.to_struct, true).to_i
38
- post.published = true
35
+ def publish(item)
36
+ process_images(item) unless item.images.nil?
37
+ case item
38
+ when Wordpress::Post
39
+ item.id = blog_api_call("metaWeblog.newPost", item.to_struct(:metaWeblog), true).to_i
40
+ item.published = true
41
+ when Wordpress::Page
42
+ item.id = blog_api_call("wp.newPage", item.to_struct(:wp), true).to_i
43
+ else
44
+ raise "Unknown item type: #{item}"
45
+ end
39
46
  end #publish
40
47
 
41
- # TODO: rename to "update"
42
- def update_post(post)
43
- process_post_images(post)
44
- return api_call("metaWeblog.editPost", post.id, @user, @password, post.to_struct, post.published)
45
- end #update_post
46
-
47
- def delete(post)
48
- return api_call("blogger.deletePost", "", post.id, @user, @password, true)
48
+ def update(item)
49
+ process_images(item) unless item.images.nil?
50
+ case item
51
+ when Post
52
+ return api_call("metaWeblog.editPost", item.id, @user, @password, item.to_struct(:metaWeblog), item.published)
53
+ when Page
54
+ return api_call("wp.editPage", @id, item.id, @user, @password, item.to_struct(:wp), item.published)
55
+ else
56
+ raise "Unknown item type: #{item}"
57
+ end
58
+ end #update
59
+
60
+ def delete(item)
61
+ case item
62
+ when Wordpress::Post
63
+ return api_call("blogger.deletePost", "", item.id, @user, @password, true)
64
+ when Wordpress::Page
65
+ return blog_api_call("wp.deletePage", item.id)
66
+ else
67
+ raise "Unknown item type: #{item}"
68
+ end
49
69
  end
50
70
 
71
+ def get_page_list
72
+ page_list = blog_api_call("wp.getPageList").collect do |struct|
73
+ Wordpress::Page.from_struct(:wp, struct)
74
+ end
75
+ # link pages list with each other
76
+ page_list.each do |page|
77
+ page.parent = page_list.find{|p| p.id == page.parent_id} if page.parent_id
78
+ end
79
+
80
+ page_list
81
+ end #get_page_list
82
+
51
83
  def upload_file(file)
52
84
  struct = {
53
85
  :name => File.basename(file.path),
@@ -59,9 +91,9 @@ module Wordpress
59
91
  end
60
92
 
61
93
  private
62
- def process_post_images(post)
63
- doc = Nokogiri::HTML::DocumentFragment.parse(post.content)
64
- post.images.each do |image|
94
+ def process_images(item)
95
+ doc = Nokogiri::HTML::DocumentFragment.parse(item.content)
96
+ item.images.each do |image|
65
97
 
66
98
  raise ArgumentError, "Image not found (path: #{image[:file_path]})" unless File.exist?(image[:file_path])
67
99
 
@@ -72,8 +104,8 @@ module Wordpress
72
104
  img['src'] = uploaded_image['url'] if img['src'].include?(basename)
73
105
  end
74
106
  end
75
- post.content = doc.to_html
76
- end #process_post_images
107
+ item.content = doc.to_html
108
+ end #process_images
77
109
 
78
110
  def api_call(method_name, *args)
79
111
  begin
@@ -0,0 +1,74 @@
1
+ module Wordpress
2
+ module ContentItem
3
+ module ClassMethods
4
+ def from_struct(api, struct)
5
+ content_item = self.new
6
+
7
+ self::ATTRIBUTE_MATCHES[api].each do |struct_attribute, item_attribute|
8
+ value = struct[struct_attribute.to_s]
9
+ value = value.to_date if value.kind_of?XMLRPC::DateTime
10
+ content_item.send("#{item_attribute}=", value) unless value.nil?
11
+ end
12
+
13
+ content_item
14
+ end #self.from_struct
15
+ end
16
+
17
+ module InstanceMethods
18
+ def initialize(attributes = {})
19
+ super()
20
+ self.images = []
21
+ apply_attributes(attributes)
22
+ end #initialize
23
+
24
+ def to_struct(api)
25
+ struct = {}
26
+ self.class::ATTRIBUTE_MATCHES[api].each do |struct_attribute, item_attribute|
27
+ value = self.send(item_attribute)
28
+ struct[struct_attribute] = value if value
29
+ end
30
+ struct
31
+ end #to_struct
32
+
33
+ def creation_date=(value)
34
+ case value
35
+ when String
36
+ @creation_date = Date.parse(value)
37
+ when Date
38
+ @creation_date = value
39
+ when nil
40
+ @creation_date = value
41
+ else
42
+ raise ArgumentError, "Date or String expected instead of #{value.class.name}"
43
+ end
44
+ end #creation_date=
45
+
46
+ protected
47
+
48
+ def apply_attributes(attributes)
49
+ attributes.each do |attribute, value|
50
+ accessor_name = "#{attribute}="
51
+ send(accessor_name, value) if respond_to?(accessor_name)
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.included(host)
57
+ host.send :include, InstanceMethods
58
+
59
+ host.class_eval do
60
+ attr_accessor(
61
+ :id,
62
+ :title,
63
+ :content,
64
+ :excerpt,
65
+ :images
66
+ )
67
+ attr_reader(:creation_date)
68
+ end
69
+
70
+ host.extend ClassMethods
71
+ end #included
72
+
73
+ end
74
+ end
data/lib/page.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Wordpress
2
+ class Page
3
+ include ContentItem
4
+
5
+ ATTRIBUTE_MATCHES = {
6
+ :metaWeblog => {
7
+ },
8
+ :wp => {
9
+ :page_id => :id,
10
+ :title => :title,
11
+ :page_title => :title,
12
+ :description => :content,
13
+ :mt_excerpt => :excerpt,
14
+ :dateCreated => :creation_date,
15
+ :page_parent_id => :parent_id,
16
+ :wp_page_parent_id => :parent_id
17
+ }
18
+ }
19
+
20
+ attr_accessor(:parent_id, :published)
21
+ attr_reader(:parent)
22
+
23
+ def parent=(page)
24
+ if page.nil?
25
+ @parent_id = @parent = nil
26
+ else
27
+ raise "Page expected instead of #{page}" unless page.kind_of? Wordpress::Page
28
+ @parent = page
29
+ @parent_id = page.id
30
+ end
31
+ end #parent=
32
+
33
+ end
34
+ end
data/lib/post.rb CHANGED
@@ -1,60 +1,31 @@
1
1
  module Wordpress
2
2
  class Post
3
+ include ContentItem
4
+
3
5
  ATTRIBUTE_MATCHES = {
4
- :title => :title,
5
- :content => :description,
6
- :excerpt => :mt_excerpt,
7
- :creation_date => :dateCreated,
8
- :id => :postid
6
+ :metaWeblog => {
7
+ :postid => :id,
8
+ :title => :title,
9
+ :description => :content,
10
+ :mt_excerpt => :excerpt,
11
+ :dateCreated => :creation_date,
12
+ :post_state => :struct_published
13
+ },
14
+ :wp => {
15
+ }
9
16
  }
10
17
 
11
- attr_accessor(
12
- :id,
13
- :title,
14
- :content,
15
- :excerpt,
16
- :creation_date,
17
- :published,
18
- :images
19
- )
20
-
21
- def initialize(attributes = {})
22
- self.images = []
23
- attributes.each do |attribute, value|
24
- accessor_name = "#{attribute}="
25
- send(accessor_name, value) if respond_to?(accessor_name)
26
- end
27
- end #initialize
18
+ attr_accessor(:published)
28
19
 
29
- def self.from_struct(struct)
30
- post = Post.new
31
- ATTRIBUTE_MATCHES.each do |post_attribute, struct_attribute|
32
- post.send("#{post_attribute}=", struct[struct_attribute])
33
- end
34
- post.published = struct[:post_state] == "publish"
35
- post
36
- end #self.from_struct
20
+ def struct_published=(value)
21
+ @published = value if [true, false].include? value
22
+ @published = value == "publish" if value.kind_of? String
23
+ end
37
24
 
38
- def to_struct
39
- struct = {}
40
- ATTRIBUTE_MATCHES.each do |post_attribute, struct_attribute|
41
- value = self.send(post_attribute)
42
- struct[struct_attribute] = value if value
43
- end
44
- struct
45
- end #to_struct
25
+ def struct_published()
26
+ return "publish" if @published == true
27
+ return nil
28
+ end #struct_published
46
29
 
47
- def creation_date=(value)
48
- case value
49
- when String
50
- @creation_date = Date.parse(value)
51
- when Date
52
- @creation_date = value
53
- when nil
54
- @creation_date = value
55
- else
56
- raise ArgumentError, "Date or String expected instead of #{value.class.name}"
57
- end
58
- end #publish_date=
59
30
  end
60
31
  end
@@ -7,7 +7,9 @@ require 'loggable'
7
7
 
8
8
  require 'exceptions'
9
9
  require 'blog'
10
+ require 'content_item'
10
11
  require 'post'
12
+ require 'page'
11
13
 
12
14
 
13
15
 
data/spec/blog_spec.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Wordpress::Blog do
4
+
4
5
  describe "initialize" do
5
6
  before(:each) do
6
7
  @valid_params = {
@@ -56,56 +57,166 @@ describe Wordpress::Blog do
56
57
  )
57
58
  end
58
59
 
59
- describe "delete_post" do
60
- it "should make appropriate call to xmlrpc api" do
61
- @client_mock.should_receive(:call).with("blogger.deletePost", "", 123, "admin", "wordpress-xmlrpc", true).and_return(true)
60
+ describe "delete" do
61
+ context "when post passed as param" do
62
+ it "should make appropriate call to XMLRPC API" do
63
+ @client_mock.should_receive(:call).with("blogger.deletePost", "", 123, "admin", "wordpress-xmlrpc", true).and_return(true)
64
+
65
+ post = Wordpress::Post.new(:id => 123)
66
+ @blog.delete(post).should be_true
67
+ end
68
+ end
69
+
70
+ context "when page passed as param" do
71
+ it "should make appropriate call to XMLRPC API" do
72
+ @client_mock.should_receive(:call).with("wp.deletePage", 0, "admin", "wordpress-xmlrpc", 123).and_return(true)
73
+
74
+ page = Wordpress::Page.new(:id => 123)
75
+ @blog.delete(page).should be_true
76
+ end
77
+ end
78
+
79
+ end
80
+
81
+ describe "get_page_list" do
82
+ it "should return list of pages" do
83
+ page_structs = [
84
+ {
85
+ "page_id" => 1,
86
+ "page_title" => "Page one",
87
+ "page_parent_id" => 2,
88
+ "dateCreated" => Date.parse("01.08.2010")
89
+ },
90
+ {
91
+ "page_id" => 2,
92
+ "page_title" => "Page two",
93
+ "page_parent_id" => nil,
94
+ "dateCreated" => Date.parse("01.08.2010")
95
+ }
96
+ ]
97
+ @client_mock.should_receive(:call).with("wp.getPageList", 0, "admin", "wordpress-xmlrpc").and_return(page_structs)
98
+
99
+ page_two = Wordpress::Page.new(
100
+ :id => 2,
101
+ :title => "Page two",
102
+ :creation_date => Date.parse("01.08.2010"),
103
+ :parent => nil
104
+ )
105
+ page_one = Wordpress::Page.new(
106
+ :id => 1,
107
+ :title => "Page one",
108
+ :creation_date => Date.parse("01.08.2010"),
109
+ :parent_id => 2
110
+ )
111
+ page_list = [page_one, page_two]
112
+
113
+ result_page_list = @blog.get_page_list
114
+ result_page_list.size.should == 2
115
+
116
+ result_page_list[0].id.should == 1
117
+ result_page_list[0].title.should == "Page one"
118
+ result_page_list[0].parent_id == 2
119
+ result_page_list[0].parent.should == result_page_list[1]
120
+ result_page_list[0].creation_date.should == Date.parse("01.08.2010")
121
+
122
+ result_page_list[1].id.should == 2
123
+ result_page_list[1].title.should == "Page two"
124
+ result_page_list[1].parent_id.should be_nil
125
+ result_page_list[1].creation_date.should == Date.parse("01.08.2010")
62
126
 
63
- post = Wordpress::Post.new(:id => 123)
64
- @blog.delete(post).should be_true
65
127
  end
66
128
  end
67
129
 
68
130
  describe "publish" do
69
- it "should make appropriate call to xmlrpc api" do
70
- images = [{:file_path => File.expand_path("./spec/support/files/post_picture.jpg")}]
71
- post = Wordpress::Post.new(
72
- :title => "Hey ho",
73
- :content => "Content <img src=\"http://otherhost/post_picture.jpg?1231231123\">",
74
- :excerpt => "Excerpt",
75
- :images => images,
76
- :publish_date => Date.parse("01.08.2010"))
77
-
78
-
79
- required_post_struct = {
80
- :title=>"Hey ho",
81
- :description=>"Content <img src=\"http://localhost/post_picture.jpg\">",
82
- :mt_excerpt=>"Excerpt"
83
- }
131
+ context "when Page passed as param" do
132
+ it "should make appropriate calls to XMLRPC API" do
133
+ images = [{:file_path => File.expand_path("./spec/support/files/post_picture.jpg")}]
84
134
 
85
- @client_mock.should_receive(:call).with(
86
- "wp.uploadFile",
87
- 0, "admin", "wordpress-xmlrpc",
88
- {
89
- :name => "post_picture.jpg",
90
- :type => "image/jpeg",
91
- :bits => "encoded file content",
92
- :overwrite => true
93
- }).and_return({
94
- 'file' => "post_picture.jpg",
95
- 'url' => "http://localhost/post_picture.jpg",
96
- 'type' => "image/jpeg"
97
- })
135
+ page = Wordpress::Page.new(
136
+ :title => "new Page",
137
+ :content => "Page content",
138
+ :excerpt => "Page excerpt",
139
+ :creation_date => Date.parse("01.08.2010"),
140
+ :images => images
141
+ )
142
+ @client_mock.should_receive(:call).with("wp.newPage",
143
+ 0, "admin", "wordpress-xmlrpc",
144
+ {
145
+ :title => "new Page",
146
+ :page_title => "new Page",
147
+ :description => "Page content",
148
+ :mt_excerpt => "Page excerpt",
149
+ :dateCreated => Date.parse("01.08.2010")
150
+ }, true).and_return(123)
98
151
 
99
- @client_mock.should_receive(:call).with(
100
- "metaWeblog.newPost",
101
- 0, "admin", "wordpress-xmlrpc",
102
- required_post_struct, true).and_return("123")
152
+ file_struct = {
153
+ :name => "post_picture.jpg",
154
+ :type => "image/jpeg",
155
+ :bits => "encoded file content",
156
+ :overwrite => true
157
+ }
158
+ @client_mock.should_receive(:call).with(
159
+ "wp.uploadFile",
160
+ 0, "admin", "wordpress-xmlrpc",
161
+ file_struct).and_return({
162
+ 'file' => "post_picture.jpg",
163
+ 'url' => "http://localhost/post_picture.jpg",
164
+ 'type' => "image/jpeg"
165
+ })
166
+
167
+ XMLRPC::Base64.should_receive(:new).and_return("encoded file content")
103
168
 
104
- XMLRPC::Base64.should_receive(:new).and_return("encoded file content")
105
169
 
106
- @blog.publish(post).should be_true
107
- post.id.should == 123
108
- post.published.should be_true
170
+ @blog.publish(page).should be_true
171
+ page.id.should == 123
172
+ end
173
+ end
174
+
175
+ context "when Post passed as param" do
176
+ it "should make appropriate call to XMLRPC API" do
177
+ images = [{:file_path => File.expand_path("./spec/support/files/post_picture.jpg")}]
178
+ post = Wordpress::Post.new(
179
+ :title => "Hey ho",
180
+ :content => "Content <img src=\"http://otherhost/post_picture.jpg?1231231123\">",
181
+ :excerpt => "Excerpt",
182
+ :images => images,
183
+ :creation_date => Date.parse("01.08.2010"))
184
+
185
+
186
+ required_post_struct = {
187
+ :title => "Hey ho",
188
+ :description => "Content <img src=\"http://localhost/post_picture.jpg\">",
189
+ :mt_excerpt => "Excerpt",
190
+ :dateCreated => Date.parse("01.08.2010")
191
+ }
192
+
193
+
194
+ file_struct = {
195
+ :name => "post_picture.jpg",
196
+ :type => "image/jpeg",
197
+ :bits => "encoded file content",
198
+ :overwrite => true
199
+ }
200
+ @client_mock.should_receive(:call).with(
201
+ "wp.uploadFile",
202
+ 0, "admin", "wordpress-xmlrpc",
203
+ file_struct).and_return({
204
+ 'file' => "post_picture.jpg",
205
+ 'url' => "http://localhost/post_picture.jpg",
206
+ 'type' => "image/jpeg"
207
+ })
208
+
209
+ @client_mock.should_receive(:call).with(
210
+ "metaWeblog.newPost",
211
+ 0, "admin", "wordpress-xmlrpc",
212
+ required_post_struct, true).and_return("123")
213
+
214
+ XMLRPC::Base64.should_receive(:new).and_return("encoded file content")
215
+
216
+ @blog.publish(post).should be_true
217
+ post.id.should == 123
218
+ post.published.should be_true
219
+ end
109
220
  end
110
221
  end
111
222
 
@@ -113,11 +224,14 @@ describe Wordpress::Blog do
113
224
  it "should make appropriate call to xmlrpc api and return list of posts" do
114
225
  post_structs = (1..10).collect do |index|
115
226
  {
116
- :title => "Post #{index}"
227
+ "title" => "Post #{index}"
117
228
  }
118
229
  end
119
230
 
120
- @client_mock.should_receive(:call).with("metaWeblog.getRecentPosts", 0, "admin", "wordpress-xmlrpc", 10).and_return(post_structs)
231
+ @client_mock.should_receive(:call).with(
232
+ "metaWeblog.getRecentPosts",
233
+ 0, "admin", "wordpress-xmlrpc",
234
+ 10).and_return(post_structs)
121
235
 
122
236
  recent_posts = @blog.recent_posts(10)
123
237
  recent_posts.size.should == 10
@@ -137,38 +251,83 @@ describe Wordpress::Blog do
137
251
  end
138
252
  end
139
253
 
140
- describe "update_post" do
141
- it "should submit post update" do
142
- images = [{:file_path => File.expand_path("./spec/support/files/post_picture.jpg")}]
143
- post = Wordpress::Post.new(:id => 54, :title => "Updated post", :content => "Content <img src=\"http://otherhost/post_picture.jpg\">", :published => true, :images => images)
254
+ describe "update" do
255
+ before(:each) do
256
+ @images = [{:file_path => File.expand_path("./spec/support/files/post_picture.jpg")}]
144
257
 
145
- required_post_struct = {
146
- :title=>"Updated post",
147
- :description=>"Content <img src=\"http://localhost/post_picture.jpg\">",
148
- :postid => 54
149
- }
150
- @client_mock.should_receive(:call).with("metaWeblog.editPost",
151
- 54, "admin", "wordpress-xmlrpc",
152
- required_post_struct, true).and_return(true)
258
+ end
153
259
 
154
- @client_mock.should_receive(:call).with("wp.uploadFile",
155
- 0, "admin", "wordpress-xmlrpc",
156
- {
157
- :name => "post_picture.jpg",
158
- :type => "image/jpeg",
159
- :bits => "encoded file content",
160
- :overwrite => true
161
- }).and_return({
162
- 'file' => "post_picture.jpg",
163
- 'url' => "http://localhost/post_picture.jpg",
164
- 'type' => "image/jpeg"
165
- })
166
- XMLRPC::Base64.should_receive(:new).and_return("encoded file content")
167
-
168
- @blog.update_post(post).should be_true
260
+ context "when page passed as param" do
261
+ it "should submit page update" do
262
+ page = Wordpress::Page.new(
263
+ :id => 123,
264
+ :title => "Updated page",
265
+ :content => "Content <img src=\"http://otherhost/post_picture.jpg\">",
266
+ :published => true,
267
+ :images => @images
268
+ )
269
+ required_page_struct = {
270
+ :title => "Updated page",
271
+ :page_title => "Updated page",
272
+ :description => "Content <img src=\"http://localhost/post_picture.jpg\">",
273
+ :page_id => 123
274
+ }
275
+ @client_mock.should_receive(:call).with("wp.editPage", 0, 123, "admin", "wordpress-xmlrpc", required_page_struct, true).and_return true
276
+ @client_mock.should_receive(:call).with("wp.uploadFile",
277
+ 0, "admin", "wordpress-xmlrpc",
278
+ {
279
+ :name => "post_picture.jpg",
280
+ :type => "image/jpeg",
281
+ :bits => "encoded file content",
282
+ :overwrite => true
283
+ }).and_return({
284
+ 'file' => "post_picture.jpg",
285
+ 'url' => "http://localhost/post_picture.jpg",
286
+ 'type' => "image/jpeg"
287
+ })
288
+ XMLRPC::Base64.should_receive(:new).and_return("encoded file content")
289
+
290
+ @blog.update(page).should be_true
291
+ end
169
292
  end
170
- end
171
293
 
294
+ context "when post passed as param" do
295
+ it "should submit post update" do
296
+ post = Wordpress::Post.new(
297
+ :id => 54,
298
+ :title => "Updated post",
299
+ :content => "Content <img src=\"http://otherhost/post_picture.jpg\">",
300
+ :published => true,
301
+ :images => @images)
302
+
303
+ required_post_struct = {
304
+ :title => "Updated post",
305
+ :description => "Content <img src=\"http://localhost/post_picture.jpg\">",
306
+ :postid => 54,
307
+ :post_state => "publish"
308
+ }
309
+ @client_mock.should_receive(:call).with("metaWeblog.editPost",
310
+ 54, "admin", "wordpress-xmlrpc",
311
+ required_post_struct, true).and_return(true)
312
+
313
+ @client_mock.should_receive(:call).with("wp.uploadFile",
314
+ 0, "admin", "wordpress-xmlrpc",
315
+ {
316
+ :name => "post_picture.jpg",
317
+ :type => "image/jpeg",
318
+ :bits => "encoded file content",
319
+ :overwrite => true
320
+ }).and_return({
321
+ 'file' => "post_picture.jpg",
322
+ 'url' => "http://localhost/post_picture.jpg",
323
+ 'type' => "image/jpeg"
324
+ })
325
+ XMLRPC::Base64.should_receive(:new).and_return("encoded file content")
326
+
327
+ @blog.update(post).should be_true
328
+ end
329
+ end
330
+ end
172
331
  end
173
332
  end
174
333
 
data/spec/page_spec.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wordpress::Page do
4
+ subject {Wordpress::Page}
5
+
6
+ it_should_behave_like "Blog item"
7
+
8
+ describe "matching attributes" do
9
+ it "should match attributes as defined in wp API" do
10
+ matches = Wordpress::Page::ATTRIBUTE_MATCHES[:wp]
11
+ matches[:page_id].should == :id
12
+ matches[:title].should == :title
13
+ matches[:page_title].should == :title
14
+ matches[:description].should == :content
15
+ matches[:mt_excerpt].should == :excerpt
16
+ matches[:dateCreated].should == :creation_date
17
+ matches[:page_parent_id].should == :parent_id
18
+ matches[:wp_page_parent_id].should == :parent_id
19
+ end
20
+
21
+ it "should not match for metaWeblog API at all" do
22
+ matches = Wordpress::Page::ATTRIBUTE_MATCHES[:metaWeblog]
23
+ matches.should be_empty
24
+ end
25
+ end
26
+
27
+ describe "parent=" do
28
+ it "should assign parent_id when parent page assigned" do
29
+ parent_page = Wordpress::Page.new(:title => "parent page", :id => 123)
30
+ child_page = Wordpress::Page.new(:title => "child page")
31
+ child_page.parent = parent_page
32
+ child_page.parent_id.should == 123
33
+ end
34
+ end
35
+
36
+ end
data/spec/post_spec.rb CHANGED
@@ -1,91 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Wordpress::Post do
4
- describe "initialize" do
5
- it "should populate title from params" do
6
- post = Wordpress::Post.new(:title => "Hey ho")
7
- post.title.should == "Hey ho"
8
- end
9
- it "should populate content from params" do
10
- post = Wordpress::Post.new(:content => "This is a content")
11
- post.content.should == "This is a content"
12
- end
13
- end
14
-
15
- describe "to_struct" do
16
- it "should return struct hash reflecting all post params" do
17
- post = Wordpress::Post.new(
18
- :id => 99,
19
- :title => "Post title",
20
- :content => "Post content",
21
- :excerpt => "Post excerpt",
22
- :creation_date => Date.parse("01.08.2010")
23
- )
24
- post.to_struct.should == {
25
- :postid => 99,
26
- :title => "Post title",
27
- :description => "Post content",
28
- :mt_excerpt => "Post excerpt",
29
- :dateCreated => Date.parse("01.08.2010")
30
- }
31
- end
32
- it "should return incomplete struct for params without params that are nil" do
33
- post = Wordpress::Post.new(:title => "Post title")
34
- post.to_struct.should == {
35
- :title => "Post title"
36
- }
37
- end
38
- end
39
-
40
- describe "from_struct" do
41
- it "should create post from RPC struct" do
42
- post = Wordpress::Post.from_struct({
43
- :postid => 99,
44
- :title => "Post title",
45
- :description => "Post content",
46
- :mt_excerpt => "Post excerpt",
47
- :dateCreated => "01.08.2010",
48
- :post_state => "publish"
49
- })
50
- post.id.should == 99
51
- post.title.should == "Post title"
52
- post.content.should == "Post content"
53
- post.excerpt.should == "Post excerpt"
54
- post.creation_date.should == Date.parse("01.08.2010")
55
- post.published.should be_true
56
- end
57
- end
4
+ subject {Wordpress::Post}
58
5
 
59
- describe "creation_date=" do
60
- before(:each) do
61
- @post = Wordpress::Post.new
62
- end
6
+ it_should_behave_like "Blog item"
63
7
 
64
- it "should convert string to date" do
65
- @post.creation_date = "01.08.2010"
66
- @post.creation_date.should == Date.parse("01.08.2010")
8
+ describe "matching attributes" do
9
+ it "should match attributes as defined in metaWeblog API" do
10
+ matches = Wordpress::Post::ATTRIBUTE_MATCHES[:metaWeblog]
11
+ matches[:postid].should == :id
12
+ matches[:title].should == :title
13
+ matches[:description].should == :content
14
+ matches[:mt_excerpt].should == :excerpt
15
+ matches[:post_state].should == :struct_published
67
16
  end
68
-
69
- it "should assign date as is if kind_of? Date provided" do
70
- date = Date.parse("01.08.2010")
71
- @post.creation_date = date
72
- @post.creation_date.should == date
73
- end
74
-
75
- it "should raise error if string could not be parsed to date" do
76
- lambda{
77
- @post.creation_date = "abracadabra"
78
- }.should raise_error ArgumentError, "invalid date"
79
- end
80
-
81
- it "should raise exception if object is not a string and not a date" do
82
- lambda{
83
- @post.creation_date = Integer(10)
84
- }.should raise_error ArgumentError, "Date or String expected instead of Fixnum"
17
+ it "should not match for wp API at all" do
18
+ matches = Wordpress::Post::ATTRIBUTE_MATCHES[:wp]
19
+ matches.should be_empty
85
20
  end
86
21
  end
87
22
 
88
-
89
-
90
23
  end
91
24
 
data/spec/spec.opts CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --format specdoc
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,10 @@ require 'spec/autorun'
13
13
 
14
14
  require 'wordpress-xmlrpc'
15
15
 
16
+ # Requires supporting files with custom matchers and macros, etc,
17
+ # in ./support/ and its subdirectories.
18
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
19
+
16
20
  Spec::Runner.configure do |config|
17
21
 
18
22
  end
@@ -0,0 +1,86 @@
1
+ shared_examples_for "Blog item" do
2
+ before(:each) do
3
+ @api_standard = subject == Wordpress::Post ? :metaWeblog : :wp
4
+ end
5
+
6
+
7
+
8
+ describe "initialize" do
9
+ it "should populate title from params" do
10
+ item = subject.new(:title => "Hey ho")
11
+ item.title.should == "Hey ho"
12
+ end
13
+ it "should populate content from params" do
14
+ item = subject.new(:content => "This is a content")
15
+ item.content.should == "This is a content"
16
+ end
17
+ end
18
+
19
+ describe "to_struct" do
20
+ it "should return struct hash reflecting matching item params" do
21
+ item = subject.new(
22
+ :content => "item content",
23
+ :excerpt => "item excerpt",
24
+ :creation_date => Date.parse("01.08.2010")
25
+ )
26
+ item.to_struct(@api_standard).should == {
27
+ :description => "item content",
28
+ :mt_excerpt => "item excerpt",
29
+ :dateCreated => Date.parse("01.08.2010")
30
+ }
31
+ end
32
+
33
+ it "should return incomplete struct for params without params that are nil" do
34
+ item = subject.new(:content => "item content")
35
+ item.to_struct(@api_standard).should == {
36
+ :description => "item content"
37
+ }
38
+ end
39
+ end
40
+
41
+ describe "from_struct" do
42
+ it "should create item from RPC struct" do
43
+ item = subject.from_struct(@api_standard,
44
+ {
45
+ "description" => "item content",
46
+ "mt_excerpt" => "item excerpt",
47
+ "dateCreated" => "01.08.2010"
48
+ })
49
+ item.content.should == "item content"
50
+ item.excerpt.should == "item excerpt"
51
+ item.creation_date.should == Date.parse("01.08.2010")
52
+ end
53
+ end
54
+
55
+ describe "creation_date=" do
56
+ before(:each) do
57
+ @item = subject.new
58
+ end
59
+
60
+ it "should convert string to date" do
61
+ @item.creation_date = "01.08.2010"
62
+ @item.creation_date.should == Date.parse("01.08.2010")
63
+ end
64
+
65
+ it "should assign date as is if kind_of? Date provided" do
66
+ date = Date.parse("01.08.2010")
67
+ @item.creation_date = date
68
+ @item.creation_date.should == date
69
+ end
70
+
71
+ it "should raise error if string could not be parsed to date" do
72
+ lambda{
73
+ @item.creation_date = "abracadabra"
74
+ }.should raise_error ArgumentError, "invalid date"
75
+ end
76
+
77
+ it "should raise exception if object is not a string and not a date" do
78
+ lambda{
79
+ @item.creation_date = Integer(10)
80
+ }.should raise_error ArgumentError, "Date or String expected instead of Fixnum"
81
+ end
82
+ end
83
+
84
+
85
+
86
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wordpress-xmlrpc}
8
- s.version = "0.0.9"
8
+ s.version = "0.0.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Naumenko"]
12
- s.date = %q{2010-09-20}
12
+ s.date = %q{2010-10-05}
13
13
  s.description = %q{Please do not fork it before directly contacint}
14
14
  s.email = %q{alecnmk@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -29,16 +29,20 @@ Gem::Specification.new do |s|
29
29
  "features/step_definitions/mysql_steps.rb",
30
30
  "features/support/env.rb",
31
31
  "lib/blog.rb",
32
+ "lib/content_item.rb",
32
33
  "lib/exceptions.rb",
33
34
  "lib/loggable.rb",
35
+ "lib/page.rb",
34
36
  "lib/params_check.rb",
35
37
  "lib/post.rb",
36
38
  "lib/wordpress-xmlrpc.rb",
37
39
  "spec/blog_spec.rb",
40
+ "spec/page_spec.rb",
38
41
  "spec/post_spec.rb",
39
42
  "spec/spec.opts",
40
43
  "spec/spec_helper.rb",
41
44
  "spec/support/files/post_picture.jpg",
45
+ "spec/support/models/blog_item_shared.rb",
42
46
  "wordpress-xmlrpc.gemspec"
43
47
  ]
44
48
  s.homepage = %q{http://github.com/alecnmk/wordpress-xmlrpc}
@@ -47,8 +51,10 @@ Gem::Specification.new do |s|
47
51
  s.rubygems_version = %q{1.3.7}
48
52
  s.summary = %q{This gem is supposed to simplify wordpress xmlrpc interaction}
49
53
  s.test_files = [
50
- "spec/spec_helper.rb",
54
+ "spec/page_spec.rb",
55
+ "spec/spec_helper.rb",
51
56
  "spec/blog_spec.rb",
57
+ "spec/support/models/blog_item_shared.rb",
52
58
  "spec/post_spec.rb"
53
59
  ]
54
60
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordpress-xmlrpc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Naumenko
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-20 00:00:00 +03:00
18
+ date: 2010-10-05 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -105,16 +105,20 @@ files:
105
105
  - features/step_definitions/mysql_steps.rb
106
106
  - features/support/env.rb
107
107
  - lib/blog.rb
108
+ - lib/content_item.rb
108
109
  - lib/exceptions.rb
109
110
  - lib/loggable.rb
111
+ - lib/page.rb
110
112
  - lib/params_check.rb
111
113
  - lib/post.rb
112
114
  - lib/wordpress-xmlrpc.rb
113
115
  - spec/blog_spec.rb
116
+ - spec/page_spec.rb
114
117
  - spec/post_spec.rb
115
118
  - spec/spec.opts
116
119
  - spec/spec_helper.rb
117
120
  - spec/support/files/post_picture.jpg
121
+ - spec/support/models/blog_item_shared.rb
118
122
  - wordpress-xmlrpc.gemspec
119
123
  has_rdoc: true
120
124
  homepage: http://github.com/alecnmk/wordpress-xmlrpc
@@ -151,6 +155,8 @@ signing_key:
151
155
  specification_version: 3
152
156
  summary: This gem is supposed to simplify wordpress xmlrpc interaction
153
157
  test_files:
158
+ - spec/page_spec.rb
154
159
  - spec/spec_helper.rb
155
160
  - spec/blog_spec.rb
161
+ - spec/support/models/blog_item_shared.rb
156
162
  - spec/post_spec.rb