droplet_kit 2.6.0 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +10 -0
- data/lib/droplet_kit/client.rb +8 -2
- data/lib/droplet_kit/version.rb +1 -1
- data/spec/lib/droplet_kit/client_spec.rb +15 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86f7ab1bde3cbd736afb675cef233f4d24775c32
|
4
|
+
data.tar.gz: 8d525afec4d2bf96b3e77cafa35dd475584210f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d8b775dea7c1d4f2972e22a4c27d00d697f1f028fe27b9caf232ea3643bd21f545591cc736893730f2cccc0294b563d13a1a003e61396266d4150acd4b34e16
|
7
|
+
data.tar.gz: fed45dc62fe67d39777503472e32345bcb9ac0d886792782fe4ab914cf5f7197d349dcb1ce23c827160531d7a65d7620fa691470abf44aa5a1203dad417a93da
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -29,6 +29,16 @@ require 'droplet_kit'
|
|
29
29
|
client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
|
30
30
|
```
|
31
31
|
|
32
|
+
### Custom User-Agent
|
33
|
+
|
34
|
+
If you would like to include a custom User-Agent header beyond what DropletKit
|
35
|
+
uses, you can pass one in at the client initialization like so:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'droplet_kit'
|
39
|
+
client = DropletKit::Client.new(access_token: 'YOUR_TOKEN', user_agent: 'custom')
|
40
|
+
```
|
41
|
+
|
32
42
|
## Design
|
33
43
|
|
34
44
|
DropletKit follows a strict design of resources as methods on your client. For examples, for droplets, you will call your client like this:
|
data/lib/droplet_kit/client.rb
CHANGED
@@ -4,10 +4,11 @@ module DropletKit
|
|
4
4
|
class Client
|
5
5
|
DIGITALOCEAN_API = 'https://api.digitalocean.com'
|
6
6
|
|
7
|
-
attr_reader :access_token
|
7
|
+
attr_reader :access_token, :user_agent
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
10
|
@access_token = options.with_indifferent_access[:access_token]
|
11
|
+
@user_agent = options.with_indifferent_access[:user_agent]
|
11
12
|
end
|
12
13
|
|
13
14
|
def connection
|
@@ -56,6 +57,10 @@ module DropletKit
|
|
56
57
|
@resources ||= {}
|
57
58
|
end
|
58
59
|
|
60
|
+
def default_user_agent
|
61
|
+
"DropletKit/#{DropletKit::VERSION} Faraday/#{Faraday::VERSION}"
|
62
|
+
end
|
63
|
+
|
59
64
|
private
|
60
65
|
|
61
66
|
def connection_options
|
@@ -63,7 +68,8 @@ module DropletKit
|
|
63
68
|
url: DIGITALOCEAN_API,
|
64
69
|
headers: {
|
65
70
|
content_type: 'application/json',
|
66
|
-
authorization: "Bearer #{access_token}"
|
71
|
+
authorization: "Bearer #{access_token}",
|
72
|
+
user_agent: "#{user_agent} #{default_user_agent}".strip
|
67
73
|
}
|
68
74
|
}
|
69
75
|
end
|
data/lib/droplet_kit/version.rb
CHANGED
@@ -39,6 +39,21 @@ RSpec.describe DropletKit::Client do
|
|
39
39
|
expect(client.connection.headers['Content-Type']).to eq("application/json")
|
40
40
|
end
|
41
41
|
|
42
|
+
context 'with default user agent' do
|
43
|
+
it 'contains the version of DropletKit and Faraday' do
|
44
|
+
stub_const('DropletKit::VERSION', '1.2.3')
|
45
|
+
stub_const('Faraday::VERSION', '1.2.3')
|
46
|
+
expect(client.connection.headers['User-Agent']).to eq('DropletKit/1.2.3 Faraday/1.2.3')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with user provided user agent' do
|
51
|
+
it 'includes their agent string as well' do
|
52
|
+
client = DropletKit::Client.new(access_token: 'bunk', user_agent: 'tugboat')
|
53
|
+
expect(client.connection.headers['User-Agent']).to include('tugboat')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
42
57
|
it 'allows access to faraday instance' do
|
43
58
|
client.connection.use AcmeApp::CustomLogger
|
44
59
|
expect(client.connection.builder.handlers).to include(AcmeApp::CustomLogger)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: droplet_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Ross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -447,7 +447,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
447
447
|
version: '0'
|
448
448
|
requirements: []
|
449
449
|
rubyforge_project:
|
450
|
-
rubygems_version: 2.6.
|
450
|
+
rubygems_version: 2.6.12
|
451
451
|
signing_key:
|
452
452
|
specification_version: 4
|
453
453
|
summary: Droplet Kit is the official Ruby library for DigitalOcean's API
|