Module: Simplecast::Client::Statistic

Extended by:
Resource
Defined in:
lib/simplecast/client/statistic.rb

Instance Attribute Summary

Attributes included from Simplecast::Configurable

#api_key, #podcast_id

Class Method Summary collapse

Methods included from Resource

all, client, find, model, resource_plural_name_lower

Methods included from Simplecast::Configurable

#configure, keys, #options

Class Method Details

.all(podcast_id: nil) ⇒ Object



20
21
22
23
24
# File 'lib/simplecast/client/statistic.rb', line 20

def all(podcast_id: nil)
  podcast_id ||= client.podcast_id
  api_obj_array = client.get("podcasts/#{podcast_id}/statistics.json")
  api_obj_array.map {|api_obj| model.new(api_obj) }
end

.for_episode(episode_id, podcast_id: nil, opts: {}) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/simplecast/client/statistic.rb', line 7

def for_episode(episode_id, podcast_id: nil, opts: {})
  opts.merge!({episode_id: episode_id})
  podcast_id ||= client.podcast_id # TODO: || raise Simplecast::Error.new("Podcast ID must be supplied either in configuration or directly to the #for_episode method.")
  q = Hurley::Query::Flat.new(opts).to_query_string
  api_obj = client.get("podcasts/#{podcast_id}/statistics/episode.json?#{q}")
  model.new(api_obj)
end

.overall(podcast_id: nil, opts: { timeframe: "recent" }) ⇒ Object



14
15
16
17
18
19
# File 'lib/simplecast/client/statistic.rb', line 14

def overall(podcast_id: nil, opts: { timeframe: "recent" })
  podcast_id ||= client.podcast_id
  q = Hurley::Query::Flat.new(opts).to_query_string
  api_obj = client.get("podcasts/#{podcast_id}/statistics/overall.json?#{q}")
  model.new(api_obj)
end