droplet_kit 2.6.0 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c4785840d709bf0fb77376b1a0bde83177bf180
4
- data.tar.gz: bd3c1da28e541f47c2f701fed55730a618e99af9
3
+ metadata.gz: 86f7ab1bde3cbd736afb675cef233f4d24775c32
4
+ data.tar.gz: 8d525afec4d2bf96b3e77cafa35dd475584210f6
5
5
  SHA512:
6
- metadata.gz: e5ec1fa13b657d29485822b0b4171a39f774398bf89722bfdcf4e81db0afbf01611b689feab1f802508029715bbe4b1df0534aedbcfefa05cd1ff049dce432fd
7
- data.tar.gz: 7db985a236a9066c49fe5403418ed0f79cc7016389320e9cb6e851ebd85dd66d5422949b5f06cf7db172d9edfab07d9b016d773ad1f9ef53bb29be8753dd47d6
6
+ metadata.gz: 9d8b775dea7c1d4f2972e22a4c27d00d697f1f028fe27b9caf232ea3643bd21f545591cc736893730f2cccc0294b563d13a1a003e61396266d4150acd4b34e16
7
+ data.tar.gz: fed45dc62fe67d39777503472e32345bcb9ac0d886792782fe4ab914cf5f7197d349dcb1ce23c827160531d7a65d7620fa691470abf44aa5a1203dad417a93da
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### Version 2.6.1
2
+ * Added custom User-Agent for DropletKit
3
+
1
4
  ### Version 2.6.0
2
5
  * Added ability to manage projects.
3
6
 
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:
@@ -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
@@ -1,3 +1,3 @@
1
1
  module DropletKit
2
- VERSION = "2.6.0"
2
+ VERSION = "2.6.1"
3
3
  end
@@ -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.0
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-10-16 00:00:00.000000000 Z
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.11
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