Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Getting real URL for Tumblr posts

  • Loading branch information...
commit e7608e4b5d25af3b37ffc51b7eecdcce6b051e5f 1 parent 5951dcd
myfreeweb authored committed
Showing with 10 additions and 3 deletions.
  1. +10 −3 Tumblr.dropzone
View
13 Tumblr.dropzone
@@ -12,12 +12,11 @@
# OptionsNIB: Login
# LoginTitle: Tumblr Login Details
-# TODO: Get the users tumblr url so that the url on pasteboard works
-
module Tumblr
class Api
require 'net/http'
require 'uri'
+ require 'rexml/document'
attr_accessor :form_data, :result_body
@@ -32,7 +31,7 @@ module Tumblr
self.add_form_data('type', type)
block.call(self)
- self.result_body = self.run_commands.body
+ self.result_body = self.get_url(self.run_commands.body)
end
def add_form_data(key, value)
@@ -46,6 +45,14 @@ module Tumblr
h = Net::HTTP.new(url.host, url.port)
return h.start {|http| http.request(req) }
end
+
+ def get_url(id)
+ url = URI.parse("http://www.tumblr.com/api/authenticate")
+ res = Net::HTTP.post_form(url, {'email' => ENV['USERNAME'], 'password' => ENV['PASSWORD']})
+ doc = REXML::Document.new(res.body)
+ blog = doc.root.elements["tumblelog[@is-primary='yes']"]
+ return "#{blog.attributes["url"]}post/#{id}"
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.