Class: DropletKit::Client

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

Constant Summary collapse

DIGITALOCEAN_API =
'https://api.digitalocean.com'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/droplet_kit/client.rb', line 9

def initialize(options = {})
  @access_token = options.with_indifferent_access[:access_token]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/droplet_kit/client.rb', line 46

def method_missing(name, *args, &block)
  if self.class.resources.keys.include?(name)
    resources[name] ||= self.class.resources[name].new(connection: connection)
    resources[name]
  else
    super
  end
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

Class Method Details

.resourcesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/droplet_kit/client.rb', line 19

def self.resources
  {
    actions: ActionResource,
    cdns: CDNResource,
    certificates: CertificateResource,
    droplets: DropletResource,
    domains: DomainResource,
    domain_records: DomainRecordResource,
    droplet_actions: DropletActionResource,
    firewalls: FirewallResource,
    images: ImageResource,
    image_actions: ImageActionResource,
    load_balancers: LoadBalancerResource,
    regions: RegionResource,
    sizes: SizeResource,
    ssh_keys: SSHKeyResource,
    snapshots: SnapshotResource,
    account: AccountResource,
    floating_ips: FloatingIpResource,
    floating_ip_actions: FloatingIpActionResource,
    tags: TagResource,
    projects: ProjectResource,
    volumes: VolumeResource,
    volume_actions: VolumeActionResource
  }
end

Instance Method Details

#connectionObject



13
14
15
16
17
# File 'lib/droplet_kit/client.rb', line 13

def connection
  @faraday ||= Faraday.new connection_options do |req|
    req.adapter :net_http
  end
end

#resourcesObject



55
56
57
# File 'lib/droplet_kit/client.rb', line 55

def resources
  @resources ||= {}
end