vault-usage-client 0.0.6 → 0.0.7
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 +7 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +26 -28
- data/lib/vault-usage-client/client.rb +40 -0
- data/lib/vault-usage-client/version.rb +1 -1
- data/test/client_test.rb +75 -1
- metadata +13 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 102e34a7cb1dd30db607612394f6b8b8d3b94af9
|
4
|
+
data.tar.gz: a901605e7da73791d57631ea4a726d2d051d8f42
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3adb16ddbb8a0883730202843aa845f50a1f0fde8d274cf60ce1cb11025acf5b34fb29952ab33faf11fc25965626dfd0389a43bba27ffe502bb6aba2af3ab6ff
|
7
|
+
data.tar.gz: 2708bea990ecff179dbefe9542092ff28927610bac75e28778f2e28c7526b3995bdfe724fadba6f29de492c4efea79e904ca527db5d0984440bb936d20273f0e
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
GIT
|
2
|
-
remote: https://github.com/heroku/vault-test-tools.git
|
3
|
-
revision: 14b52d0aad51aeefa58b7fc00dde63d5e578cbe8
|
4
|
-
specs:
|
5
|
-
vault-test-tools (0.2.4)
|
6
|
-
minitest
|
7
|
-
nokogiri
|
8
|
-
rack-perftools_profiler
|
9
|
-
rack-test
|
10
|
-
rdoc
|
11
|
-
redcarpet
|
12
|
-
turn
|
13
|
-
yard
|
14
|
-
|
15
1
|
PATH
|
16
2
|
remote: .
|
17
3
|
specs:
|
@@ -24,29 +10,41 @@ GEM
|
|
24
10
|
remote: https://rubygems.org/
|
25
11
|
specs:
|
26
12
|
ansi (1.4.3)
|
27
|
-
colorize (0.
|
28
|
-
excon (0.
|
29
|
-
json (1.
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
colorize (0.6.0)
|
14
|
+
excon (0.27.1)
|
15
|
+
json (1.8.0)
|
16
|
+
mini_portile (0.5.1)
|
17
|
+
minitest (4.7.4)
|
18
|
+
multi_json (1.8.1)
|
19
|
+
nokogiri (1.6.0)
|
20
|
+
mini_portile (~> 0.5.0)
|
33
21
|
open4 (1.3.0)
|
34
|
-
perftools.rb (2.0.
|
22
|
+
perftools.rb (2.0.1)
|
35
23
|
rack (1.5.2)
|
36
|
-
rack-perftools_profiler (0.6.
|
24
|
+
rack-perftools_profiler (0.6.1)
|
37
25
|
open4 (~> 1.0)
|
38
|
-
perftools.rb (~> 2.0.
|
26
|
+
perftools.rb (~> 2.0.1)
|
39
27
|
rack (~> 1.0)
|
40
28
|
rack-test (0.6.2)
|
41
29
|
rack (>= 1.0)
|
42
|
-
rake (10.0
|
30
|
+
rake (10.1.0)
|
43
31
|
rdoc (4.0.1)
|
44
32
|
json (~> 1.4)
|
45
|
-
redcarpet (
|
46
|
-
rr (1.
|
33
|
+
redcarpet (3.0.0)
|
34
|
+
rr (1.1.2)
|
47
35
|
turn (0.9.6)
|
48
36
|
ansi
|
49
|
-
|
37
|
+
vault-test-tools (0.3.4)
|
38
|
+
minitest (= 4.7.4)
|
39
|
+
nokogiri
|
40
|
+
rack-perftools_profiler
|
41
|
+
rack-test
|
42
|
+
rdoc
|
43
|
+
redcarpet
|
44
|
+
rr
|
45
|
+
turn
|
46
|
+
yard
|
47
|
+
yard (0.8.7.2)
|
50
48
|
|
51
49
|
PLATFORMS
|
52
50
|
ruby
|
@@ -54,5 +52,5 @@ PLATFORMS
|
|
54
52
|
DEPENDENCIES
|
55
53
|
rake
|
56
54
|
rr
|
57
|
-
vault-test-tools
|
55
|
+
vault-test-tools
|
58
56
|
vault-usage-client!
|
@@ -74,6 +74,46 @@ module Vault::Usage
|
|
74
74
|
connection.put(path: path, expects: [201])
|
75
75
|
end
|
76
76
|
|
77
|
+
# Report that usage of a product, by a user or app, started at a
|
78
|
+
# particular time.
|
79
|
+
#
|
80
|
+
# @param event_id [String] A UUID that uniquely identifies the usage
|
81
|
+
# event.
|
82
|
+
# @param product_name [String] The name of the product that was used, such
|
83
|
+
# as `platform:dyno:logical` or `addon:memcache:100mb`.
|
84
|
+
# @param consumer_hid [String] The Heroku ID, such as `app1234@heroku.com`
|
85
|
+
# or `user1234@heroku.com`, that represents the user or app that used
|
86
|
+
# the specified product.
|
87
|
+
# @param start_time [Time] The beginning of the usage period, always in
|
88
|
+
# UTC.
|
89
|
+
# @param stop_time [Time] The end of the usage period, always in UTC.
|
90
|
+
# @param detail [Hash] Optionally, additional details to store with the
|
91
|
+
# event. Keys must be of type `Symbol` and values may only be of type
|
92
|
+
# `String`, `Fixnum`, `Bignum`, `Float`, `TrueClass`, `FalseClass` or
|
93
|
+
# `NilClass`.
|
94
|
+
# @raise [InvalidTimeError] Raised if a non-UTC start time is provided.
|
95
|
+
# @raise [Excon::Errors::HTTPStatusError] Raised if the server returns an
|
96
|
+
# unsuccessful HTTP status code.
|
97
|
+
def open_close_usage_event(event_id, product_name, consumer_hid,
|
98
|
+
start_time, stop_time, detail=nil)
|
99
|
+
unless start_time.zone.eql?('UTC')
|
100
|
+
raise InvalidTimeError.new('Start time must be in UTC.')
|
101
|
+
end
|
102
|
+
unless stop_time.zone.eql?('UTC')
|
103
|
+
raise InvalidTimeError.new('Stop time must be in UTC.')
|
104
|
+
end
|
105
|
+
path = "/products/#{product_name}/usage/#{consumer_hid}" +
|
106
|
+
"/events/#{event_id}/open/#{iso_format(start_time)}" +
|
107
|
+
"/close/#{iso_format(stop_time)}"
|
108
|
+
unless detail.nil?
|
109
|
+
headers = {'Content-Type' => 'application/json'}
|
110
|
+
body = MultiJson.dump(detail)
|
111
|
+
end
|
112
|
+
connection = Excon.new(@url)
|
113
|
+
connection.put(path: path, headers: headers, body: body,
|
114
|
+
expects: [201])
|
115
|
+
end
|
116
|
+
|
77
117
|
# Get the usage events for the apps owned by the specified user during the
|
78
118
|
# specified period.
|
79
119
|
#
|
data/test/client_test.rb
CHANGED
@@ -66,7 +66,8 @@ class ClientTest < Vault::TestCase
|
|
66
66
|
kernel: 'us-east-1-a'}
|
67
67
|
Excon.stub(method: :put) do |request|
|
68
68
|
assert_equal('application/json', request[:headers]['Content-Type'])
|
69
|
-
assert_equal(detail, MultiJson.load(request[:body],
|
69
|
+
assert_equal(detail, MultiJson.load(request[:body],
|
70
|
+
{symbolize_keys: true}))
|
70
71
|
Excon.stubs.pop
|
71
72
|
{status: 201}
|
72
73
|
end
|
@@ -138,6 +139,79 @@ class ClientTest < Vault::TestCase
|
|
138
139
|
end
|
139
140
|
end
|
140
141
|
|
142
|
+
# Client.open_close_usage_event makes a PUT request to the Vault::Usage HTTP
|
143
|
+
# API, passing the supplied credentials using HTTP basic auth, to report
|
144
|
+
# that usage of a product began at a particular time.
|
145
|
+
def test_open_close_usage_event
|
146
|
+
Excon.stub(method: :put) do |request|
|
147
|
+
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
148
|
+
request[:headers]['Authorization'])
|
149
|
+
assert_equal('vault-usage.herokuapp.com', request[:host])
|
150
|
+
assert_equal('443', request[:port])
|
151
|
+
assert_equal("/products/#{@product_name}/usage/#{@app_hid}" +
|
152
|
+
"/events/#{@event_id}/open/#{iso_format(@start_time)}" +
|
153
|
+
"/close/#{iso_format(@stop_time)}",
|
154
|
+
request[:path])
|
155
|
+
Excon.stubs.pop
|
156
|
+
{status: 201}
|
157
|
+
end
|
158
|
+
@client.open_close_usage_event(@event_id, @product_name, @app_hid,
|
159
|
+
@start_time, @stop_time)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Client.open_close_usage_event optionally accepts a detail hash which is
|
163
|
+
# sent as a JSON payload in the request body when provided.
|
164
|
+
def test_open_close_usage_event_with_detail
|
165
|
+
detail = {type: 'web',
|
166
|
+
description: 'bundle exec bin/web',
|
167
|
+
kernel: 'us-east-1-a'}
|
168
|
+
Excon.stub(method: :put) do |request|
|
169
|
+
assert_equal('application/json', request[:headers]['Content-Type'])
|
170
|
+
assert_equal(detail, MultiJson.load(request[:body],
|
171
|
+
{symbolize_keys: true}))
|
172
|
+
Excon.stubs.pop
|
173
|
+
{status: 201}
|
174
|
+
end
|
175
|
+
@client.open_close_usage_event(@event_id, @product_name, @app_hid,
|
176
|
+
@start_time, @stop_time, detail)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Client.open_close_usage_event raises an InvalidTimeError if the start time
|
180
|
+
# is not in UTC.
|
181
|
+
def test_open_close_usage_event_with_non_utc_start_time
|
182
|
+
start_time = Time.new(2013, 1, 12, 15, 25, 0, '+09:00')
|
183
|
+
error = assert_raises Vault::Usage::Client::InvalidTimeError do
|
184
|
+
@client.open_close_usage_event(@event_id, @product_name, @app_hid,
|
185
|
+
start_time, @stop_time)
|
186
|
+
end
|
187
|
+
assert_equal('Start time must be in UTC.', error.message)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Client.open_close_usage_event raises an InvalidTimeError if the stop time
|
191
|
+
# is not in UTC.
|
192
|
+
def test_open_close_usage_event_with_non_utc_stop_time
|
193
|
+
stop_time = Time.new(2013, 1, 12, 15, 25, 0, '+09:00')
|
194
|
+
error = assert_raises Vault::Usage::Client::InvalidTimeError do
|
195
|
+
@client.open_close_usage_event(@event_id, @product_name, @app_hid,
|
196
|
+
@start_time, stop_time)
|
197
|
+
end
|
198
|
+
assert_equal('Stop time must be in UTC.', error.message)
|
199
|
+
end
|
200
|
+
|
201
|
+
# Client.open_close_usage_event raises the appropriate
|
202
|
+
# Excon::Errors::HTTPStatusError if an unsuccessful HTTP status code is
|
203
|
+
# returned by the server.
|
204
|
+
def test_open_close_usage_event_with_unsuccessful_response
|
205
|
+
Excon.stub(method: :put) do |request|
|
206
|
+
Excon.stubs.pop
|
207
|
+
{status: 400, body: 'Bad inputs provided.'}
|
208
|
+
end
|
209
|
+
assert_raises Excon::Errors::BadRequest do
|
210
|
+
@client.open_close_usage_event(@event_id, @product_name, @app_hid,
|
211
|
+
@start_time, @stop_time)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
141
215
|
# Client.usage_for_user makes a GET request to the Vault::Usage HTTP API,
|
142
216
|
# passing the supplied credentials using HTTP basic auth, to retrieve the
|
143
217
|
# usage events for a particular user that occurred during the specified
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vault-usage-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Chris Continanza
|
@@ -10,54 +9,48 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: excon
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - '>='
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: '0'
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - '>='
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '0'
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: multi_json
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - '>='
|
37
33
|
- !ruby/object:Gem::Version
|
38
34
|
version: '0'
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - '>='
|
45
40
|
- !ruby/object:Gem::Version
|
46
41
|
version: '0'
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: colorize
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- -
|
46
|
+
- - '>='
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '0'
|
55
49
|
type: :runtime
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- -
|
53
|
+
- - '>='
|
61
54
|
- !ruby/object:Gem::Version
|
62
55
|
version: '0'
|
63
56
|
description: Client for Vault::Usage
|
@@ -85,33 +78,26 @@ files:
|
|
85
78
|
- vault-usage-client.gemspec
|
86
79
|
homepage: https://github.com/heroku/vault-usage-client
|
87
80
|
licenses: []
|
81
|
+
metadata: {}
|
88
82
|
post_install_message:
|
89
83
|
rdoc_options: []
|
90
84
|
require_paths:
|
91
85
|
- lib
|
92
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
87
|
requirements:
|
95
|
-
- -
|
88
|
+
- - '>='
|
96
89
|
- !ruby/object:Gem::Version
|
97
90
|
version: '0'
|
98
|
-
segments:
|
99
|
-
- 0
|
100
|
-
hash: -3250898009532451176
|
101
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
92
|
requirements:
|
104
|
-
- -
|
93
|
+
- - '>='
|
105
94
|
- !ruby/object:Gem::Version
|
106
95
|
version: '0'
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
hash: -3250898009532451176
|
110
96
|
requirements: []
|
111
97
|
rubyforge_project:
|
112
|
-
rubygems_version:
|
98
|
+
rubygems_version: 2.2.2
|
113
99
|
signing_key:
|
114
|
-
specification_version:
|
100
|
+
specification_version: 4
|
115
101
|
summary: A simple wrapper around the Vault::Usage HTTP API
|
116
102
|
test_files: []
|
117
103
|
has_rdoc:
|