class WoerkClient::Client
Acts as a gateway to the woerk.net API
Public Class Methods
Gateway for API requests
@param method [Symbol] the HTTP verb as a symbol, e.g. :get, :post, :put @param path [String] the path of the URL @param payload [Hash] the body for the request
# File lib/woerk_client/client.rb, line 13 def self.call(method: :get, path: '/', payload: nil) new(method, path, payload).call end
Shorthand for DELETE requests to the API
@param path [String]
# File lib/woerk_client/client.rb, line 47 def self.delete(path) new(:put, path, nil).call end
Shorthand for GET requests to the API
@param path [String]
# File lib/woerk_client/client.rb, line 21 def self.get(path) new(:get, path, nil).call end
@param method [Symbol] the HTTP verb as a symbol, e.g. :get, :post, :put @param path [String] the path of the URL @param payload [Hash] the body for the request
# File lib/woerk_client/client.rb, line 54 def initialize(method, path, payload) @method = method @path = path @payload = payload end
Shorthand for POST requests to the API
@param path [String] @param payload [Hash]
# File lib/woerk_client/client.rb, line 30 def self.post(path:, payload:) new(:post, path, payload).call end
Shorthand for PUT requests to the API
@param path [String] @param payload [Hash]
# File lib/woerk_client/client.rb, line 39 def self.put(path:, payload:) new(:put, path, payload).call end
Public Instance Methods
Uses RestClient to make API requests
# File lib/woerk_client/client.rb, line 61 def call RestClient::Request.execute( method: @method, url: url, payload: @payload, headers: headers ) end
Private Instance Methods
@return [String] the authentication token from the configuration file
# File lib/woerk_client/client.rb, line 97 def auth_token WoerkClient.configuration.auth_token end
Base URL from the configuration
@return [String] the base URL, e.g. woerk.net/api
# File lib/woerk_client/client.rb, line 92 def base_url WoerkClient.configuration.api_host end
All headers for every API call
@return [Hash] the headers that are submitted with every request
# File lib/woerk_client/client.rb, line 82 def headers { Accept: 'application/json; version=1', Authorization: auth_token } end
Puts the url together
@return [String] the final URL for the request
# File lib/woerk_client/client.rb, line 75 def url "#{base_url}#{@path}" end