Module: Puddle
- Defined in:
- lib/puddle.rb,
lib/puddle/version.rb,
lib/puddle/cli/main.rb,
lib/puddle/cli/base_cli.rb
Defined Under Namespace
Modules: Cli
Constant Summary collapse
- DO_API_BASE =
'https://api.digitalocean.com'- DO_API_VERSION =
'v2'- VERSION =
"0.1.0"
Class Attribute Summary collapse
-
.api_token ⇒ Object
Returns the value of attribute api_token.
Class Method Summary collapse
- .accept_encoding_header ⇒ Object
- .accept_header ⇒ Object
- .account ⇒ Object
- .authorization_header ⇒ Object
- .build_headers(headers = {}) ⇒ Object
- .content_type_header ⇒ Object
- .digital_ocean(method, endpoint, options = {}) ⇒ Object
- .digital_ocean_api_url ⇒ Object
- .user_agent_header ⇒ Object
Class Attribute Details
.api_token ⇒ Object
Returns the value of attribute api_token.
10 11 12 |
# File 'lib/puddle.rb', line 10 def api_token @api_token end |
Class Method Details
.accept_encoding_header ⇒ Object
31 32 33 |
# File 'lib/puddle.rb', line 31 def accept_encoding_header 'gzip, deflate' end |
.accept_header ⇒ Object
19 20 21 |
# File 'lib/puddle.rb', line 19 def accept_header '*/*; q=0.5, application/json' end |
.account ⇒ Object
47 48 49 50 |
# File 'lib/puddle.rb', line 47 def account result = digital_ocean(:get, 'account') JSON.parse(result) end |
.authorization_header ⇒ Object
23 24 25 |
# File 'lib/puddle.rb', line 23 def "Bearer #{api_token}" end |
.build_headers(headers = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/puddle.rb', line 35 def build_headers(headers = {}) defaults = { 'Accept' => accept_header, 'Accept-Encoding' => accept_encoding_header, 'Authorization' => , 'Content-Type' => content_type_header, 'User-Agent' => user_agent_header, } defaults.merge(headers) end |
.content_type_header ⇒ Object
15 16 17 |
# File 'lib/puddle.rb', line 15 def content_type_header 'application/json' end |
.digital_ocean(method, endpoint, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/puddle.rb', line 52 def digital_ocean(method, endpoint, = {}) headers = build_headers([:headers] || {}) timeout = [:timeout] || 10 url = "#{digital_ocean_api_url}/#{endpoint}" RestClient::Request.execute( method: method, url: url, headers: headers, timeout: timeout ) end |
.digital_ocean_api_url ⇒ Object
11 12 13 |
# File 'lib/puddle.rb', line 11 def digital_ocean_api_url "#{DO_API_BASE}/#{DO_API_VERSION}" end |
.user_agent_header ⇒ Object
27 28 29 |
# File 'lib/puddle.rb', line 27 def user_agent_header 'Puddle' end |