vault-usage-client 0.0.10 → 0.0.11

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: c82c32f7f2abe841193cc95b66838c820b9248a2
4
- data.tar.gz: 7ad3a2bd85a6a621f64cf3b35be391d0de383767
3
+ metadata.gz: 68c67490431226bad7e3226be45499e255db555e
4
+ data.tar.gz: acad611c2b6b788c30113d0df48ed4d8979c56fb
5
5
  SHA512:
6
- metadata.gz: 277b575e35822654ffe8c1a1e7f813bd8d8955882960a3c51948b1b3880baddddea41db652e93a9e47e555c2a326233562d10dd9f0bf80c7a39069b4ac2e15fb
7
- data.tar.gz: cb836ecd390795cd6a2a4ebbee1e2f554f58f6fdad0694ed0673783f6d2f81bb4c08c2a8e7bf26b4ec5ffc033f42e496fdb443cdc3d3b1984384e2b4be1e79de
6
+ metadata.gz: d65b4dc26dc5ec6155be8714a04dbb2dba125d4ea1b929dfd79422448215ad0376f487b37e0409c4146eecffc82adb163bb71c0d95529971bc1730ea87aabbba
7
+ data.tar.gz: 378ebbab8db4dc0e4a27bd7d75a1dd679b5b54bccfb333929ec032cfcbfd7e3a9367efb0c59f8a8a21c81d42a641838a99198c06dc7bfb3728ea21f44fc875f2
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vault-usage-client (0.0.9)
5
- colorize
6
- excon
7
- multi_json
4
+ vault-usage-client (0.0.11)
5
+ colorize (~> 0.7.3)
6
+ excon (~> 0.39.5)
7
+ multi_json (~> 1.10.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -114,6 +114,32 @@ module Vault::Usage
114
114
  expects: [201])
115
115
  end
116
116
 
117
+ # Request a single usage event.
118
+ #
119
+ # @raise [Excon::Errors::HTTPStatusError] Raised if the server returns an
120
+ # unsuccessful HTTP status code.
121
+ # @return [Array] A single usage event, matching the following format:
122
+ #
123
+ # ```json
124
+ # {id: '<event-uuid>',
125
+ # product: '<name>',
126
+ # consumer: '<heroku-id>',
127
+ # start_time: '<YYYY-MM-DDTHH:MM:SSZ>',
128
+ # stop_time: '<YYYY-MM-DDTHH:MM:SSZ>',
129
+ # detail: {<key1>: <value1>,
130
+ # <key2>: <value2> }
131
+ # }
132
+ #
133
+ def usage_for_event(event_id)
134
+ path = "/usage_events/#{event_id}"
135
+ connection = Excon.new(@url)
136
+ response = connection.get(path: path, expects: [200])
137
+ event = MultiJson.load(response.body, {symbolize_keys: true})
138
+ event.each do |key, value|
139
+ event[key] = parse_date(value) if date?(value)
140
+ end
141
+ end
142
+
117
143
  # Get the usage events for the apps owned by the specified user during the
118
144
  # specified period.
119
145
  #
@@ -2,7 +2,7 @@ module Vault
2
2
  module Usage
3
3
  class Client
4
4
  # The `Vault::Usage::Client` gem version.
5
- VERSION = '0.0.10'
5
+ VERSION = '0.0.11'
6
6
  end
7
7
  end
8
8
  end
data/test/client_test.rb CHANGED
@@ -212,6 +212,30 @@ class ClientTest < Vault::TestCase
212
212
  end
213
213
  end
214
214
 
215
+ def test_usage_for_event
216
+ Excon.stub(method: :get) do |request|
217
+ assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
218
+ request[:headers]['Authorization'])
219
+ assert_equal('vault-usage.herokuapp.com', request[:host])
220
+ assert_equal(443, request[:port])
221
+ assert_equal("/usage_events/#{@event_id}",
222
+ request[:path])
223
+ Excon.stubs.pop
224
+ {status: 200, body: MultiJson.dump({id: @event_id,
225
+ product: @product_name,
226
+ consumer: @app_hid,
227
+ start_time: iso_format(@start_time),
228
+ stop_time: iso_format(@stop_time),
229
+ detail: {}})}
230
+ end
231
+ assert_equal({id: @event_id,
232
+ product: @product_name,
233
+ consumer: @app_hid,
234
+ start_time: @start_time,
235
+ stop_time: @stop_time,
236
+ detail: {}}, @client.usage_for_event(@event_id))
237
+ end
238
+
215
239
  # Client.usage_for_user makes a GET request to the Vault::Usage HTTP API,
216
240
  # passing the supplied credentials using HTTP basic auth, to retrieve the
217
241
  # usage events for a particular user that occurred during the specified
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.require_paths = ['lib']
18
18
  gem.executables = ['vault-usage']
19
19
 
20
- gem.add_dependency 'excon'
21
- gem.add_dependency 'multi_json'
22
- gem.add_dependency 'colorize'
20
+ gem.add_dependency 'excon', '~> 0.39.5'
21
+ gem.add_dependency 'multi_json', '~> 1.10.1'
22
+ gem.add_dependency 'colorize', '~> 0.7.3'
23
23
  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.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Continanza
@@ -9,50 +9,50 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-25 00:00:00.000000000 Z
12
+ date: 2015-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: 0.39.5
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: 0.39.5
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: multi_json
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 1.10.1
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: 1.10.1
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: colorize
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: 0.7.3
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: 0.7.3
56
56
  description: Client for Vault::Usage
57
57
  email:
58
58
  - csquared@heroku.com