Class: AppleNews::Section

Inherits:
Object
  • Object
show all
Includes:
Links, Resource
Defined in:
lib/apple-news/section.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data = nil, config = AppleNews.config) ⇒ Section

Returns a new instance of Section.



8
9
10
11
12
13
14
# File 'lib/apple-news/section.rb', line 8

def initialize(id, data = nil, config = AppleNews.config)
  @id = id
  @config = config
  @resource_path = '/sections'

  data.nil? ? hydrate! : set_read_only_properties(data)
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



6
7
8
# File 'lib/apple-news/section.rb', line 6

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/apple-news/section.rb', line 6

def id
  @id
end

#is_defaultObject (readonly)

Returns the value of attribute is_default.



6
7
8
# File 'lib/apple-news/section.rb', line 6

def is_default
  @is_default
end

Returns the value of attribute links.



6
7
8
# File 'lib/apple-news/section.rb', line 6

def links
  @links
end

#modified_atObject (readonly)

Returns the value of attribute modified_at.



6
7
8
# File 'lib/apple-news/section.rb', line 6

def modified_at
  @modified_at
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/apple-news/section.rb', line 6

def name
  @name
end

#share_urlObject (readonly)

Returns the value of attribute share_url.



6
7
8
# File 'lib/apple-news/section.rb', line 6

def share_url
  @share_url
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/apple-news/section.rb', line 6

def type
  @type
end

Instance Method Details

#articles(params = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/apple-news/section.rb', line 20

def articles(params = {})
  params  = params.with_indifferent_access
  hydrate = params.delete(:hydrate)
  resp = get_request("/sections/#{id}/articles", params)
  resp['data'].map do |article|
    data = hydrate == false ? article : {}
    Article.new(article['id'], data, config)
  end
end

#channelObject



16
17
18
# File 'lib/apple-news/section.rb', line 16

def channel
  Channel.new(channel_link_id('channel'), nil, config)
end