Created
March 30, 2010 05:36
-
-
Save daveyeu/348798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tumblr | |
class << self | |
def email | |
credentials["email"] | |
end | |
def password | |
credentials["password"] | |
end | |
def credentials | |
@credentials ||= YAML.load(File.read("config/tumblr.yml")) | |
end | |
def common_data | |
{ | |
"email" => email, | |
"password" => password, | |
"type" => "regular" | |
} | |
end | |
def write(post) | |
data = { | |
"date" => post.created_on.strftime("%Y-%m-%d %H:%M:%S"), | |
"format" => "markdown", | |
"slug" => post.stub, | |
"title" => post.title, | |
"body" => post.content | |
}.merge(common_data) | |
res = Net::HTTP.post_form(URI.parse('http://www.tumblr.com/api/write'), data) | |
if res.is_a?(Net::HTTPSuccess) | |
res.body | |
else | |
puts "Failed to create #{post.id}/#{post.stub} -- #{res.code} #{res.message}" | |
false | |
end | |
end | |
def delete(tumblr_id) | |
res = Net::HTTP.post_form(URI.parse('http://www.tumblr.com/api/delete'), | |
common_data.merge({'post-id' => tumblr_id})) | |
if res.is_a?(Net::HTTPSuccess) | |
true | |
else | |
puts "Failed to delete #{tumblr_id} -- #{res.code} #{res.message}" | |
false | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment