Class: WCC::Blogs::Collection

Inherits:
Object
  • Object
show all
Extended by:
Utils
Includes:
WCC::Blogs::Concerns::Caching
Defined in:
lib/wcc/blogs/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

camelcase, define_camelcase_alias

Methods included from WCC::Blogs::Concerns::Caching

#cache_key, #cache_key_with_version, #cache_version

Constructor Details

#initialize(raw, client: WCC::Blogs.client) ⇒ Collection

Returns a new instance of Collection.



16
17
18
19
# File 'lib/wcc/blogs/collection.rb', line 16

def initialize(raw, client: WCC::Blogs.client)
  @raw = raw
  @client = client
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



14
15
16
# File 'lib/wcc/blogs/collection.rb', line 14

def raw
  @raw
end

Class Method Details

.find(key = nil, client: WCC::Blogs.client) ⇒ Object



10
11
12
# File 'lib/wcc/blogs/collection.rb', line 10

def self.find(key = nil, client: WCC::Blogs.client)
  new(client.collection_show(key).raw, client: client)
end

Instance Method Details



47
48
49
# File 'lib/wcc/blogs/collection.rb', line 47

def _links
  OpenStruct.new(raw['_links'] || {})
end

#postsObject



40
41
42
43
44
45
# File 'lib/wcc/blogs/collection.rb', line 40

def posts
  @posts ||=
    (raw['posts'] || []).map do |summary|
      PostSummary.new(summary, client: @client)
    end
end

#to_paramObject



21
22
23
# File 'lib/wcc/blogs/collection.rb', line 21

def to_param
  key
end