garage_client 2.2.0 → 2.3.0

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: f0ae5b3ae6c5a36e39aea7fbb4c508248329ceb0
4
- data.tar.gz: 951d87cff4b2fa051f523879810c3231b6e95f12
3
+ metadata.gz: f2fe048281c50ac7a86c5c7e797767aad598ba7d
4
+ data.tar.gz: 79145a3ccd636a550ff080cfbf645c4b84d039ab
5
5
  SHA512:
6
- metadata.gz: 35480761fae84cd1ae4df093eb7ca58ff12a0b3942cf62220a28f6dc992297ad38dc070a627726516f701576628c47b9761fe0f36d950bb7139b5116f1a50fac
7
- data.tar.gz: dc3709d896cb7c5f4f25d71a286adfe5c2e1ed699aa3ccd773f5205054c3d4a59493f1dab127b22c96e04ad351aa04740a9007dac3bfb65bdd64b30b01e239fb
6
+ metadata.gz: b0b85356fbc7483e712608039c4fcd3281d624c497e4b5f1af6bb04345733d78b56316d7266d5570f0c70c80ec72f725993477f3f805a739ca77596e115c8f47
7
+ data.tar.gz: 8f7f45c81e14b3894010566be0af202b28f5dab33dddf7a987069a83ad712dc89fd323606ade7f9e27909f38de250769d7ce231c4f9763a24f6371f65f845e37
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.3.0
2
+ - Add new configuration parameter `name`, which is embedded in User-Agent by default
3
+
1
4
  ## 2.2.0
2
5
  - Change all 4xx exceptions to be `GarageClient::ClientError`
3
6
  - Change all 5xx exceptions to be `GarageClient::ServerError`
data/README.md CHANGED
@@ -92,7 +92,8 @@ There are the following options:
92
92
 
93
93
  - `adapter` - faraday adapter for http client (default: `:net_http`)
94
94
  - `cacher` - take a cacher class in which caching logic is defined (default: nil)
95
- - `headers` - default http headers (default: `{ "Accept" => "application/json", "User-Agent" => "garage_client #{VERSION}" }`)
95
+ - `name` - Client's application name, which is embedded in User-Agent by default (default: nil)
96
+ - `headers` - default http headers (default: `{ "Accept" => "application/json", "User-Agent" => "garage_client #{VERSION} #{name}" }`)
96
97
  - `endpoint` - Garage application API endpoint (default: nil)
97
98
  - `path_prefix` - API path prefix (default: `'/v1'`)
98
99
  - `verbose` - Enable verbose http log (default: `false`)
@@ -102,6 +103,7 @@ You can configure the global settings:
102
103
  ```ruby
103
104
  GarageClient.configure do |c|
104
105
  c.endpoint = "http://localhost:3000"
106
+ c.name = 'my-awesome-client'
105
107
  c.verbose = true
106
108
  end
107
109
  ```
@@ -113,6 +115,7 @@ client = GarageClient::Client.new(
113
115
  adapter: :test,
114
116
  headers: { "Host" => "garage.example.com" },
115
117
  endpoint: "http://localhost:3000",
118
+ name: 'my-awesome-client',
116
119
  path_prefix: "/v2",
117
120
  verbose: true,
118
121
  )
@@ -85,6 +85,9 @@ module GarageClient
85
85
  if !options[:endpoint] && !default_options.endpoint
86
86
  raise "Missing endpoint configuration"
87
87
  end
88
+ if !options[:name] && !default_options.name
89
+ raise "Missing name configuration"
90
+ end
88
91
  end
89
92
 
90
93
  def default_options
@@ -3,16 +3,12 @@ module GarageClient
3
3
  DEFAULTS = {
4
4
  adapter: :net_http,
5
5
  cacher: nil,
6
- headers: {
7
- 'Accept' => 'application/json',
8
- 'User-Agent' => "garage_client #{GarageClient::VERSION}",
9
- },
10
6
  path_prefix: '/v1',
11
7
  verbose: false,
12
8
  }
