Sha256: f9768e0c3ee58e57e4750da373631a9a3a36a3ffd66d932ced35d4fd5a43e14c

Contents?: true

Size: 941 Bytes

Versions: 11

Compression:

Stored size: 941 Bytes

Contents

module AppleNews
  class Channel
    include Resource
    include Links

    attr_reader :id, :type, :name, :website, :links, :created_at, :modified_at,
                :default_section, :share_url

    def self.current
      self.new(AppleNews.config.channel_id)
    end

    def initialize(id, data = nil)
      @id = id
      @resource_path = "/channels"

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

    def default_section
      Section.new(section_link_id('defaultSection'))
    end

    def sections
      request = Request::Get.new("/channels/#{id}/sections")
      resp = request.call
      resp['data'].map do |section|
        Section.new(section['id'], section)
      end
    end

    def articles(params = {})
      request = Request::Get.new("/channels/#{id}/articles")
      resp = request.call(params)
      resp['data'].map do |article|
        Article.new(article['id'])
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
apple-news-0.4.2 lib/apple-news/channel.rb
apple-news-0.4.1 lib/apple-news/channel.rb
apple-news-0.4.0 lib/apple-news/channel.rb
apple-news-0.3.1 lib/apple-news/channel.rb
apple-news-0.3.0 lib/apple-news/channel.rb
apple-news-0.2.5 lib/apple-news/channel.rb
apple-news-0.2.4 lib/apple-news/channel.rb
apple-news-0.2.3 lib/apple-news/channel.rb
apple-news-0.2.2 lib/apple-news/channel.rb
apple-news-0.2.1 lib/apple-news/channel.rb
apple-news-0.2.0 lib/apple-news/channel.rb