class Deis::Client::Real

Attributes

logger[RW]
url[RW]
username[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/deis/client/real.rb, line 7
def initialize(options={})
  @url      = options.fetch(:url)
  @logger   = options[:logger]   || Logger.new(nil)
  adapter   = options[:adapter]  || Faraday.default_adapter
  @username = options[:username]
  password  = options[:password]
  token     = options[:token]


  @auth_token = password || token

  connection_options = options[:connection_options] || {}

  @connection = Faraday.new({url: @url}.merge(connection_options)) do |builder|
    # response
    if username && auth_token
      builder.use Faraday::Request::BasicAuthentication, @username, @auth_token
    end

    builder.use Faraday::Response::RaiseError
    builder.request :retry,
      :max            => 5,
      :interval       => 1,
      :backoff_factor => 2
    builder.response :json

    # request
    builder.request :multipart
    builder.request :json

    builder.use Ey::Logger::Faraday, format: :machine, device: @logger, prefix: "deis"
    builder.adapter adapter
  end
end

Public Instance Methods

register_user(params={}) click to toggle source

@see docs.deis.io/en/v1.3.0/reference/api-v1.0/#register-a-new-user

# File lib/deis/client/requests/register_user.rb, line 3
def register_user(params={})
  request(
    :path   => "auth/register",
    :method => :post,
    :body   => Cistern::Hash.slice(params, "username", "password", "email", "first_name", "last_name"),
  )
end
request(options={}) click to toggle source
# File lib/deis/client/real.rb, line 42
def request(options={})
  method  = options[:method] || :get
  url     = options[:url] || File.join(@url, "v1", options.fetch(:path))
  params  = options[:params] || {}
  body    = options[:body]
  headers = {
    "Content-Type" => "application/json",
    "Accept"       => "application/json",
  }.merge(options[:headers] || {})

  @connection.send(method) do |req|
    req.url(url)
    req.headers.merge!(headers)
    req.params.merge!(params)
    req.body = body
  end
end