Class: AppleNews::Channel

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Channel.



15
16
17
18
19
20
21
# File 'lib/apple-news/channel.rb', line 15

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

  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/channel.rb', line 6

def created_at
  @created_at
end

#default_sectionObject (readonly)

Returns the value of attribute default_section.



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

def default_section
  @default_section
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Returns the value of attribute links.



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

def links
  @links
end

#modified_atObject (readonly)

Returns the value of attribute modified_at.



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

def modified_at
  @modified_at
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#share_urlObject (readonly)

Returns the value of attribute share_url.



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

def share_url
  @share_url
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#websiteObject (readonly)

Returns the value of attribute website.



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

def website
  @website
end

Class Method Details

.currentObject



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

def self.current
  warn 'DEPRECATION WARNING: `AppleNews::Channel.current` is deprecated. '\
       'Please use `AppleNews.config.channel` instead.'
  AppleNews.config.channel
end

Instance Method Details

#articles(params = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/apple-news/channel.rb', line 34

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

#sectionsObject



27
28
29
30
31
32
# File 'lib/apple-news/channel.rb', line 27

def sections
  resp = get_request("/channels/#{id}/sections")
  resp['data'].map do |section|
    Section.new(section['id'], section, config)
  end
end