Class: Ipodcastly::Server::Podcast

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ipodcastly/server/podcast.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, title, url) ⇒ Podcast

Returns a new instance of Podcast.



10
11
12
13
14
# File 'lib/ipodcastly/server/podcast.rb', line 10

def initialize(id, title, url)
  @id = id
  @title = title
  @url = url
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/ipodcastly/server/podcast.rb', line 8

def id
  @id
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/ipodcastly/server/podcast.rb', line 8

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/ipodcastly/server/podcast.rb', line 8

def url
  @url
end

Class Method Details

.allObject



26
27
28
29
30
31
32
33
34
# File 'lib/ipodcastly/server/podcast.rb', line 26

def self.all
  response = get('/podcasts.json')

  if response.code == 200
    response.map { |p| new(p['id'], p['title'], p['url']) }
  else
    []
  end
end

.find_by_title(title) ⇒ Object



36
37
38
# File 'lib/ipodcastly/server/podcast.rb', line 36

def self.find_by_title(title)
  all.detect { |p| p.title == title }
end

Instance Method Details

#episodesObject



16
17
18
19
20
21
22
23
24
# File 'lib/ipodcastly/server/podcast.rb', line 16

def episodes
  response = self.class.get("/episodes.json?podcast_id=#{id}")

  if response.code == 200
    response.map { |e| Episode.new(e['id'], id, e['title'], e['position'], e['duration']) }
  else
    []
  end
end