for cross-posting to OAuth-enabled Wordpress.com or Jetpack-enabled Wordpress.org blogs. Added model for Wordpress service Added very very basic Wordpress cross-posting functionality. Added markdown support to post body Fixed Wordpress::MAX_CHARACTERS problem cleanup Added default settings for Wordpress OAuth Added default settings for Wordpress OAuth Added Wordpress to configured services spec. changelog changes
32 lines
874 B
Ruby
32 lines
874 B
Ruby
class Services::Wordpress < Service
|
|
include ActionView::Helpers::TextHelper
|
|
include MarkdownifyHelper
|
|
|
|
MAX_CHARACTERS = 1000
|
|
|
|
attr_accessor :username, :password, :host, :path
|
|
|
|
# uid = blog_id
|
|
|
|
def provider
|
|
"wordpress"
|
|
end
|
|
|
|
def post(post, url='')
|
|
res = Faraday.new(:url => "https://public-api.wordpress.com").post do |req|
|
|
req.url "/rest/v1/sites/#{self.uid}/posts/new"
|
|
req.body = post_body(post).to_json
|
|
req.headers['Authorization'] = "Bearer #{self.access_token}"
|
|
req.headers['Content-Type'] = 'application/json'
|
|
end
|
|
JSON.parse res.env[:body]
|
|
end
|
|
|
|
def post_body(post, url='')
|
|
post_text = markdownify(post.text)
|
|
post_title = truncate(strip_markdown(post.text(:plain_text => true)), :length => 40, :separator => ' ')
|
|
|
|
{:title => post_title, :content => post_text.html_safe}
|
|
end
|
|
|
|
end
|