| Subcribe via RSS

Creating a new post in Wordpress using the JoeBlogs library

October 12th, 2009 | 5 Comments | Posted in Development

A few people have recently been asking how the NewPost method works within JoeBlogs

First, you need to create an instance of Post.

Then, set the following properties:

dateCreated
Fairly self explanatory, but you should set this to today’s date (or whatever date you wish the post to be set as published)

title
The title of the post

description
The body of the post.
This can of course contain HTML

categories
This is a string array of categories to associate with the post

mt_keywords
Another string array, representing the tags for the post

Then, using your presumably already instantiated Wrapper class, you can call the NewPost method, which takes the above Post object as a parameter, and a boolean – indicating if the post is to be set as published. Note – if this is set to false, the post is set in draft mode.

Here’s some sample code:

//create a new post
var post = new Post();

//since this is a struct, we can't have a constructor that does this!
post.dateCreated=DateTime.Now;
post.title="This is a title";
post.description="this is the body of the post. it <strong>could</strong> be html.";

//create the post!
wp.NewPost(post,true);

Hope this helps!

VN:F [1.8.2_1042]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.2_1042]
Rating: 0 (from 0 votes)
Tags: , ,

JoeBlogs – Typo in dummy URL fixed

August 31st, 2009 | 1 Comment | Posted in Development

I’ve recently had a few comments that the JoeBlogs wrapper wasn’t working – and they were getting an “invalid response” or more specifically “Response XML not valid XML-RPC – missing methodResponse element.”

It seems that I had a typo in my comments in JoeBlogs.TestHarness/Program.cs on line 15:

//typically http://www.yourdomain.com/xmlprc.php (if your wordpress blog is installed in root dir)

The problem, is the xmlprc.php – this should be xmlrpc.php.

Those of you that copy pasted / uncommented out that line, would be executing requests against a file that didn’t exist on your server!

I’ve changed this typo, and committed to Codeplex: revision #27138

Thanks to Felix for pointing this out!

VN:F [1.8.2_1042]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.2_1042]
Rating: 0 (from 0 votes)
Tags: ,

Using JoeBlogs -metaWeblog API Wrapper

July 7th, 2009 | 22 Comments | Posted in Blogging, Geek Speak, Web

Step 1

Download the latest release of JoeBlogs from Codeplex
(Click the Downloads tab, and select the latest download)

Step 2

Unzip the contents of the downloaded zip file.
(I usually copy DLLs I am going to use into a “lib” folder at the root of my solution)

Step 3


Add a reference to BOTH CookComputing.XmlRpcV2.dll AND JoeBlogs.dll

image

Include AlexJamesBrown.JoeBlogs in your class, with using / Imports:

C#

using AlexJamesBrown.JoeBlogs;

VB

Imports AlexJamesBrown.JoeBlogs

Step 4:

Instantiate a new Wrapper object.

So far, the available wrappers are:

MetaWeblogWrapper

WordPressWrapper

C#

WordPressWrapper wrapper = new WordPressWrapper(Url, Username, Password);

VB

Dim wrapper As New WordPressWrapper(Url, Username, Password)

Please note -

The above example has the Url, Username and Password strings omitted. Simply replace them with the relevant information.

Step 5

You can now take full advantage of all the methods on your instantiated wrapper.

C#

string Url = "www.alexjamesbrown.com";
string User = "MyUser"; //enter your username
string Password = "MyPassword"; //enter your password

var wp = new WordPressWrapper(Url, User, Password);

//a few test functions...
var userBlogs = wp.GetUserBlogs();
var tags = wp.GetTags();
var categories = wp.GetCategories();

var authors = wp.GetAuthors();
VN:F [1.8.2_1042]
Rating: 9.5/10 (6 votes cast)
VN:F [1.8.2_1042]
Rating: 0 (from 0 votes)
Tags: , , ,

Specify XML-RPC Endpoints at Run Time With CookComputing XMLRPC.net

July 6th, 2009 | 1 Comment | Posted in Uncategorized

A common question when using Cook Computing XML RPC.net to talk to blogs etc… is how to specify a blog / endpoint at runtime? Most of the examples seem to specify the details in an attribute… not much use if you’re trying to develop a wrapper.

To enable me to create JoeBlogs, I made use of the IXmlRpcProxy Proxy classes…

I created my interface, implementing IXmlRpcProxy:

We define the method as an XML RPC method using XmlRpcMethod.
The name of the method is also specified.
In this case, we are using getPost from the metaWeblog XML RPC API – Wordpress supports this, as well as the Blogger API and the Movable Type API.
They also have their own (which is an extension to the Moveable Type API) –

http://codex.wordpress.org/XML-RPC_wp

Anyway…..

As per the metaWeblog.getPost specification, we need to pass in the postid, username, and password. So we create our interface as follows:

	public interface IMyProxy: IXmlRpcProxy
	{
		[XmlRpcMethod("metaWeblog.getPost")]
		Post GetPost(string postid, string username, string password);
  	}

As we can see, this returns a “Post”

This is a struct, that basically defines the structure of the response.

	[XmlRpcMissingMapping(MappingAction.Ignore)]
	public struct Post
	{
		public DateTime dateCreated;
		public string description;
		public string title;
		public string postid;
		public string[] categories;

		public override string ToString()
		{
			return this.description;
		}
	}

To use this,  you need to create an instance of the proxy object.

XML RPC.net provides a method called XmlRpcProxyGen to do this for us.

We then set the Url, which is declared as part of IXmlRpcProxy (remember IMyProxy implemented this interface…)

Since our proxy declared the method GetPost, we can now use this, pass in the required post id, username and password.

    public void myTest()
    {
      string postId = "1234";
      string username = "myUsername";
      string password = "password";

      var proxy = (IMyProxy)XmlRpcProxyGen.Create(typeof(IMyProxy));
      proxy.Url = "www.alexjamesbrown.com";

      var post = proxy.GetPost(postId, username, password);
    }

And there we have it.

Of course this is a very bare bones example.

JoeBlogs contains much more separation of these concerns.

VN:F [1.8.2_1042]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.2_1042]
Rating: 0 (from 0 votes)
Tags: , , ,

C# WordPress Wrapper

May 22nd, 2009 | 5 Comments | Posted in Blogging, Geek Speak, Web

Ok, I’ve barely finished this as a stable release, but I thought I’d post this up any way….

A little open source project I’m working on – Joe Blogs.

In a nutshell, it allows easy communication to your WordPress (or other blog) via an xml-rpc interface.

Big thanks to the work by Charles Cook at http://www.xml-rpc.net/

Joe Blogs is currently hosted on CodePlex – http://joeblogs.codeplex.com/

I’ll be posting more info, tutorials, documentation etc… in the coming days and weeks.

Update

See here for usage instructions:
http://www.alexjamesbrown.com/geek/using-joeblogs/

VN:F [1.8.2_1042]
Rating: 10.0/10 (1 vote cast)
VN:F [1.8.2_1042]
Rating: 0 (from 0 votes)
Tags: , , , , ,