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- DEFAULT_RETRY_MAX =
3- DEFAULT_RETRY_WAIT_MIN =
0- 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.
-
#retry_max ⇒ Object
readonly
Returns the value of attribute retry_max.
-
#retry_wait_min ⇒ Object
readonly
Returns the value of attribute retry_wait_min.
-
#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
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/droplet_kit/client.rb', line 18 def initialize( = {}) = DropletKit::Utils.transform_keys(, &:to_sym) @access_token = [:access_token] @api_url = [:api_url] || DIGITALOCEAN_API @open_timeout = [:open_timeout] || DEFAULT_OPEN_TIMEOUT @timeout = [:timeout] || DEFAULT_TIMEOUT @user_agent = [:user_agent] @retry_max = [:retry_max] || DEFAULT_RETRY_MAX @retry_wait_min = [:retry_wait_min] || DEFAULT_RETRY_WAIT_MIN end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/droplet_kit/client.rb', line 92 def method_missing(name, *args, &block) if self.class.resources.key?(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.
16 17 18 |
# File 'lib/droplet_kit/client.rb', line 16 def access_token @access_token end |
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
16 17 18 |
# File 'lib/droplet_kit/client.rb', line 16 def api_url @api_url end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
16 17 18 |
# File 'lib/droplet_kit/client.rb', line 16 def open_timeout @open_timeout end |
#retry_max ⇒ Object (readonly)
Returns the value of attribute retry_max.
16 17 18 |
# File 'lib/droplet_kit/client.rb', line 16 def retry_max @retry_max end |
#retry_wait_min ⇒ Object (readonly)
Returns the value of attribute retry_wait_min.
16 17 18 |
# File 'lib/droplet_kit/client.rb', line 16 def retry_wait_min @retry_wait_min end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
16 17 18 |
# File 'lib/droplet_kit/client.rb', line 16 def timeout @timeout end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
16 17 18 |
# File 'lib/droplet_kit/client.rb', line 16 def user_agent @user_agent end |
Class Method Details
.resources ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/droplet_kit/client.rb', line 50 def self.resources { actions: ActionResource, cdns: CDNResource, certificates: CertificateResource, container_registry: ContainerRegistryResource, container_registry_repository: ContainerRegistryRepositoryResource, databases: DatabaseResource, droplets: DropletResource, kubernetes_clusters: KubernetesClusterResource, kubernetes_options: KubernetesOptionsResource, domains: DomainResource, domain_records: DomainRecordResource, droplet_actions: DropletActionResource, firewalls: FirewallResource, images: ImageResource, image_actions: ImageActionResource, invoices: InvoiceResource, load_balancers: LoadBalancerResource, regions: RegionResource, sizes: SizeResource, ssh_keys: SSHKeyResource, snapshots: SnapshotResource, account: AccountResource, balance: BalanceResource, floating_ips: FloatingIpResource, floating_ip_actions: FloatingIpActionResource, reserved_ips: ReservedIpResource, reserved_ipv6s: ReservedIpv6Resource, reserved_ip_actions: ReservedIpActionResource, reserved_ipv6_actions: ReservedIpv6ActionResource, tags: TagResource, projects: ProjectResource, volumes: VolumeResource, volume_actions: VolumeActionResource, vpcs: VPCResource, vpc_peerings: VPCPeeringResource, one_clicks: OneClickResource, apps: AppResource } end |
Instance Method Details
#connection ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/droplet_kit/client.rb', line 29 def connection @faraday ||= Faraday.new do |req| req.adapter :net_http req..open_timeout = open_timeout req..timeout = timeout unless retry_max.zero? req.request :retry, { max: @retry_max, interval: @retry_wait_min, retry_statuses: [429], # faraday-retry supports both the Retry-After and RateLimit-Reset # headers, however, it favours the RateLimit-Reset one. To force it # to use the Retry-After header, we override the header that it # expects for the RateLimit-Reset header to something that we know # we don't set. rate_limit_reset_header: 'undefined' } end end end |
#default_user_agent ⇒ Object
105 106 107 |
# File 'lib/droplet_kit/client.rb', line 105 def default_user_agent "DropletKit/#{DropletKit::VERSION} Faraday/#{Faraday::VERSION}" end |
#resources ⇒ Object
101 102 103 |
# File 'lib/droplet_kit/client.rb', line 101 def resources @resources ||= {} end |