Change to new posterous API
This commit is contained in:
parent
72b7b1f056
commit
ddd5dbb5fb
|
@ -1,11 +1,14 @@
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'jekyll'
|
require 'jekyll'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'net/http'
|
require 'net/https'
|
||||||
|
require 'open-uri'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
require "json"
|
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 Jekyll
|
||||||
module Posterous
|
module Posterous
|
||||||
|
@ -14,6 +17,9 @@ module Jekyll
|
||||||
raise ArgumentError, 'Stuck in a redirect loop. Please double check your email and password' if limit == 0
|
raise ArgumentError, 'Stuck in a redirect loop. Please double check your email and password' if limit == 0
|
||||||
|
|
||||||
response = nil
|
response = nil
|
||||||
|
|
||||||
|
puts uri_str
|
||||||
|
puts '-------'
|
||||||
Net::HTTP.start('posterous.com') do |http|
|
Net::HTTP.start('posterous.com') do |http|
|
||||||
req = Net::HTTP::Get.new(uri_str)
|
req = Net::HTTP::Get.new(uri_str)
|
||||||
req.basic_auth @email, @pass
|
req.basic_auth @email, @pass
|
||||||
|
@ -27,12 +33,11 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.process(email, pass, blog = 'primary')
|
def self.process(email, pass, api_token, blog = 'primary')
|
||||||
@email, @pass = email, pass
|
@email, @pass , @api_token = email, pass, api_token
|
||||||
@api_token = JSON.parse(self.fetch("/api/2/auth/token").body)['api_token']
|
|
||||||
FileUtils.mkdir_p "_posts"
|
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
|
page = 1
|
||||||
|
|
||||||
while posts.any?
|
while posts.any?
|
||||||
|
@ -54,14 +59,15 @@ module Jekyll
|
||||||
|
|
||||||
# Write out the data and content to file
|
# Write out the data and content to file
|
||||||
File.open("_posts/#{name}", "w") do |f|
|
File.open("_posts/#{name}", "w") do |f|
|
||||||
f.puts data
|
puts name
|
||||||
|
f.puts name
|
||||||
f.puts "---"
|
f.puts "---"
|
||||||
f.puts content
|
f.puts content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
page += 1
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue