Class: Barge::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/barge/client.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{}
DIGITAL_OCEAN_URL =
'https://api.digitalocean.com/v2'
TIMEOUTS =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = DEFAULT_OPTIONS) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:

  • _self (Barge::Client)

    the object that the method was called on



13
14
15
16
17
18
19
20
# File 'lib/barge/client.rb', line 13

def initialize(options = DEFAULT_OPTIONS)
  self.access_token = options.fetch(:access_token, nil)
  self.request_options =
    { open_timeout: TIMEOUTS, timeout: TIMEOUTS }
    .merge(options.fetch(:request_options, {}))
  yield(self) if block_given?
  fail ArgumentError, 'missing access_token' unless access_token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



6
7
8
# File 'lib/barge/client.rb', line 6

def access_token
  @access_token
end

#request_optionsObject

Returns the value of attribute request_options.



7
8
9
# File 'lib/barge/client.rb', line 7

def request_options
  @request_options
end

Instance Method Details

#accountObject



22
23
24
# File 'lib/barge/client.rb', line 22

def 
  @account ||= Resource::Account.new(faraday)
end

#actionObject



26
27
28
# File 'lib/barge/client.rb', line 26

def action
  @action ||= Resource::Action.new(faraday)
end

#domainObject



30
31
32
# File 'lib/barge/client.rb', line 30

def domain
  @domain ||= Resource::Domain.new(faraday)
end

#dropletObject



34
35
36
# File 'lib/barge/client.rb', line 34

def droplet
  @droplet ||= Resource::Droplet.new(faraday)
end

#faradayObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/barge/client.rb', line 58

def faraday
  @faraday ||= Faraday.new faraday_options do |f|
    f.adapter :net_http

    f.request :json

    f.response :follow_redirects
    f.response :mashify
    f.response :json

    f.options.merge! request_options
  end
end

#floating_ipObject



54
55
56
# File 'lib/barge/client.rb', line 54

def floating_ip
  @floating_ip ||= Resource::FloatingIP.new(faraday)
end

#imageObject



38
39
40
# File 'lib/barge/client.rb', line 38

def image
  @image ||= Resource::Image.new(faraday)
end

#keyObject



42
43
44
# File 'lib/barge/client.rb', line 42

def key
  @key ||= Resource::Key.new(faraday)
end

#regionObject



46
47
48
# File 'lib/barge/client.rb', line 46

def region
  @region ||= Resource::Region.new(faraday)
end

#sizeObject



50
51
52
# File 'lib/barge/client.rb', line 50

def size
  @size ||= Resource::Size.new(faraday)
end