zachfeldman / rubypress Goto Github PK
View Code? Open in Web Editor NEWThis project forked from djcp/ruby-wordpress-api
Ruby interface for the WordPress XMLRPC API. Follows standard XML-RPC Documentation closely.
This project forked from djcp/ruby-wordpress-api
Ruby interface for the WordPress XMLRPC API. Follows standard XML-RPC Documentation closely.
I've been repeatedly trying to post on Wordpress blogs while setting it's categories but it doesn't seem to work.
Whenever I send something like this
# After authentication, of course
blog.newPost(:content => {
:post_title => "title",
:post_content => "content"
},
:terms_names => {
:category => ["category"]
})
I've seen several examples on how to do it, and they all point to that structure.
I've tried changing :category
to a hash; sending a single category as a string; making sure that this specific category
exists; and none worked - the post always get published as Uncategorized
.
Is this really the right Ruby idiom to use when posting with rubypress
?
I am not getting any method to get all categories.
Currently Comments
, Media
, Options
, Posts
, Taxonomies
, and Users
modules are at the top level. They should be namespaced to prevent conflicts with other modules (especially in ruby on rails applications).
Rubypress::Comments
, Rubypress::Options
, ... and so on.
currently I get a "SocketError: getaddrinfo: Name or service not known" error if I try to connect to a wordpress site running at website.com/blog instead of website.com because the client only takes a host rather than a url as parameters -- would this be difficult for you to fix?
I am getting the following error on Windows 7. Any idea how to fix this? Thanks.
C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/rubypress-1.0.7/lib/rubypress/xml_rpc_r
etryable.rb:7:in <module:XMLRPCRetryable>': uninitialized constant Net::ReadTim eout (NameError) from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/rubypress-1.0.7/lib/rubypr ess/xml_rpc_retryable.rb:2:in
module:Rubypress'
from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/rubypress-1.0.7/lib/rubypr
ess/xml_rpc_retryable.rb:1:in <top (required)>' from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/rubypress-1.0.7/lib/rubypr ess/client.rb:11:in
require_relative'
from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/rubypress-1.0.7/lib/rubypr
ess/client.rb:11:in <top (required)>' from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/rubypress-1.0.7/lib/rubypr ess.rb:4:in
<top (required)>'
from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/
runtime.rb:72:in require' from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/ runtime.rb:72:in
block (2 levels) in require'
from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/
runtime.rb:70:in each' from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/ runtime.rb:70:in
block in require'
from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/
runtime.rb:59:in each' from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/ runtime.rb:59:in
require'
from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler.
rb:132:in require' from D:/Eclipse2/overheid_upgrade/config/application.rb:8:in
<top (requ
ired)>'
from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.18/lib/rails/
commands/runner.rb:43:in require' from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.18/lib/rails/ commands/runner.rb:43:in
<top (required)>'
from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.18/lib/rails/
commands.rb:64:in require' from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.18/lib/rails/ commands.rb:64:in
<top (required)>'
from script/rails:6:in require' from script/rails:6:in
Edit: Nevermind, I was mistyping something. ๐
Hi, in the readme it says
Returns the newly created posts ID if successful
about newPost. I need to test the return so I can do some things only in case the post was successfully created, but I'm having a hard time trying to create an error on purpose. Turns out it's pretty resilient, it creates the post even when I put nonsense into the parameters. So, what does it return when the post isn't created? An Exception? A string with the HTTP error?
/usr/local/rvm/gems/ruby-2.3.0/gems/xmlrpc-0.3.0/lib/xmlrpc/client.rb:272:in call': A name is required for this term. (XMLRPC::FaultException) from /usr/local/rvm/gems/ruby-2.3.0/gems/rubypress-1.2.2/lib/rubypress/client.rb:70:in
execute'
from /usr/local/rvm/gems/ruby-2.3.0/gems/rubypress-1.2.2/lib/rubypress/posts.rb:29:in newPost' from run_program.rb:56:in
post_to_wp'
from run_program.rb:84:in `
I am getting the above error any suggestion?
Hi all,
I have problem when set up sensitive data to .env
file. I got error below:
/usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/net/http.rb:906:in
'rescue in block in connect': Failed to open TCP connection to localhost:80 (Connection refused - connect(2) for "localhost" port 80) (Errno::ECONNREFUSED) from /usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/net/http.rb:903:in
block in connect'
from /usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/timeout.rb:93:inblock in timeout' from /usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/timeout.rb:103:in
timeout'
from /usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/net/http.rb:902:inconnect' from /usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/net/http.rb:887:in
do_start'
from /usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/net/http.rb:882:instart' from /usr/local/lib/ruby/gems/2.4.0/gems/xmlrpc-0.3.0/lib/xmlrpc/client.rb:495:in
do_rpc'
from /usr/local/lib/ruby/gems/2.4.0/gems/xmlrpc-0.3.0/lib/xmlrpc/client.rb:287:incall2' from /usr/local/lib/ruby/gems/2.4.0/gems/xmlrpc-0.3.0/lib/xmlrpc/client.rb:268:in
call'
from /usr/local/lib/ruby/gems/2.4.0/gems/rubypress-1.2.2/lib/rubypress/client.rb:70:inexecute' from /usr/local/lib/ruby/gems/2.4.0/gems/rubypress-1.2.2/lib/rubypress/posts.rb:29:in
newPost'
from getChapter.rb:20:inpostToDB' from getChapter.rb:40:in
When i use "wp.newComment" at that time i revived this error. Using "wp.newComment" comment is created but it does not gives response it's take time after some time it gives error. "Error: 409:Duplicate comment detected; it looks as though youโve already said that!"
My code snipped is like this.
begin
result = @wp.newComment(:blog_id => 0, # 0 unless using WP Multi-Site, then use the blog id
:username => UserName,
:password => Password,
:post_id => PostId,
:comment => {
:comment_parent => 0,
:content => content,
:author => AuthorName,
:author_url =>URL,
:author_email => AuthorEmail
}
)
rescue XMLRPC::FaultException => e
puts "Error: #{e.faultCode}:#{e.faultString}"
endGive me Reply ASAP.
Thanks.
Calling
wp = Rubypress::Client.new(:host => "example.com", :username => "[email protected]", :password => "???", use_ssl: true)
Will result in the following error:
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
Unless port 443 is specified in the options. It's obvious how to fix this error, as this isn't in the documentation, so should probably default to port 443 to avoid this error.
The existing getPostStatusList calls getPostFormats instead.
A lot of WordPress blogs use self-signed SSL certs. If you try to connect to them with this library you get the following error:
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
It would be great if there was an option to set the SSL verify mode. This needs to be set on the Net::HTTP instance by setting verify_mode = OpenSSL::SSL::VERIFY_NONE
The problem right now is that since @connection is not memoized I can't find a way to set this option on the Net::HTTP instance since each time a call is made, a new @connection variable is set.
One option would be to memoize the @connection variable or adding an option to skip ssl verification.
Just to signal that since ruby 2.4.0 we now need gem 'xmlrpc' to this work, maybe require it automatically ?
How can I go about caching the result of wp.getPosts
. My Wordpress Installation is hosted on a really slow server (Azure ergh) and loading in my most recent posts is affecting the speed of my lovely speedy Rails app! (Apologies, I'm a .NET dev)
Hello, I am using this gem I am trying to upload media file, Obviously I am using uploadFile and my user in WordPress have permissions. I am using this code(get from spec)
wp.uploadFile(:data => {:id => "", :name => "test_file.png", :bits => '"\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\b\x03\x00\x00\x00\xBA\xEC?\x8F\x00\x00\x00\x19tEXtSoftware\x00Adobe ImageReadyq\xC9e<\x00\x00\x00\fPLTE\xAC\xAC\xAC\x87\x87\x87aaa\xFF\xFF\xFF\xF2\xB3\r\x90\x00\x00\x00\x04tRNS\xFF\xFF\xFF\x00@*\xA9\xF4\x00\x00\x004IDATx\xDAl\x8D1\x12\x00 \f\xC2\x02\xFE\xFF\xCF\x82\x0Eu0\x03\x97r\xD7\x96U\xDC\xE0\x98;\xE1@\xDB$ \xA7\xACJ\x1F\xD5h\xD0]{\x8E\xCD\x8B-\xC0\x00/\x88\x00\xDF$\xC9\x85\\\x00\x00\x00\x00IEND\xAEB`\x82"'})
I have tried this also:
FILENAME = '/tmp/image.jpg'
f = File.new(FILENAME, 'rb').read
wp.uploadFile(:data => {:name => 'image.jpg',
:type => MIME::Types.type_for(FILENAME).first.to_s,
:bits => f
})
These images are uploaded but it is not valid images. How should I upload media?. Thanks
EDIT: I fix this, thanks and sorry
Hi,
Is there a reason why WP.getPosts(blog_id: blog_id)
won't list me posts from that specific blog_id
but only posts from default website (the root website without subdomain)?
Thanks
@wordpress = Rubypress::Client.new(:host => ENV['WOO_URL'].split('//').last,
:username => ENV['WOO_USERNAME'],
:password => ENV['WOO_PASSWORD'],
:use_ssl => true,
:debug => true)
=> #<Rubypress::Client:0x007f84f33e3bc0 @port=80, @ssl_port=443, @use_ssl=true, @host="website.com", @path="/xmlrpc.php", @username="xxxxx", @password="xxxxx", @default_post_fields=["post", "terms", "custom_fields"], @debug=true, @http_user=nil, @http_password=nil, @retry_timeouts=false, @timeout=30, @cookie=nil>
> @wordpress.getOptions
opening connection to website.com:443...
opened
starting SSL for website.com:443...
SSL established
<- "POST /xmlrpc.php HTTP/1.1\r\nUser-Agent: XMLRPC::Client (Ruby 2.3.3)\r\nContent-Type: text/xml; charset=utf-8\r\nContent-Length: 304\r\nConnection: keep-alive\r\nAccept-Encoding: identity\r\nAccept: */*\r\nHost: easternspree.com\r\n\r\n"
<- "<?xml version=\"1.0\" ?><methodCall><methodName>wp.getOptions</methodName><params><param><value><array><data><value><i4>0</i4></value><value><string>xxxxx</string></value><value><string>xxxxxx</string></value><value><array><data/></array></value></data></array></value></param></params></methodCall>\n"
-> "HTTP/1.1 301 Moved Permanently\r\n"
-> "Date: Sat, 29 Dec 2018 04:57:25 GMT\r\n"
-> "Server: Apache/2.4.29 (Ubuntu)\r\n"
-> "Location: https://website.com/\r\n"
-> "Content-Length: 316\r\n"
-> "Keep-Alive: timeout=5, max=100\r\n"
-> "Connection: Keep-Alive\r\n"
-> "Content-Type: text/html; charset=iso-8859-1\r\n"
-> "\r\n"
reading 316 bytes...
-> "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>301 Moved Permanently</title>\n</head><body>\n<h1>Moved Permanently</h1>\n<p>The document has moved <a href=\"https://website.com/\">here</a>.</p>\n<hr>\n<address>Apache/2.4.29 (Ubuntu) Server at website.com Port 443</address>\n</body></html>\n"
read 316 bytes
Conn keep-alive
RuntimeError: HTTP-Error: 301 Moved Permanently
from (irb):138
It seems like the request is going to http://website.com and not https://website.com, which is getting redirected to https://website.com. It seems like others had similar problems and they were able to solve it by including https:// in the url, but adding https:// in the host setting will result in invalid URL.
When I am calling getPosts method its only fetched 10 records.
When client.getPosts
would result in the wordpress hosting server consume more memory than currently allowed by its php-configuration, it will respond with a 500 Internal Server Error.
What I've done in my code is to accumulate all Posts, by fetching it in batches (parameters number
and offset
).
I'd understand if this does not fall into rubypress's responsibilities from a maintainers point of view - rubypress is a pure XML-wrapper without an additional big convenience layer on top afaict. And its doing its job great btw!
Feel free to close this issue if such functionality is not "welcome" here. Otherwise we could start speaking about implementation details.
I keep getting this error `module:XMLRPCRetryable': uninitialized constant Net::ReadTimeout (NameError) .. please can you help.
/usr/local/share/gems1.9/gems/rubypress-1.0.7/lib/rubypress/xml_rpc_retryable.rb:7:in `module:XMLRPCRetryable': uninitialized constant
Net::ReadTimeout (NameError)
from /usr/local/share/gems1.9/gems/rubypress-1.0.7/lib/rubypress/xml_rpc_retryable.rb:2:in <module:Rubypress>' from /usr/local/share/gems1.9/gems/rubypress-1.0.7/lib/rubypress/xml_rpc_retryable.rb:1:in
<top (required)>'
from /usr/local/share/gems1.9/gems/rubypress-1.0.7/lib/rubypress/client.rb:11:in require_relative' from /usr/local/share/gems1.9/gems/rubypress-1.0.7/lib/rubypress/client.rb:11:in
<top (required)>'
from /usr/share/rubygems1.9/rubygems/custom_require.rb:36:in require' from /usr/share/rubygems1.9/rubygems/custom_require.rb:36:in
require'
from /usr/local/share/gems1.9/gems/rubypress-1.0.7/lib/rubypress.rb:4:in <top (required)>' from /usr/share/rubygems1.9/rubygems/custom_require.rb:60:in
require'
from /usr/share/rubygems1.9/rubygems/custom_require.rb:60:in rescue in require' from /usr/share/rubygems1.9/rubygems/custom_require.rb:35:in
require'
from generate_wordpress_data.rb:1:in `
Hiya!
Sorry for bothering, but when I try connecting to a host with slashes inside, it gives a SocketError: getaddrinfo: Name or service not known.
For example, :host => "mysite.com/blog/path/"
fails
Apparently it works when I send it as
:host => "mysite.com", path => "/blog/path/xmlrpc.php"
Could you specify this behavior on README or such?
The following error occurs when using ruby 1.9.3 however the version constraint in the gemspec is s.required_ruby_version = '>= 1.9.2'
.
/Users/brian.fletcher/.rvm/gems/ruby-1.9.3-p545@brian/gems/rubypress-1.0.7/lib/rubypress/xml_rpc_retryable.rb:7:in `<module:XMLRPCRetryable>': uninitialized constant Net::ReadTimeout (NameError)
from /Users/brian.fletcher/.rvm/gems/ruby-1.9.3-p545@brian/gems/rubypress-1.0.7/lib/rubypress/xml_rpc_retryable.rb:2:in `<module:Rubypress>'
from /Users/brian.fletcher/.rvm/gems/ruby-1.9.3-p545@brian/gems/rubypress-1.0.7/lib/rubypress/xml_rpc_retryable.rb:1:in `<top (required)>'
from /Users/brian.fletcher/.rvm/gems/ruby-1.9.3-p545@brian/gems/rubypress-1.0.7/lib/rubypress/client.rb:11:in `require_relative'
from /Users/brian.fletcher/.rvm/gems/ruby-1.9.3-p545@brian/gems/rubypress-1.0.7/lib/rubypress/client.rb:11:in `<top (required)>'
from /Users/brian.fletcher/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/brian.fletcher/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/brian.fletcher/.rvm/gems/ruby-1.9.3-p545@brian/gems/rubypress-1.0.7/lib/rubypress.rb:4:in `<top (required)>'
from /Users/brian.fletcher/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:135:in `require'
from /Users/brian.fletcher/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /Users/brian.fletcher/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:144:in `require'
from asddf.rb:3:in `<main>'
I am working on a project for someone where from a rails application I will make posts to a wordpress blog.
She has given me an account on the website that can make posts but does not have full admin access.
I can do the following command without issue:
wp = Rubypress::Client.new(:host => "dulfy.net", :username => "blah", :password => "blah")
This works returning a rubypress client.
I am not doing @dulfy.net for the username
If I try to do
wp,getOptions
I get
"RuntimeError: HTTP-Error: 403 Forbidden"
Apparently she uses XMLRPC for something else and it is enabled and working.
I am not sure if there are other things she needs to do to allow me to post remotely or if I am doing something wrong.
Edit:
I just heard back. She uses a tool called "livewriter" which communicates through XMLRPC. She said that she remembers using all of the default settings.
I tried adding ":use_ssl => true" to the Client.new. After doing that when I do anything I get
"OpenSSL:SSL:SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"
RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.
via e.g.
spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']
Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.
There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.
I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!
Appendix:
If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies
p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.
All of the client code supports SSL/HTTPS, but the spec helper does not read enough settings from the environment to allow testing against HTTPS hosts.
Reading from WORDPRESS_PORT
and WORDPRESS_USE_SSL
and defaulting to the current literals preserves the current behavior while allowing tests to run against HTTPS servers.
Trying to use the gem with a free blog hosted at wordpress.com domain, I get an error for code 301 Moved Permanently. The same occurs for http code 302.
I currently try to create new wordpress posts with metadata as described here: https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/new/
Array of metadata objects containing the following properties:
key
(metadata key),id
(meta ID),previous_value
(if set, the action will only occur for the provided previous value),value
(the new value to set the meta to),operation
(the operation to perform:update
oradd
; defaults toupdate
). All unprotected meta keys are available by default for read requests. Both unprotected and protected meta keys are avaiable for authenticated requests with proper capabilities. Protected meta keys can be made available with the rest_api_allowed_public_metadata filter.
It uses the wordpress custom fields: https://codex.wordpress.org/Custom_Fields
However I do not know how to do that with rubypress.
wp.newPost( :blog_id => "0", # 0 unless using WP Multi-Site, then use the blog id
:content => {
:post_status => "draft",
:post_date => entry.published,
:post_content => entry.content,
:post_title => entry.title,
:post_name => post_name,
:post_type => "podcast",
:post_author => 1
:metadata => [] # what do I have to write here?
}
)
Can you tell me how to do that? Is that even possible with rubypress? I do not understand how wordpress wants the "objects" to be encoded.
The Client uses an unconditional prefix of "wp." to simplify the calls and because all of the standard API includes it. However, custom additions that do not start with this prefix cannot be called without overriding the entirety of the execute method.
A straightforward technique to retain the sane default behavior and allow custom methods to be called is to check whether the method called contains a dot and only apply the prefix if not, allowing literal method names to pass through unmodified.
I was wondering if someone can add an example of how to pass options through the gem. I know with wp.getOptions we can list all of them but if I try for example the following nothing is returned:
options = {
media: {
:thumbnail_size_w => 291,
:thumbnail_size_h => 194,
}
}
Please note I have tried it without the media wrapper as well to no avail. I know you can use the filtering via this which works:
options = {
:filter => {
:order => 'desc',
},
}
So the above leads me to believe I am very close but missing something. Any suggestions? Also it would be good to add this to the docs IMO.
Hey, I had to take down my wordpress mirrors as a test host as I was getting quite a few attacks on my server. If someone else is willing to volunteer we can still use Travis, otherwise tests will have to be run locally.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.