Class: TumblrSync::Tumblr

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tumblr-sync/tumblr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Tumblr

Returns a new instance of Tumblr.



12
13
14
# File 'lib/tumblr-sync/tumblr.rb', line 12

def initialize(host)
  @host = host
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



10
11
12
# File 'lib/tumblr-sync/tumblr.rb', line 10

def host
  @host
end

Instance Method Details

#images(start, number = MAX) ⇒ Object



16
17
18
19
20
# 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/photo-url[@max-width='1280']").map { |url| url.text.strip }
end

#times(&block) ⇒ Object



28
29
30
# File 'lib/tumblr-sync/tumblr.rb', line 28

def times(&block)
  (total.to_f / MAX + 0.5).round.times(&block)
end

#totalObject



22
23
24
25
26
# 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