class Udemy::Client
Attributes
headers[RW]
Public Class Methods
get(*args)
click to toggle source
Handle Response from HTTParty
Calls superclass method
# File lib/udemy/client.rb, line 32 def self.get(*args) handle_response(super) end
handle_response(response)
click to toggle source
# File lib/udemy/client.rb, line 40 def self.handle_response(response) raise Error.new("No response from the server. Make sure the URL is correct.") \ if (response.blank? || response.parsed_response.blank?) json_response = JSON.parse(response.parsed_response) response_hash = Hashie::Mash.new(json_response) raise Udemy::APIResponseError.new(response_hash) unless response.code == 200 return Hashie::Mash.new(response_hash) end
new()
click to toggle source
# File lib/udemy/client.rb, line 9 def initialize raise Error.new("Your API credentials are missing") \ if (Udemy.client_key.blank? || Udemy.client_secret.blank?) @headers = { "X-Udemy-Client-Id" => Udemy.client_key, "X-Udemy-Client-Secret" => Udemy.client_secret } end
post(*args)
click to toggle source
Calls superclass method
# File lib/udemy/client.rb, line 36 def self.post(*args) handle_response(super) end
Public Instance Methods
get(url, opts = {})
click to toggle source
# File lib/udemy/client.rb, line 19 def get(url, opts = {}) opts = {headers: @headers}.merge(opts) Udemy::Client.get(url, opts) end
post(url, opts = {})
click to toggle source
# File lib/udemy/client.rb, line 25 def post(url, opts = {}) opts = {headers: @headers}.merge(opts) Udemy::Client.post(url, opts) end