vault-usage-client 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +5 -4
- data/bin/console +26 -0
- data/lib/vault-usage-client/client.rb +36 -0
- data/lib/vault-usage-client/version.rb +1 -1
- data/test/client_test.rb +23 -7
- metadata +3 -3
- data/.ruby-gemset +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 286fda12d23933d982e5f9d1f2c77171f161fe23
|
4
|
+
data.tar.gz: 4d37cca0d12010a7aa6844f7585959eaeb9c336b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b39d012a2896e9ad4cb980b495e057ec66260902f02a40d050e056079fe3ba3daf37fc86baad3618e6218a07487d74d541b72cc62ab98ae5b9a3bc465c7d59b
|
7
|
+
data.tar.gz: 82dc3d786ad37fcfa3f7d03c32c588a885ad122ddaafd519a8a3eaa61d4ad05f76ad5f1be8d9052a0bdb7e67da0af369db35082a09fd920d7a42e71a64f71c9f
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vault-usage-client (0.0.
|
4
|
+
vault-usage-client (0.0.9)
|
5
5
|
colorize
|
6
6
|
excon
|
7
7
|
multi_json
|
@@ -14,8 +14,8 @@ GEM
|
|
14
14
|
celluloid (0.15.2)
|
15
15
|
timers (~> 1.1.0)
|
16
16
|
coderay (1.1.0)
|
17
|
-
colorize (0.
|
18
|
-
excon (0.
|
17
|
+
colorize (0.7.3)
|
18
|
+
excon (0.39.5)
|
19
19
|
ffi (1.9.3)
|
20
20
|
formatador (0.2.5)
|
21
21
|
guard (2.6.1)
|
@@ -37,7 +37,7 @@ GEM
|
|
37
37
|
method_source (0.8.2)
|
38
38
|
mini_portile (0.6.0)
|
39
39
|
minitest (4.7.5)
|
40
|
-
multi_json (1.
|
40
|
+
multi_json (1.10.1)
|
41
41
|
nokogiri (1.6.2.1)
|
42
42
|
mini_portile (= 0.6.0)
|
43
43
|
parslet (1.6.1)
|
@@ -75,6 +75,7 @@ PLATFORMS
|
|
75
75
|
ruby
|
76
76
|
|
77
77
|
DEPENDENCIES
|
78
|
+
pry
|
78
79
|
rake
|
79
80
|
rr
|
80
81
|
scrolls
|
data/bin/console
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
### Bundler ##
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
Bundler.require(:development)
|
7
|
+
|
8
|
+
APP_ROOT=File.expand_path(File.dirname(__FILE__)) + "/.."
|
9
|
+
|
10
|
+
require File.join(APP_ROOT,'/lib/vault-usage-client.rb')
|
11
|
+
include Vault::Usage
|
12
|
+
|
13
|
+
# add ability to reload console
|
14
|
+
def reload!
|
15
|
+
reload_msg = '# Reloading the console...'
|
16
|
+
puts CodeRay.scan(reload_msg, :ruby).term
|
17
|
+
Pry.save_history
|
18
|
+
exec(File.expand_path(__FILE__), 'bin/console')
|
19
|
+
end
|
20
|
+
|
21
|
+
system('clear')
|
22
|
+
welcome = <<eos
|
23
|
+
# Welcome to Vault Usage Client Interactive Console
|
24
|
+
eos
|
25
|
+
puts CodeRay.scan(welcome, :ruby).term
|
26
|
+
Pry.start
|
@@ -170,6 +170,42 @@ module Vault::Usage
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
+
# Get the usage events for a product specific to a user.
|
174
|
+
#
|
175
|
+
# @param user_hid [String] The user HID, such as `user1234@heroku.com`, to
|
176
|
+
# fetch usage data for.
|
177
|
+
# @param product_name [String] The product name such as `account:credit:lumpsum`, to
|
178
|
+
# fetch usage data for.
|
179
|
+
# @raise [Excon::Errors::HTTPStatusError] Raised if the server returns an
|
180
|
+
# unsuccessful HTTP status code.
|
181
|
+
# @return [Array] A list of usage events for the specified user, matching
|
182
|
+
# the following format:
|
183
|
+
#
|
184
|
+
# ```
|
185
|
+
# [{id: '<event-uuid>',
|
186
|
+
# product: '<name>',
|
187
|
+
# consumer: '<heroku-id>',
|
188
|
+
# start_time: <Time>,
|
189
|
+
# stop_time: <Time>,
|
190
|
+
# detail: {<key1>: <value1>,
|
191
|
+
# <key2>: <value2>,
|
192
|
+
# ...}},
|
193
|
+
# ...]}
|
194
|
+
# ```
|
195
|
+
def usage_for_user_by_product(user_hid, product_name)
|
196
|
+
path = "/users/#{user_hid}/usage/product/#{product_name}"
|
197
|
+
connection = Excon.new(@url)
|
198
|
+
response = connection.get(path: path, expects: [200])
|
199
|
+
payload = MultiJson.load(response.body, {symbolize_keys: true})
|
200
|
+
return payload[:job_id] if payload[:job_id]
|
201
|
+
events = payload[:events]
|
202
|
+
events.each do |event|
|
203
|
+
event.each do |key, value|
|
204
|
+
event[key] = parse_date(value) if date?(value)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
173
209
|
# Get the open dyno usage events for the specified app
|
174
210
|
#
|
175
211
|
# @param app_hid [String] The app HID, such as `app1234@heroku.com`, to
|
data/test/client_test.rb
CHANGED
@@ -48,7 +48,7 @@ class ClientTest < Vault::TestCase
|
|
48
48
|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
49
49
|
request[:headers]['Authorization'])
|
50
50
|
assert_equal('vault-usage.herokuapp.com', request[:host])
|
51
|
-
assert_equal(
|
51
|
+
assert_equal(443, request[:port])
|
52
52
|
assert_equal("/products/#{@product_name}/usage/#{@app_hid}" +
|
53
53
|
"/events/#{@event_id}/open/#{iso_format(@start_time)}",
|
54
54
|
request[:path])
|
@@ -106,7 +106,7 @@ class ClientTest < Vault::TestCase
|
|
106
106
|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
107
107
|
request[:headers]['Authorization'])
|
108
108
|
assert_equal('vault-usage.herokuapp.com', request[:host])
|
109
|
-
assert_equal(
|
109
|
+
assert_equal(443, request[:port])
|
110
110
|
assert_equal("/products/#{@product_name}/usage/#{@app_hid}" +
|
111
111
|
"/events/#{@event_id}/close/#{iso_format(@stop_time)}",
|
112
112
|
request[:path])
|
@@ -147,7 +147,7 @@ class ClientTest < Vault::TestCase
|
|
147
147
|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
148
148
|
request[:headers]['Authorization'])
|
149
149
|
assert_equal('vault-usage.herokuapp.com', request[:host])
|
150
|
-
assert_equal(
|
150
|
+
assert_equal(443, request[:port])
|
151
151
|
assert_equal("/products/#{@product_name}/usage/#{@app_hid}" +
|
152
152
|
"/events/#{@event_id}/open/#{iso_format(@start_time)}" +
|
153
153
|
"/close/#{iso_format(@stop_time)}",
|
@@ -221,7 +221,7 @@ class ClientTest < Vault::TestCase
|
|
221
221
|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
222
222
|
request[:headers]['Authorization'])
|
223
223
|
assert_equal('vault-usage.herokuapp.com', request[:host])
|
224
|
-
assert_equal(
|
224
|
+
assert_equal(443, request[:port])
|
225
225
|
assert_equal("/users/#{@user_hid}/usage/#{iso_format(@start_time)}/" +
|
226
226
|
"#{iso_format(@stop_time)}",
|
227
227
|
request[:path])
|
@@ -344,7 +344,7 @@ class ClientTest < Vault::TestCase
|
|
344
344
|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
345
345
|
request[:headers]['Authorization'])
|
346
346
|
assert_equal('vault-usage.herokuapp.com', request[:host])
|
347
|
-
assert_equal(
|
347
|
+
assert_equal(443, request[:port])
|
348
348
|
assert_equal("/users/#{@user_hid}/apps/#{@app_hid}/open/#{@event_id}" +
|
349
349
|
"/#{iso_format(@start_time)}",
|
350
350
|
request[:path])
|
@@ -389,7 +389,7 @@ class ClientTest < Vault::TestCase
|
|
389
389
|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
390
390
|
request[:headers]['Authorization'])
|
391
391
|
assert_equal('vault-usage.herokuapp.com', request[:host])
|
392
|
-
assert_equal(
|
392
|
+
assert_equal(443, request[:port])
|
393
393
|
assert_equal("/users/#{@user_hid}/apps/#{@app_hid}/close/#{@event_id}" +
|
394
394
|
"/#{iso_format(@stop_time)}",
|
395
395
|
request[:path])
|
@@ -433,11 +433,27 @@ class ClientTest < Vault::TestCase
|
|
433
433
|
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
434
434
|
request[:headers]['Authorization'])
|
435
435
|
assert_equal('vault-usage.herokuapp.com', request[:host])
|
436
|
-
assert_equal(
|
436
|
+
assert_equal(443, request[:port])
|
437
437
|
assert_equal("/apps/#{@app_hid}/ps/open", request[:path])
|
438
438
|
Excon.stubs.pop
|
439
439
|
{status: 200, body: MultiJson.dump({events: []})}
|
440
440
|
end
|
441
441
|
assert_equal([], @client.open_dynos_for_app(@app_hid))
|
442
442
|
end
|
443
|
+
|
444
|
+
# Client.usage_for_user_by_product makes a GET request to the Vault::Usage HTTP API,
|
445
|
+
# passing the supplied credentials using HTTP basic auth, to retrieve the
|
446
|
+
# usage events specific to a product
|
447
|
+
def test_usage_for_user_by_product
|
448
|
+
Excon.stub(method: :get) do |request|
|
449
|
+
assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
|
450
|
+
request[:headers]['Authorization'])
|
451
|
+
assert_equal('vault-usage.herokuapp.com', request[:host])
|
452
|
+
assert_equal(443, request[:port])
|
453
|
+
assert_equal("/users/#{@user_hid}/usage/product/#{@product_name}", request[:path])
|
454
|
+
Excon.stubs.pop
|
455
|
+
{status: 200, body: MultiJson.dump({events: []})}
|
456
|
+
end
|
457
|
+
assert_equal([], @client.usage_for_user_by_product(@user_hid, @product_name))
|
458
|
+
end
|
443
459
|
end
|
metadata
CHANGED
@@ -1,7 +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.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Continanza
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: excon
|
@@ -63,7 +63,6 @@ extensions: []
|
|
63
63
|
extra_rdoc_files: []
|
64
64
|
files:
|
65
65
|
- ".gitignore"
|
66
|
-
- ".ruby-gemset"
|
67
66
|
- ".ruby-version"
|
68
67
|
- ".travis.yml"
|
69
68
|
- ".yardopts"
|
@@ -71,6 +70,7 @@ files:
|
|
71
70
|
- Gemfile.lock
|
72
71
|
- README.md
|
73
72
|
- Rakefile
|
73
|
+
- bin/console
|
74
74
|
- bin/vault-usage
|
75
75
|
- lib/vault-usage-client.rb
|
76
76
|
- lib/vault-usage-client/client.rb
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
vault-usage-client
|