13
9
 
14
10
  def self.keys
15
- DEFAULTS.keys + [:endpoint]
11
+ DEFAULTS.keys + [:endpoint, :headers]
16
12
  end
17
13
 
18
14
  def initialize(options = {})
@@ -45,6 +41,31 @@ module GarageClient
45
41
  options[:endpoint] = value
46
42
  end
47
43
 
44
+ def name
45
+ options[:name] or raise 'Configuration error: missing name'
46
+ end
47
+
48
+ def name=(value)
49
+ options[:name] = value
50
+ end
51
+
52
+ def default_user_agent
53
+ "garage_client #{GarageClient::VERSION} #{name}"
54
+ end
55
+
56
+ def headers
57
+ options.fetch(:headers) do
58
+ {
59
+ 'Accept' => 'application/json',
60
+ 'User-Agent' => default_user_agent,
61
+ }
62
+ end
63
+ end
64
+
65
+ def headers=(value)
66
+ options[:headers] = value
67
+ end
68
+
48
69
  alias :default_headers :headers
49
70
  alias :default_headers= :headers=
50
71
  end
@@ -1,3 +1,3 @@
1
1
  module GarageClient
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -23,7 +23,7 @@ describe "Configuration of GarageClient" do
23
23
  prev = GarageClient.configuration
24
24
  GarageClient.instance_variable_set(
25
25
  :@configuration,
26
- GarageClient::Configuration.new(endpoint: "https://garage.example.com")
26
+ GarageClient::Configuration.new(endpoint: "https://garage.example.com", name: "configuration_spec")
27
27
  )
28
28
 
29
29
  example.run
@@ -110,7 +110,7 @@ describe GarageClient::Client do
110
110
  client.headers.should == {
111
111
  "Accept" => "application/json",
112
112
  "Content-Type" => "text/plain",
113
- "User-Agent" => "garage_client #{GarageClient::VERSION}"
113
+ "User-Agent" => "garage_client #{GarageClient::VERSION} garage_client_spec"
114
114
  }
115
115
  end
116
116
  end
@@ -42,11 +42,23 @@ describe GarageClient::Configuration do
42
42
  end
43
43
 
44
44
  describe "#headers" do
45
+ context "name isn't configured" do
46
+ it "raises RuntimeError" do
47
+ expect { configuration.headers }.to raise_error(RuntimeError, /missing name/)
48
+ end
49
+ end
50
+
45
51
  context "in default configuration" do
52
+ let(:name) { 'configuration_spec' }
53
+
54
+ before do
55
+ configuration.name = name
56
+ end
57
+
46
58
  it "returns default headers as Hash" do
47
59
  configuration.headers.should == {
48
60
  "Accept" => "application/json",
49
- "User-Agent" => "garage_client #{GarageClient::VERSION}",
61
+ "User-Agent" => "garage_client #{GarageClient::VERSION} #{name}",
50
62
  }
51
63
  end
52
64
  end
@@ -63,6 +75,10 @@ describe GarageClient::Configuration do
63
75
  end
64
76
 
65
77
  describe "#default_headers" do
78
+ before do
79
+ configuration.name = 'configuration_spec'
80
+ end
81
+
66
82
  it "returns configuration.headers" do
67
83
  configuration.default_headers.should == configuration.headers
68
84
  end
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,7 @@ require 'garage_client'
20
20
  GarageClient.configure do |c|
21
21
  c.path_prefix = ''
22
22
  c.endpoint = "https://garage.example.com"
23
+ c.name = 'garage_client_spec'
23
24
  end
24
25
 
25
26
  # This workaround is strictly for stubbing purpose.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: garage_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cookpad Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  version: '0'
231
231
  requirements: []
232
232
  rubyforge_project:
233
- rubygems_version: 2.2.5
233
+ rubygems_version: 2.5.1
234
234
  signing_key:
235
235
  specification_version: 4
236
236
  summary: Ruby client library for the Garage API