Class: Hypem::Blog

Inherits:
Object
  • Object
show all
Defined in:
lib/hypem/blog.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Blog

Returns a new instance of Blog.



7
8
9
10
11
# File 'lib/hypem/blog.rb', line 7

def initialize(*args)
  if args.count == 1
    @id = args.first.is_a?(Integer) ? args.first : args.first.to_i
  end
end

Instance Attribute Details

#blog_imageObject (readonly)

Returns the value of attribute blog_image.



3
4
5
# File 'lib/hypem/blog.rb', line 3

def blog_image
  @blog_image
end

#blog_image_smallObject (readonly)

Returns the value of attribute blog_image_small.



3
4
5
# File 'lib/hypem/blog.rb', line 3

def blog_image_small
  @blog_image_small
end

#first_postedObject (readonly)

Returns the value of attribute first_posted.



3
4
5
# File 'lib/hypem/blog.rb', line 3

def first_posted
  @first_posted
end

#followersObject (readonly)

Returns the value of attribute followers.



3
4
5
# File 'lib/hypem/blog.rb', line 3

def followers
  @followers
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/hypem/blog.rb', line 3

def id
  @id
end

#last_postedObject (readonly)

Returns the value of attribute last_posted.



3
4
5
# File 'lib/hypem/blog.rb', line 3

def last_posted
  @last_posted
end

#site_nameObject (readonly)

Returns the value of attribute site_name.



3
4
5
# File 'lib/hypem/blog.rb', line 3

def site_name
  @site_name
end

#site_urlObject (readonly)

Returns the value of attribute site_url.



3
4
5
# File 'lib/hypem/blog.rb', line 3

def site_url
  @site_url
end

#total_tracksObject (readonly)

Returns the value of attribute total_tracks.



3
4
5
# File 'lib/hypem/blog.rb', line 3

def total_tracks
  @total_tracks
end

Class Method Details

.allObject



37
38
39
40
# File 'lib/hypem/blog.rb', line 37

def self.all
  response = Request.new("/api/get_all_blogs").tap(&:get).response.body
  response.map { |b| self.new.tap {|blog| blog.update_from_response(b) } }
end

Instance Method Details

#get_infoObject



13
14
15
16
17
18
19
# File 'lib/hypem/blog.rb', line 13

def get_info
  unless @has_info
    response = Request.new("/api/get_site_info?siteid=#{@id}").tap(&:get).response.body
    update_from_response(response)
    @has_info = true
  end
end

#update_from_response(rsp) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hypem/blog.rb', line 21

def update_from_response(rsp)
  @id ||= rsp[:site_id]
  @blog_image ||= rsp['blog_image']
  @blog_image_small ||= rsp['blog_image_small']
  @followers ||= rsp['followers']
  @id ||= rsp['siteid']
  @site_name ||= rsp['sitename']
  @site_url ||= rsp['siteurl']
  @total_tracks ||= rsp['total_tracks']

  # only from get_info
  @first_posted ||= Time.at(rsp['first_posted']) unless rsp['first_posted'].nil?
  @last_posted ||= Time.at(rsp['last_posted']) unless rsp['last_posted'].nil?

end