lib/deepl/requests/base.rb in deepl-rb-0.0.1 vs lib/deepl/requests/base.rb in deepl-rb-1.0.0

- old
+ new

@@ -1,25 +1,30 @@ module DeepL module Requests class Base API_VERSION = 'v1'.freeze - attr_reader :api, :response + attr_reader :api, :response, :options - def initialize(api) + def initialize(api, options = {}) @api = api + @options = options end def request raise NotImplementedError end private + def option(name) + options[name.to_s] || options[name.to_sym] + end + def post(payload) request = Net::HTTP::Post.new(uri.request_uri) - request.set_form_data(payload.compact) + request.set_form_data(payload.reject { |_, v| v.nil? }) response = http.request(request) validate_response!(request, response) [request, response] end @@ -63,10 +68,10 @@ def host api.configuration.host end def query_params - { auth_key: api.configuration.auth_key } + { auth_key: api.configuration.auth_key }.merge(options) end end end end