Sha256: edbdd9a5fcfecf18df6383edcf2023bed3e5bad1d093c49e18dabbfae603abf4

Contents?: true

Size: 1.14 KB

Versions: 651

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Files
  class Api
    def self.send_request(path, verb, params, options)
      warn_on_options_in_params(params)

      options[:client] ||= ApiClient.active_client

      headers = options.clone
      api_key = headers.delete(:api_key)
      client = headers.delete(:client)
      session_id = headers.delete(:session_id)
      if session = headers.delete(:session)
        session.save unless session.id
        session_id = session.id
      end

      resp, options[:api_key], options[:session_id] = client.execute_request(
        verb, path, api_key: api_key, headers: headers, params: params, session_id: session_id
      )

      # Hash#select returns an array before 1.9
      options_to_persist = {}
      options.each do |k, v|
        options_to_persist[k] = v if Util::OPTS.include?(k)
      end

      [ resp, options_to_persist ]
    end

    def self.warn_on_options_in_params(params)
      Util::OPTS.each do |opt|
        warn("WARNING: #{opt} should be in the options hash, not the params hash.  You may need to create a second hash that goes after params.)") if params.key?(opt)
      end
    end
  end
end

Version data entries

651 entries across 651 versions & 1 rubygems

Version Path
files.com-1.0.17 lib/files.com/api.rb
files.com-1.0.16 lib/files.com/api.rb
files.com-1.0.15 lib/files.com/api.rb
files.com-1.0.14 lib/files.com/api.rb
files.com-1.0.13 lib/files.com/api.rb
files.com-1.0.12 lib/files.com/api.rb
files.com-1.0.11 lib/files.com/api.rb
files.com-1.0.10 lib/files.com/api.rb
files.com-1.0.9 lib/files.com/api.rb
files.com-1.0.8 lib/files.com/api.rb
files.com-1.0.7 lib/files.com/api.rb