module PaylocityWebService::Connection

Network layer for API clients.

Public Instance Methods

delete(url, options = {}) click to toggle source

Make a HTTP DELETE request

@param url [String] The path, relative to {#api_endpoint} @param options [Hash] Query and header params for request @return [Sawyer::Resource]

# File lib/paylocity_web_service/connection.rb, line 53
def delete(url, options = {})
  request :delete, url, options
end
get(url) click to toggle source

Make a HTTP GET request

@param url [String] The path, relative to {#api_endpoint} @return [Sawyer::Resource]

# File lib/paylocity_web_service/connection.rb, line 17
def get(url)
  request :get, url
end
head(url, options = {}) click to toggle source

Make a HTTP HEAD request

@param url [String] The path, relative to {#api_endpoint} @param options [Hash] Query and header params for request @return [Sawyer::Resource]

# File lib/paylocity_web_service/connection.rb, line 62
def head(url, options = {})
  request :head, url, options
end
patch(url, options = {}) click to toggle source

Make a HTTP PATCH request

@param url [String] The path, relative to {#api_endpoint} @param options [Hash] Body and header params for request @return [Sawyer::Resource]

# File lib/paylocity_web_service/connection.rb, line 44
def patch(url, options = {})
  request :patch, url, options
end
post(url, options = {}) click to toggle source

Make a HTTP POST request

@param url [String] The path, relative to {#api_endpoint} @param options [Hash] Body and header params for request @return [Sawyer::Resource]

# File lib/paylocity_web_service/connection.rb, line 26
def post(url, options = {})
  request :post, url, options
end
put(url, options = {}) click to toggle source

Make a HTTP PUT request

@param url [String] The path, relative to {#api_endpoint} @param options [Hash] Body and header params for request @return [Sawyer::Resource]

# File lib/paylocity_web_service/connection.rb, line 35
def put(url, options = {})
  request :put, url, options
end

Private Instance Methods

connection() click to toggle source
# File lib/paylocity_web_service/connection.rb, line 83
def connection
  options = {
    headers: {
      'Accept' => "application/#{format}; charset=utf-8",
      'User-Agent' => user_agent,
      'Content-Type' => "application/#{format}"
    },
    proxy: proxy,
    url: endpoint,
  }.merge(connection_options)

  connection = Faraday::Connection.new(options) do |conn|
    conn.use Faraday::Request::Authorization, :Bearer, access_token
    conn.request :retry, max: 2
    conn.request :json

    conn.use PaylocityWebService::Middleware::Response::RaiseError
    conn.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
  end

  connection
end
request(method, path, options = {}) click to toggle source
# File lib/paylocity_web_service/connection.rb, line 69
def request(method, path, options = {})
  response = connection.send(method) do |request|
    case method
    when :get, :delete
      request.url(path, options)
    when :post, :put
      request.path = path
      request.body = envelope_encrypt(options)
    end
  end

  response
end