class ECSBundler::RestClient

Wrapper under rest-client with authorization headers

Attributes

options[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/ecs_bundler/rest_client.rb, line 11
def initialize(options = {})
  @options = options
end

Public Instance Methods

headers() click to toggle source
# File lib/ecs_bundler/rest_client.rb, line 15
def headers
  {
    content_type: :json,
    accept: :json,
    'User-Agent' => options[:userAgent],
    'X-ApiKey' => options[:apiKey],
    'X-User' => options[:userName]
  }
end
method_missing(name, *args) { |response, parsed_response, message| ... } click to toggle source

get delete head options post patch put methods

Calls superclass method
# File lib/ecs_bundler/rest_client.rb, line 31
def method_missing(name, *args)
  if %i[get delete head options post patch put].include?(name)
    if %i[get delete head options].include?(name)
      path, headers = args
      payload = nil
    else
      path, payload, headers = args
    end
    return ::RestClient::Request.execute(
      method: name,
      url: "#{options[:url]}#{path}",
      payload: payload ? payload.to_json : payload,
      headers: self.headers.merge(headers || {})
    ) do |response|
      parsed_response = JSON.parse(response.body) rescue {}
      message = [
        "#{response.code} #{::RestClient::STATUSES[response.code]}",
        parsed_response['info'],
        (parsed_response['messages'] || []).map { |message| message['message'] }
      ].compact.join(', ')
      yield(response, parsed_response, message) if block_given?
      response
    end
  end
  super(name, *args)
end
respond_to?(name) click to toggle source
Calls superclass method
# File lib/ecs_bundler/rest_client.rb, line 25
def respond_to?(name)
  return true if %i[get delete head options post patch put].include?(name)
  super(name)
end