Sha256: 60e129850aeadcd6d727c965a67c0f759562f074171a6fd0097e43d67027adc2

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

require 'rest_in_peace/template_sanitizer'
require 'rest_in_peace/response_converter'

module RESTinPeace
  class ApiCall
    def initialize(api, url_template, klass, params)
      @api = api
      @url_template = url_template
      @klass = klass
      @params = params
    end

    def get
      response = api.get(url, params)
      convert_response(response)
    end

    def post
      response = api.post(url, params)
      convert_response(response)
    end

    def patch
      response = api.patch(url, params)
      convert_response(response)
    end

    def put
      response = api.put(url, params)
      convert_response(response)
    end

    def delete
      response = api.delete(url, params)
      convert_response(response)
    end

    def url
      sanitizer.url
    end

    def params
      sanitizer.leftover_params
    end

    def sanitizer
      @sanitizer ||= RESTinPeace::TemplateSanitizer.new(@url_template, @params)
    end

    def convert_response(response)
      RESTinPeace::ResponseConverter.new(response, @klass).result
    end

    def api
      @api.respond_to?(:call) ? @api.call : @api
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rest-in-peace-4.0.0 lib/rest_in_peace/api_call.rb
rest-in-peace-3.0.0 lib/rest_in_peace/api_call.rb
rest-in-peace-2.0.4 lib/rest_in_peace/api_call.rb
rest-in-peace-2.0.3 lib/rest_in_peace/api_call.rb
rest-in-peace-2.0.2 lib/rest_in_peace/api_call.rb
rest-in-peace-2.0.1 lib/rest_in_peace/api_call.rb
rest-in-peace-2.0.0 lib/rest_in_peace/api_call.rb
rest-in-peace-1.4.0 lib/rest_in_peace/api_call.rb
rest-in-peace-1.3.1 lib/rest_in_peace/api_call.rb
rest-in-peace-1.3.0 lib/rest_in_peace/api_call.rb