Class: DropletKit::Client
- Inherits:
-
Object
- Object
- DropletKit::Client
- Defined in:
- lib/droplet_kit/client.rb
Constant Summary collapse
- DEFAULT_OPEN_TIMEOUT =
60
- DEFAULT_TIMEOUT =
120
- DIGITALOCEAN_API =
'https://api.digitalocean.com'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Class Method Summary collapse
Instance Method Summary collapse
- #connection ⇒ Object
- #default_user_agent ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(name, *args, &block) ⇒ Object
- #resources ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 |
# File 'lib/droplet_kit/client.rb', line 11 def initialize( = {}) @access_token = .with_indifferent_access[:access_token] @api_url = .with_indifferent_access[:api_url] || DIGITALOCEAN_API @open_timeout = .with_indifferent_access[:open_timeout] || DEFAULT_OPEN_TIMEOUT @timeout = .with_indifferent_access[:timeout] || DEFAULT_TIMEOUT @user_agent = .with_indifferent_access[:user_agent] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/droplet_kit/client.rb', line 57 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_token ⇒ Object (readonly)
Returns the value of attribute access_token.
9 10 11 |
# File 'lib/droplet_kit/client.rb', line 9 def access_token @access_token end |
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
9 10 11 |
# File 'lib/droplet_kit/client.rb', line 9 def api_url @api_url end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
9 10 11 |
# File 'lib/droplet_kit/client.rb', line 9 def open_timeout @open_timeout end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/droplet_kit/client.rb', line 9 def timeout @timeout end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
9 10 11 |
# File 'lib/droplet_kit/client.rb', line 9 def user_agent @user_agent end |
Class Method Details
.resources ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/droplet_kit/client.rb', line 27 def self.resources { actions: ActionResource, cdns: CDNResource, certificates: CertificateResource, droplets: DropletResource, kubernetes_clusters: KubernetesClusterResource, kubernetes_options: KubernetesOptionsResource, 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, vpcs: VPCResource } end |
Instance Method Details
#connection ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/droplet_kit/client.rb', line 19 def connection @faraday ||= Faraday.new do |req| req.adapter :net_http req..open_timeout = open_timeout req..timeout = timeout end end |
#default_user_agent ⇒ Object
70 71 72 |
# File 'lib/droplet_kit/client.rb', line 70 def default_user_agent "DropletKit/#{DropletKit::VERSION} Faraday/#{Faraday::VERSION}" end |
#resources ⇒ Object
66 67 68 |
# File 'lib/droplet_kit/client.rb', line 66 def resources @resources ||= {} end |