class TumblrSync::Tumblr
Attributes
host[RW]
Public Class Methods
new(host)
click to toggle source
# File lib/tumblr-sync/tumblr.rb, line 12 def initialize(host) @host = host end
Public Instance Methods
images(start, number = MAX)
click to toggle source
# File lib/tumblr-sync/tumblr.rb, line 16 def images(start, number = MAX) response = Net::HTTP.get_response uri_endpoint(type: :photo, start: start, num: number) doc = Nokogiri::XML.parse response.body doc.xpath("//posts/post").map{|post| post.xpath(".//photo-url[@max-width='1280']").map { |url| url.text.strip }.uniq } end
times(&block)
click to toggle source
# File lib/tumblr-sync/tumblr.rb, line 28 def times(&block) (total.to_f / MAX + 0.5).round.times(&block) end
total()
click to toggle source
# File lib/tumblr-sync/tumblr.rb, line 22 def total response = Net::HTTP.get_response uri_endpoint(type: :photo) doc = Nokogiri::XML.parse response.body doc.xpath("//posts/@total").text.to_i end
Private Instance Methods
endpoint()
click to toggle source
# File lib/tumblr-sync/tumblr.rb, line 35 def endpoint "http://#{host}/api/read" end
uri_endpoint(params = {})
click to toggle source
# File lib/tumblr-sync/tumblr.rb, line 39 def uri_endpoint(params = {}) URI.parse(endpoint).tap do |uri| uri.query = URI.encode_www_form params end end