Class: Appfirst::Client::Real

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/appfirst/client.rb,
lib/appfirst/requests/create_server_tag.rb

Instance Attribute Summary

Attributes included from Shared

#path, #url, #user

Instance Method Summary collapse

Methods included from Shared

#setup

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/appfirst/client.rb', line 39

def initialize(options={})
  setup(options)
  adapter            = options[:adapter] || Faraday.default_adapter
  connection_options = options[:connection_options] || {ssl: {verify: false}}

  @connection = Faraday.new({url: @url}.merge(connection_options)) do |builder|
    builder.basic_auth @user, @password
    builder.request  :url_encoded
    builder.response :json, content_type: /\bjson$/
    builder.adapter  adapter
    builder.request :retry, max: 10, interval: 0.05, interval_randomness: 0.5, backoff_factor: 2

    builder.use Appfirst::Logger, @logger

    builder.adapter *adapter
  end
end

Instance Method Details

#create_server_tag(params = {}) ⇒ Object



3
4
5
# File 'lib/appfirst/requests/create_server_tag.rb', line 3

def create_server_tag(params={})
  request(:post, "/server_tags", params)
end

#request(method, request_path, params = nil) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/appfirst/client.rb', line 57

def request(method, request_path, params = nil)
  response = @connection.send(method) do |req|
    req.url(File.join(@url, path, request_path, "/"))
    req.params.merge!(params)
  end

  Appfirst::Response.new(response.status, response.headers, response.body).raise!
end