Sha256: 9143330df352c5be1e9f5aaac7013276b6de7f398700162db4b91f9dd5c200eb

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'faraday'
require 'smartsheet/api/request'
require 'smartsheet/api/faraday_adapter/middleware/faraday_error_translator'
require 'smartsheet/api/faraday_adapter/middleware/response_parser'

module Smartsheet
  module API
    # Makes calls to the Smartsheet API through Faraday
    class FaradayNetClient
      def initialize
        create_connection
      end

      # Expected output:
      # - returned Success Response
      # - returned Error Response
      # - thrown Request Error
      def make_request(request)
        response = conn.send(request.method) do |req|
          req.url(request.url)
          req.headers = request.headers
          req.params = request.params
          req.body = request.body
        end

        response.body
      end

      private

      def create_connection
        @conn = Faraday.new do |conn|
          conn.use Middleware::FaradayErrorTranslator
          conn.use Middleware::ResponseParser

          conn.adapter Faraday.default_adapter
        end
      end

      attr_reader :conn
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smartsheet-1.0.0 lib/smartsheet/api/faraday_adapter/faraday_net_client.rb