class Cronofy::ApiKey
Public Class Methods
new(client, client_secret)
click to toggle source
# File lib/cronofy/api_key.rb, line 5 def initialize(client, client_secret) @client = client @client_secret = client_secret end
Public Instance Methods
get(path, opts = {}, &block)
click to toggle source
Make a GET request with the API Key
@see ApiKey#request
# File lib/cronofy/api_key.rb, line 25 def get(path, opts = {}, &block) request(:get, path, opts, &block) end
patch(path, opts = {}, &block)
click to toggle source
Make a PATCH request with the API Key
@see ApiKey#request
# File lib/cronofy/api_key.rb, line 46 def patch(path, opts = {}, &block) request(:patch, path, opts, &block) end
post(path, opts = {}, &block)
click to toggle source
Make a POST request with the API Key
@see ApiKey#request
# File lib/cronofy/api_key.rb, line 32 def post(path, opts = {}, &block) request(:post, path, opts, &block) end
put(path, opts = {}, &block)
click to toggle source
Make a PUT request with the API Key
@see ApiKey#request
# File lib/cronofy/api_key.rb, line 39 def put(path, opts = {}, &block) request(:put, path, opts, &block) end
request(verb, path, opts = {}, &block)
click to toggle source
Make a request with the API Key
@param [Symbol] verb the HTTP request method @param [String] path the HTTP URL path of the request @param [Hash] opts the options to make the request with @see Client#request
# File lib/cronofy/api_key.rb, line 16 def request(verb, path, opts = {}, &block) configure_authentication!(opts) opts = { snaky: false }.merge(opts) do_request { @client.request(verb, path, opts, &block) } end
Private Instance Methods
blank?(value)
click to toggle source
# File lib/cronofy/api_key.rb, line 70 def blank?(value) value.nil? || value.strip.empty? end
configure_authentication!(opts)
click to toggle source
# File lib/cronofy/api_key.rb, line 56 def configure_authentication!(opts) opts[:headers] ||= {} opts[:headers].merge!(headers) end
do_request(&block)
click to toggle source
# File lib/cronofy/api_key.rb, line 61 def do_request(&block) if blank?(@client_secret) raise CredentialsMissingError.new("OAuth client_id and client_secret must be set") end block.call rescue OAuth2::Error => e raise Errors.map_error(e) end
headers()
click to toggle source
# File lib/cronofy/api_key.rb, line 52 def headers {'Authorization' => "Bearer #{@client_secret}"} end