Class: Simplecast::Client
- Inherits:
-
Object
- Object
- Simplecast::Client
- 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
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #request(method, path, data, options = {}) ⇒ Object
Methods included from Configurable
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( = {}) # Use options passed in, but fall back to module defaults Simplecast::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", [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, = {}) if data.is_a?(Hash) [:query] = data.delete(:query) || {} [:headers] = data.delete(:headers) || {} if accept = data.delete(:accept) [:headers][:accept] = accept end end @last_response = response = @client.send(method, URI::Parser.new.escape(path.to_s), data, ) response.data end |