Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change to new posterous API

  • Loading branch information...
commit ddd5dbb5fbf956909f792b2aba1c721b2cca9b56 1 parent 72b7b1f
@alagu authored
Showing with 14 additions and 8 deletions.
  1. +14 −8 lib/jekyll/migrators/posterous.rb
View
22 lib/jekyll/migrators/posterous.rb
@@ -1,11 +1,14 @@
require 'rubygems'
require 'jekyll'
require 'fileutils'
-require 'net/http'
+require 'net/https'
+require 'open-uri'
require 'uri'
require "json"
-# ruby -r './lib/jekyll/migrators/posterous.rb' -e 'Jekyll::Posterous.process(email, pass, blog)'
+# ruby -r './lib/jekyll/migrators/posterous.rb' -e 'Jekyll::Posterous.process(email, pass, api_token, blog)'
+# You can find your api token in posterous api page - http://posterous.com/api . Click on any of the 'view token' links to see your token.
+# blog is optional, by default it is the primary one
module Jekyll
module Posterous
@@ -14,6 +17,9 @@ def self.fetch(uri_str, limit = 10)
raise ArgumentError, 'Stuck in a redirect loop. Please double check your email and password' if limit == 0
response = nil
+
+ puts uri_str
+ puts '-------'
Net::HTTP.start('posterous.com') do |http|
req = Net::HTTP::Get.new(uri_str)
req.basic_auth @email, @pass
@@ -27,12 +33,11 @@ def self.fetch(uri_str, limit = 10)
end
end
- def self.process(email, pass, blog = 'primary')
- @email, @pass = email, pass
- @api_token = JSON.parse(self.fetch("/api/2/auth/token").body)['api_token']
+ def self.process(email, pass, api_token, blog = 'primary')
+ @email, @pass , @api_token = email, pass, api_token
FileUtils.mkdir_p "_posts"
- posts = JSON.parse(self.fetch("/api/v2/users/me/sites/#{blog}/posts?api_token=#{@api_token}").body)
+ posts = JSON.parse(self.fetch("/api/2/sites/#{blog}/posts?api_token=#{@api_token}").body)
page = 1
while posts.any?
@@ -54,14 +59,15 @@ def self.process(email, pass, blog = 'primary')
# Write out the data and content to file
File.open("_posts/#{name}", "w") do |f|
- f.puts data
+ puts name
+ f.puts name
f.puts "---"
f.puts content
end
end
page += 1
- posts = JSON.parse(self.fetch("/api/v2/users/me/sites/#{blog}/posts?api_token=#{@api_token}&page=#{page}").body)
+ posts = JSON.parse(self.fetch("/api/2/sites/#{blog}/posts?api_token=#{@api_token}&page=#{page}").body)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.