Sha256: f9a5bf1b00c3a22c6e62472f276ce40e74f5145e2496fbcdfefd4608c97b4d11

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true
module Slack
  module Web
    module Faraday
      module Request
        def get(path, options = {})
          request(:get, path, options)
        end

        def post(path, options = {})
          request(:post, path, options)
        end

        def put(path, options = {})
          request(:put, path, options)
        end

        def delete(path, options = {})
          request(:delete, path, options)
        end

        private

        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
              options.compact!
              request.body = options unless options.empty?
            end
            request.headers['Authorization'] = "Bearer #{token}" if token
            request.options.merge!(options.delete(:request)) if options.key?(:request)
          end
          response.body
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack-ruby-client-1.0.0 lib/slack/web/faraday/request.rb