Sha256: a088fb214d7b1bce07572df460bd3628d4b86e8273882a8d79367b89683fea4e

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Strava
  module Web
    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)
        options = options.dup if options.key?(:request) || options.key?(:endpoint)
        root = options.delete(:endpoint) || endpoint
        path = [root, path].join('/')
        http_response = connection.send(method) do |request|
          case method
          when :get, :delete
            request.url(path, options)
          when :post, :put
            request.path = path
            request.body = options unless options.empty?
          end
          request.options.merge!(options.delete(:request)) if options.key?(:request)
        end

        Strava::Web::Response.new(http_response)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
strava-ruby-client-2.2.0 lib/strava/web/request.rb
strava-ruby-client-2.1.0 lib/strava/web/request.rb
strava-ruby-client-2.0.0 lib/strava/web/request.rb
strava-ruby-client-1.1.0 lib/strava/web/request.rb
strava-ruby-client-1.0.1 lib/strava/web/request.rb
strava-ruby-client-1.0.0 lib/strava/web/request.rb