Class: Posterous::Reader

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/posterous.rb

Overview

Posterous reader posterous.com/api/reading

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname = "", site_id = nil, num_posts = nil, page = nil, tag = nil) ⇒ Reader

Non-authenticated initialization

Raises:



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/posterous.rb', line 31

def initialize hostname = "", site_id = nil, num_posts = nil, page = nil, tag = nil
  raise AuthError, 'Either Site Id or Hostname must be supplied if not using authentication.' if \
    (hostname == "" && !site_id.is_a?(Integer)) || (!hostname.is_a?(String) && site_id == nil) 
  @site_id = site_id ? site_id.to_s : site_id
  @hostname = hostname
  @num_posts = num_posts ? num_posts.to_s : num_posts
  @page = page ? page.to_s : page
  @tag = tag ? tag.to_s : tag
  @response = read_posts
  self
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



28
29
30
# File 'lib/posterous.rb', line 28

def response
  @response
end

Instance Method Details

#build_queryObject



47
48
49
50
51
52
53
54
55
# File 'lib/posterous.rb', line 47

def build_query
  query   = { :site_id    => @site_id,
              :hostname   => @hostname,
              :num_posts  => @num_posts,
              :page       => @page,
              :tag        => @tag }
  query.delete_if { |k,v| !v }
  query
end

#read_postsObject



43
44
45
# File 'lib/posterous.rb', line 43

def read_posts
  self.class.get(READ_PATH, :query => build_query)["rsp"]["post"]
end