Skip to content

Commit

Permalink
Change to new posterous API
Browse files Browse the repository at this point in the history
  • Loading branch information
alagu committed Sep 16, 2011
1 parent 72b7b1f commit ddd5dbb
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/jekyll/migrators/posterous.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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?
Expand All @@ -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
Expand Down

0 comments on commit ddd5dbb

Please sign in to comment.