Skip to content

Instantly share code, notes, and snippets.

@mguterl
Created June 11, 2013 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mguterl/5759442 to your computer and use it in GitHub Desktop.
Save mguterl/5759442 to your computer and use it in GitHub Desktop.
require 'mechanize'
module TumblrGateway
class Blog
def initialize(base_url)
@base_url = base_url
end
def author_for(post_id)
PostPage.new(post_url_for(post_id)).author_name
end
private
def post_url_for(post_id)
URI.join(@base_url, 'post', post_id)
end
class PostPage
def initialize(url)
@url = url
end
def author_name
mechanize = Mechanize.new
page = mechanize.get(@url)
page.search(".authorname").text
end
end
end
end
blog = TumblrGateway::Blog.new('http://blog.gaslight.co')
blog.author_for('52640678160')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment