Class: Simplecast::Client

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/simplecast/client.rb,
lib/simplecast/client/episode.rb,
lib/simplecast/client/podcast.rb,
lib/simplecast/client/resource.rb,
lib/simplecast/client/statistic.rb

Defined Under Namespace

Modules: Episode, Podcast, Resource, Statistic

Instance Attribute Summary

Attributes included from Configurable

#api_key, #podcast_id

Instance Method Summary collapse

Methods included from Configurable

#configure, keys, #options

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



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

def initialize(options = {})
  # Use options passed in, but fall back to module defaults
  Simplecast::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || Simplecast.instance_variable_get(:"@#{key}"))
  end
  @client = Hurley::Client.new('https://api.simplecast.fm/v1/')
  @client.header["X-API-KEY"] = @api_key
  @client
end

Instance Method Details

#get(url) ⇒ Object



27
28
29
30
31
# File 'lib/simplecast/client.rb', line 27

def get(url)
  puts "Log request: #{url.inspect}"
  response = @client.get(url)
  JSON.parse(response.body)
end

#request(method, path, data, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simplecast/client.rb', line 16

def request(method, path, data, options = {})
  if data.is_a?(Hash)
    options[:query]   = data.delete(:query) || {}
    options[:headers] = data.delete(:headers) || {}
    if accept = data.delete(:accept)
      options[:headers][:accept] = accept
    end
  end
  @last_response = response = @client.send(method, URI::Parser.new.escape(path.to_s), data, options)
  response.data
end