Sha256: 16800f2fa200cdd27191a3683363d8eab1576bee61f3a0532f86bbbe855c3963

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 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
        rescue ::Faraday::ParsingError => e
          raise Slack::Web::Api::Errors::ParsingError, e.response
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
slack-ruby-client-2.4.0 lib/slack/web/faraday/request.rb
slack-ruby-client-2.3.0 lib/slack/web/faraday/request.rb
slack-ruby-client-2.2.0 lib/slack/web/faraday/request.rb
slack-ruby-client-2.1.0 lib/slack/web/faraday/request.rb
slack-ruby-client-2.0.0 lib/slack/web/faraday/request.rb
slack-ruby-client-1.1.0 lib/slack/web/faraday/request.rb