wp_rpc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +4 -0
- data/Gemfile +8 -0
- data/LICENSE +22 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/lib/wp_rpc/attachment.rb +38 -0
- data/lib/wp_rpc/base.rb +23 -0
- data/lib/wp_rpc/blog.rb +65 -0
- data/lib/wp_rpc/category.rb +37 -0
- data/lib/wp_rpc/collections/attachments.rb +9 -0
- data/lib/wp_rpc/collections/categories.rb +38 -0
- data/lib/wp_rpc/collections/posts.rb +30 -0
- data/lib/wp_rpc/post.rb +95 -0
- data/lib/wp_rpc/version.rb +3 -0
- data/lib/wp_rpc.rb +11 -0
- data/spec/blog_spec.rb +119 -0
- data/spec/category_collection_spec.rb +12 -0
- data/spec/category_spec.rb +24 -0
- data/spec/spec_helper.rb +28 -0
- data/wp_rpc.gemspec +18 -0
- metadata +70 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alex Ferreira
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# WpRpc
|
2
|
+
|
3
|
+
WpRpc is a Ruby library for reading and writing blogs to Wordpress via XMLRPC interface.
|
4
|
+
|
5
|
+
The documentation is missing and the test set is not complete.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'wp_rpc'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install wp_rpc
|
20
|
+
|
21
|
+
### Usage
|
22
|
+
|
23
|
+
require 'wp_rpc'
|
24
|
+
blog = WpRpc::Blog.new :url => 'http://www.example.com/xmlrpc.php', :username => 'admin', :password=> 'admin'
|
25
|
+
|
26
|
+
# Output the list of categories
|
27
|
+
blog.categories.map { |c| puts "Category: #{c.name}" }
|
28
|
+
|
29
|
+
# Get List of Posts
|
30
|
+
blog.posts.all.map{|p| puts p['title']}
|
31
|
+
|
32
|
+
# Get the 20 most recent posts
|
33
|
+
blog.posts.find_recent(:limit => 20).map { |p| puts "#{p.id} | #{p.title}" }
|
34
|
+
|
35
|
+
# Create a new blog post
|
36
|
+
post = blog.posts.new(:title => 'Test', :description => 'This is a test', :keywords => 'test, testing', :published => true)
|
37
|
+
post.save
|
38
|
+
|
39
|
+
# Edit a blog post
|
40
|
+
post = blog.posts.find(1)
|
41
|
+
post.title = "Edited title"
|
42
|
+
post.save
|
43
|
+
|
44
|
+
# Upload an attachment
|
45
|
+
attachment = blog.attachments.new(:name => 'Photo of me', :filename => '/home/john/me.jpg')
|
46
|
+
attachment.save
|
47
|
+
|
48
|
+
### Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "wp_rpc/collections/attachments"
|
2
|
+
module WpRpc
|
3
|
+
class Attachment < Base
|
4
|
+
attr_accessor :name, :mimetype, :file, :filename, :url
|
5
|
+
|
6
|
+
def initialize(attributes, options = { })
|
7
|
+
super(options)
|
8
|
+
self.name = attributes[:name]
|
9
|
+
self.filename = attributes[:filename]
|
10
|
+
self.mimetype = attributes[:mimetype]
|
11
|
+
self.file = attributes[:file]
|
12
|
+
end
|
13
|
+
|
14
|
+
def save
|
15
|
+
ret = conn.upload_file(name, mimetype, bits)
|
16
|
+
self.url = ret["url"]
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def mimetype
|
21
|
+
@mimetype ||= MIME::Types.type_for(name).to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
@name ||= File.basename(filename)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def bits
|
31
|
+
file.read
|
32
|
+
end
|
33
|
+
|
34
|
+
def file
|
35
|
+
@file ||= File.open(filename)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/wp_rpc/base.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module WpRpc
|
2
|
+
class Error < StandardError ; end
|
3
|
+
class ConnectionFailure < Error ; end
|
4
|
+
|
5
|
+
class Base
|
6
|
+
def initialize(options = { })
|
7
|
+
@conn = options[:conn] || options[:connection]
|
8
|
+
end
|
9
|
+
|
10
|
+
def conn
|
11
|
+
@conn
|
12
|
+
end
|
13
|
+
|
14
|
+
def pattern
|
15
|
+
@pattern = {"post_title" => "title", "post_content" => "content"}
|
16
|
+
end
|
17
|
+
|
18
|
+
def change_attributes(source, mappings = {})
|
19
|
+
source.map{ |obj| obj.keys.each { |k| obj[mappings[k] ] = obj.delete(k) if mappings[k] } }
|
20
|
+
source
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/wp_rpc/blog.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module WpRpc
|
2
|
+
class Blog
|
3
|
+
attr_accessor :url, :username, :password, :blog_id
|
4
|
+
|
5
|
+
def initialize(options = { })
|
6
|
+
@username = options[:username] if options[:username]
|
7
|
+
@password = options[:password] if options[:password]
|
8
|
+
@blog_id = options[:blog_id] || 1
|
9
|
+
@url = options[:url] if options[:url]
|
10
|
+
end
|
11
|
+
|
12
|
+
def posts
|
13
|
+
@post_collection ||= Collection::Posts.new(:conn => self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def attachments
|
17
|
+
@attachments ||= Collection::Attachments.new(:conn => self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def categories
|
21
|
+
@categories ||= Collection::Categories.new(:conn => self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_recent_posts(limit = 10)
|
25
|
+
call('metaWeblog.getRecentPosts', blog_id, username, password, limit)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_post(qid)
|
29
|
+
call('metaWeblog.getPost', qid, username, password)
|
30
|
+
end
|
31
|
+
|
32
|
+
def edit_post(qid, attributes, published = nil)
|
33
|
+
cargs = ['metaWeblog.editPost', qid, username, password, attributes]
|
34
|
+
cargs << published unless published.nil?
|
35
|
+
call(*cargs)
|
36
|
+
end
|
37
|
+
|
38
|
+
def new_post(attributes, published = nil)
|
39
|
+
cargs = ['metaWeblog.newPost', blog_id, username, password, attributes]
|
40
|
+
cargs << published unless published.nil?
|
41
|
+
call(*cargs)
|
42
|
+
end
|
43
|
+
|
44
|
+
def upload_file(name, mimetype, bits, overwrite = false)
|
45
|
+
|
46
|
+
call('wp.uploadFile', blog_id, username, password,
|
47
|
+
{ :name => name, :type => mimetype, :bits => XMLRPC::Base64.new(bits), :overwrite => overwrite })
|
48
|
+
end
|
49
|
+
|
50
|
+
def call(*args)
|
51
|
+
xmlrpc.call(*args)
|
52
|
+
rescue XMLRPC::FaultException => e
|
53
|
+
if e.message =~ /XML-RPC services are disabled/
|
54
|
+
raise WpRpc::ConnectionFailure, e.message
|
55
|
+
else
|
56
|
+
raise WpRpc::Error, e.message
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def xmlrpc
|
61
|
+
@xclient ||= XMLRPC::Client.new2(url)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "wp_rpc/collections/categories"
|
2
|
+
module WpRpc
|
3
|
+
class Category
|
4
|
+
attr_reader :id, :category_id, :description, :name, :url, :rss_url, :conn
|
5
|
+
|
6
|
+
def initialize(attributes = {}, options = {})
|
7
|
+
@id = attributes[:id]
|
8
|
+
@category_id = attributes[:category_id] || 0
|
9
|
+
@description = attributes[:description]
|
10
|
+
@name = attributes[:name]
|
11
|
+
@url = attributes[:url]
|
12
|
+
@rss_url = attributes[:rss_url]
|
13
|
+
@slug = attributes[:slug]
|
14
|
+
@conn = options[:conn]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.new_from_xmlrpc(attributes, options = {})
|
18
|
+
self.new( { :id => attributes['categoryId'], :category_id => attributes['parentId'],
|
19
|
+
:description => attributes['description'], :name => attributes['categoryName'],
|
20
|
+
:url => attributes['htmlUrl'], :rss_url => attributes['rssUrl'] },
|
21
|
+
options )
|
22
|
+
end
|
23
|
+
|
24
|
+
def save
|
25
|
+
@id = conn.call 'wp.newCategory', conn.blog_id, conn.username, conn.password, to_xmlrpc_struct
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_xmlrpc_struct
|
29
|
+
{ "name" => name, "slug" => slug, "parent_id" => category_id, "description" => description.to_s }
|
30
|
+
end
|
31
|
+
|
32
|
+
def slug
|
33
|
+
@slug ||= @name.to_s.downcase.strip.gsub(/\s/, '-')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module WpRpc
|
2
|
+
module Collection
|
3
|
+
class Categories < Base
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
super(*args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def all
|
11
|
+
@categories ||= load
|
12
|
+
end
|
13
|
+
|
14
|
+
# retrieve the categories via xmlrpc
|
15
|
+
def load
|
16
|
+
cats = []
|
17
|
+
conn.call('wp.getCategories', conn.blog_id, conn.username, conn.password).each do |c|
|
18
|
+
cats << WpRpc::Category.new_from_xmlrpc(c, :conn => conn)
|
19
|
+
end
|
20
|
+
@categories = cats
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](i)
|
24
|
+
all[i]
|
25
|
+
end
|
26
|
+
|
27
|
+
def each
|
28
|
+
all.each { |c| yield c }
|
29
|
+
end
|
30
|
+
|
31
|
+
def create(attributes)
|
32
|
+
new_cat = WpRpc::Category.new(attributes, :conn => conn)
|
33
|
+
new_cat.save
|
34
|
+
new_cat
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module WpRpc
|
2
|
+
module Collection
|
3
|
+
class Posts < Base
|
4
|
+
def find_recent(options = { })
|
5
|
+
options = { :limit => 10 }.merge(options)
|
6
|
+
posts = conn.get_recent_posts(options[:limit])
|
7
|
+
posts.collect { |post| Post.new(post, :conn => conn) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(qid, options = { })
|
11
|
+
if qid.is_a?(Array)
|
12
|
+
qid.collect { |sqid| find(sqid) }
|
13
|
+
elsif qid == :recent
|
14
|
+
find_recent(options)
|
15
|
+
else
|
16
|
+
post = conn.get_post(qid)
|
17
|
+
Post.new(post, :conn => conn)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def new(attributes = { })
|
22
|
+
WpRpc::Post.new(attributes, :conn => conn)
|
23
|
+
end
|
24
|
+
|
25
|
+
def all
|
26
|
+
change_attributes(conn.call('wp.getPosts', conn.blog_id, conn.username, conn.password), pattern)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/wp_rpc/post.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require "wp_rpc/collections/posts"
|
2
|
+
module WpRpc
|
3
|
+
class Post < Base
|
4
|
+
attr_accessor :title, :content
|
5
|
+
attr_accessor :created_at
|
6
|
+
attr_accessor :keywords, :categories, :published
|
7
|
+
|
8
|
+
def initialize(attributes = { }, options = { })
|
9
|
+
super(options)
|
10
|
+
self.attributes = attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
def attributes=(attr)
|
14
|
+
symbolized_attr = { }
|
15
|
+
attr = attr.each { |k,v| symbolized_attr[k.to_sym] = v }
|
16
|
+
attr = symbolized_attr
|
17
|
+
@title = attr[:title]
|
18
|
+
@keywords = attr[:keywords].to_s.split(/,|;/).collect { |k| k.strip }
|
19
|
+
@categories = attr[:categories]
|
20
|
+
@content = attr[:content]
|
21
|
+
@created_at = attr[:dateCreated]
|
22
|
+
@id = attr[:postid]
|
23
|
+
@userid = attr[:userid]
|
24
|
+
@published = attr[:published]
|
25
|
+
end
|
26
|
+
|
27
|
+
def id
|
28
|
+
@id
|
29
|
+
end
|
30
|
+
|
31
|
+
def save
|
32
|
+
id ? update : create
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
conn.edit_post(id, attributes, published)
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def create
|
41
|
+
@id = conn.new_post(attributes, published)
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
def publish
|
46
|
+
self.published = true
|
47
|
+
save
|
48
|
+
end
|
49
|
+
|
50
|
+
def keywords
|
51
|
+
if @keywords.is_a? String
|
52
|
+
@keywords = @keywords.split(",")
|
53
|
+
elsif @keywords.is_a? Array
|
54
|
+
@keywords
|
55
|
+
else
|
56
|
+
[]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def created_at
|
61
|
+
@created_at
|
62
|
+
end
|
63
|
+
|
64
|
+
def categories
|
65
|
+
if @categories.nil?
|
66
|
+
[]
|
67
|
+
elsif @categories.is_a?(Array)
|
68
|
+
@categories
|
69
|
+
elsif @categories.is_a(String)
|
70
|
+
@categories = @categories.split(",")
|
71
|
+
else
|
72
|
+
[]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def attributes
|
77
|
+
h = { }
|
78
|
+
h[:title] = title if title
|
79
|
+
h[:description] = content if content
|
80
|
+
h[:dateCreated] = created_at if created_at
|
81
|
+
h[:mt_keywords] = keywords.join(",")
|
82
|
+
h[:categories] = categories if categories
|
83
|
+
h
|
84
|
+
end
|
85
|
+
|
86
|
+
def reload
|
87
|
+
if id
|
88
|
+
saved_id = id
|
89
|
+
self.attributes = conn.posts.find(id).attributes
|
90
|
+
@id = saved_id
|
91
|
+
true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/wp_rpc.rb
ADDED
data/spec/blog_spec.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe Blog do
|
4
|
+
|
5
|
+
describe "initialize" do
|
6
|
+
it "take the :username, :password, :url and :blog_id options" do
|
7
|
+
blog = a_wp_blog
|
8
|
+
blog.username.should == valid_wp_blog_options[:username]
|
9
|
+
blog.password.should == valid_wp_blog_options[:password]
|
10
|
+
blog.blog_id.should == valid_wp_blog_options[:blog_id]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should default to blog_id 1" do
|
14
|
+
Blog.new.blog_id.should == 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return an XMLRPC::Client" do
|
19
|
+
xmlrpc = a_wp_blog.send(:xmlrpc)
|
20
|
+
xmlrpc.should be_a_kind_of XMLRPC::Client
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should make xmlrpc calls to metaWeblog.getPost" do
|
24
|
+
blog = a_wp_blog
|
25
|
+
blog.send(:xmlrpc).should_receive(:call).once.with('metaWeblog.getPost',
|
26
|
+
999, blog.username, blog.password )
|
27
|
+
blog.get_post(999)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should make xmlrpc calls to metaWeblog.getRecentPosts" do
|
31
|
+
blog = a_wp_blog
|
32
|
+
blog.send(:xmlrpc).should_receive(:call).once.with('metaWeblog.getRecentPosts',
|
33
|
+
blog.blog_id, blog.username, blog.password, 345)
|
34
|
+
blog.get_recent_posts(345)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "edit_post" do
|
38
|
+
|
39
|
+
it "should make xmlrpc calls to metaWeblog.editPost with no published arg by default" do
|
40
|
+
blog = a_wp_blog
|
41
|
+
blog.send(:xmlrpc).should_receive(:call).once.with('metaWeblog.editPost',
|
42
|
+
98, blog.username, blog.password,
|
43
|
+
valid_wp_post_options)
|
44
|
+
blog.edit_post(98, valid_wp_post_options)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should make xmlrpc calls to metaWeblog.editPost with published = true" do
|
48
|
+
blog = a_wp_blog
|
49
|
+
blog.send(:xmlrpc).should_receive(:call).once.with('metaWeblog.editPost',
|
50
|
+
98, blog.username, blog.password,
|
51
|
+
valid_wp_post_options, true)
|
52
|
+
blog.edit_post(98, valid_wp_post_options, true)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should make xmlrpc calls to metaWeblog.editPost with published = false" do
|
56
|
+
blog = a_wp_blog
|
57
|
+
blog.send(:xmlrpc).should_receive(:call).once.with('metaWeblog.editPost',
|
58
|
+
98, blog.username, blog.password,
|
59
|
+
valid_wp_post_options, false)
|
60
|
+
blog.edit_post(98, valid_wp_post_options, false)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "new_post" do
|
67
|
+
it "should make metaWeblog.newPost calls with no published arg by default" do
|
68
|
+
blog = a_wp_blog
|
69
|
+
blog.send(:xmlrpc).should_receive(:call).once.with('metaWeblog.newPost',
|
70
|
+
blog.blog_id, blog.username, blog.password,
|
71
|
+
valid_wp_post_options)
|
72
|
+
blog.new_post(valid_wp_post_options)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should make metaWeblog.newPost calls with published = true" do
|
76
|
+
blog = a_wp_blog
|
77
|
+
blog.send(:xmlrpc).should_receive(:call).once.with('metaWeblog.newPost',
|
78
|
+
blog.blog_id, blog.username, blog.password,
|
79
|
+
valid_wp_post_options, true)
|
80
|
+
blog.new_post(valid_wp_post_options, true)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should make metaWeblog.newPost calls with published = false" do
|
84
|
+
blog = a_wp_blog
|
85
|
+
blog.send(:xmlrpc).should_receive(:call).once.with('metaWeblog.newPost',
|
86
|
+
blog.blog_id, blog.username, blog.password,
|
87
|
+
valid_wp_post_options, false)
|
88
|
+
blog.new_post(valid_wp_post_options, false)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "upload_file" do
|
94
|
+
it "should make wp.uploadFile calls" do
|
95
|
+
blog = a_wp_blog
|
96
|
+
xmlrpc_valid_wp_upload_options = valid_wp_upload_options.merge({
|
97
|
+
:bits => XMLRPC::Base64.new(valid_wp_upload_options[:bits])
|
98
|
+
})
|
99
|
+
blog.send(:xmlrpc).should_receive(:call).once.with('wp.uploadFile', blog.blog_id, blog.username,
|
100
|
+
blog.password,
|
101
|
+
hash_including({
|
102
|
+
:name => valid_wp_upload_options[:name],
|
103
|
+
:type => valid_wp_upload_options[:type],
|
104
|
+
:overwrite => valid_wp_upload_options[:overwrite],
|
105
|
+
:bits => an_instance_of(XMLRPC::Base64)
|
106
|
+
}))
|
107
|
+
args = [:name, :type, :bits, :overwrite].collect { |k| valid_wp_upload_options[k] }
|
108
|
+
blog.upload_file(*args)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return a CategoryCollection" do
|
113
|
+
blog = a_wp_blog
|
114
|
+
blog.categories.should be_a_kind_of Collection::Categories
|
115
|
+
blog.categories.conn.should == blog
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe Collection::Categories do
|
4
|
+
it "should retrieve categories via xmlrpc" do
|
5
|
+
blog = a_wp_blog
|
6
|
+
blog.xmlrpc.should_receive(:call).once.with('wp.getCategories', blog.blog_id, blog.username, blog.password).and_return([{}, {}, {}])
|
7
|
+
cats = blog.categories.load
|
8
|
+
cats.size.should == 3
|
9
|
+
cats.first.should be_a_kind_of Category
|
10
|
+
cats.first.conn.should == blog
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe Category do
|
4
|
+
describe "create" do
|
5
|
+
it "should call wp.newCategory" do
|
6
|
+
blog = a_wp_blog
|
7
|
+
blog.xmlrpc.should_receive(:call).once.with('wp.newCategory', blog.blog_id, blog.username, blog.password,
|
8
|
+
hash_including("name" => valid_category_options[:name])).and_return(10)
|
9
|
+
blog.categories.create valid_category_options
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return a Category instance with the right id" do
|
13
|
+
blog = a_wp_blog
|
14
|
+
blog.xmlrpc.should_receive(:call).once.and_return(10)
|
15
|
+
blog.categories.create(valid_category_options).id.should == 10
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should generate a slug from the title if not provided" do
|
20
|
+
Category.new(:name => "Blog Posts ").slug.should == "blog-posts"
|
21
|
+
Category.new(:name => "Blog Posts", :slug => 'posts').slug.should == "posts"
|
22
|
+
Category.new(:name => nil).slug.should be_empty
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
ROOT_PATH = File.join(File.dirname(__FILE__), '..')
|
2
|
+
$:.unshift ROOT_PATH unless $:.include? ROOT_PATH
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'lib/wp_rpc.rb'
|
6
|
+
include WpRpc
|
7
|
+
|
8
|
+
def valid_wp_blog_options
|
9
|
+
{ :username => 'lily', :password => 'lilybeans', :url => 'http://example.com', :blog_id => 666 }
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid_wp_post_options
|
13
|
+
{ :title => "Test Post", :description => "The text of the post", :dateCreated => Time.at(1284243726),
|
14
|
+
:mt_keywords => 'test,post,example', :categories => 'blog' }
|
15
|
+
end
|
16
|
+
|
17
|
+
def a_wp_blog
|
18
|
+
Blog.new(valid_wp_blog_options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_wp_upload_options
|
22
|
+
{ :name => "A file", :type => "application/octet-stream",
|
23
|
+
:bits => "12345678910", :overwrite => false }
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid_category_options
|
27
|
+
{ :name => 'Posts', :slug => 'posts', :parent_id => nil, :description => "Blog posts" }
|
28
|
+
end
|
data/wp_rpc.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/wp_rpc/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alex Ferreira"]
|
6
|
+
gem.email = ["alex@dsol.com.br"]
|
7
|
+
gem.description = "A Ruby library to interact with the Wordpress XMLRPC interface"
|
8
|
+
gem.summary = "A Ruby library to interact with the Wordpress XMLRPC interface"
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "wp_rpc"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.version = WpRpc::VERSION
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wp_rpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alex Ferreira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Ruby library to interact with the Wordpress XMLRPC interface
|
15
|
+
email:
|
16
|
+
- alex@dsol.com.br
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rspec
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/wp_rpc.rb
|
28
|
+
- lib/wp_rpc/attachment.rb
|
29
|
+
- lib/wp_rpc/base.rb
|
30
|
+
- lib/wp_rpc/blog.rb
|
31
|
+
- lib/wp_rpc/category.rb
|
32
|
+
- lib/wp_rpc/collections/attachments.rb
|
33
|
+
- lib/wp_rpc/collections/categories.rb
|
34
|
+
- lib/wp_rpc/collections/posts.rb
|
35
|
+
- lib/wp_rpc/post.rb
|
36
|
+
- lib/wp_rpc/version.rb
|
37
|
+
- spec/blog_spec.rb
|
38
|
+
- spec/category_collection_spec.rb
|
39
|
+
- spec/category_spec.rb
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
- wp_rpc.gemspec
|
42
|
+
homepage: ''
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.24
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: A Ruby library to interact with the Wordpress XMLRPC interface
|
66
|
+
test_files:
|
67
|
+
- spec/blog_spec.rb
|
68
|
+
- spec/category_collection_spec.rb
|
69
|
+
- spec/category_spec.rb
|
70
|
+
- spec/spec_helper.rb
|