vault-usage-client 0.0.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,8 @@
1
1
  .bundle
2
2
  doc
3
+ .env
4
+ .rvmrc
3
5
  test/.test.profile*
4
6
  vendor
5
7
  .yardoc
8
+ pkg
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  GIT
2
2
  remote: https://github.com/heroku/vault-test-tools.git
3
- revision: 5eabd67610f279b81cadb803cee8ef704093a05d
3
+ revision: 14b52d0aad51aeefa58b7fc00dde63d5e578cbe8
4
4
  specs:
5
- vault-test-tools (0.2.2)
5
+ vault-test-tools (0.2.4)
6
6
  minitest
7
7
  nokogiri
8
8
  rack-perftools_profiler
@@ -15,20 +15,20 @@ GIT
15
15
  PATH
16
16
  remote: .
17
17
  specs:
18
- vault-usage-client (0.0.1)
18
+ vault-usage-client (0.0.4)
19
19
  colorize
20
20
  excon
21
21
  yajl-ruby
22
22
 
23
23
  GEM
24
- remote: http://rubygems.org/
24
+ remote: https://rubygems.org/
25
25
  specs:
26
26
  ansi (1.4.3)
27
27
  colorize (0.5.8)
28
- excon (0.16.10)
29
- json (1.7.6)
30
- minitest (4.6.0)
31
- nokogiri (1.5.6)
28
+ excon (0.20.1)
29
+ json (1.7.7)
30
+ minitest (4.7.1)
31
+ nokogiri (1.5.9)
32
32
  open4 (1.3.0)
33
33
  perftools.rb (2.0.0)
34
34
  rack (1.5.2)
@@ -38,15 +38,15 @@ GEM
38
38
  rack (~> 1.0)
39
39
  rack-test (0.6.2)
40
40
  rack (>= 1.0)
41
- rake (10.0.3)
42
- rdoc (3.12.1)
41
+ rake (10.0.4)
42
+ rdoc (4.0.1)
43
43
  json (~> 1.4)
44
44
  redcarpet (2.2.2)
45
- rr (1.0.4)
45
+ rr (1.0.5)
46
46
  turn (0.9.6)
47
47
  ansi
48
48
  yajl-ruby (1.1.0)
49
- yard (0.8.4.1)
49
+ yard (0.8.6.1)
50
50
 
51
51
  PLATFORMS
52
52
  ruby
data/bin/vault-usage CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'ostruct'
2
3
 
3
4
  lib = File.expand_path('../../lib', __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -12,13 +13,13 @@ stop_time = Time.utc(*ARGV[2].split('-'))
12
13
 
13
14
  client = Vault::Usage::Client.new
14
15
 
15
- all_events = client.usage_for_user(user_hid, start_time, stop_time, ['platform:dyno:physical'])[:events]
16
+ all_events = client.usage_for_user(user_hid, start_time, stop_time,
17
+ ['platform:dyno:physical'])
16
18
 
17
19
  all_events.group_by { |e| e[:consumer] }.each do |consumer, app_events|
18
20
  puts "=== #{consumer} ===".blue
19
21
 
20
22
  app_events.group_by { |e| e[:product] }.each do |product, product_events|
21
-
22
23
  puts " #{product}"
23
24
  product_events.
24
25
  map { |event| OpenStruct.new(event) }.
@@ -31,7 +32,6 @@ all_events.group_by { |e| e[:consumer] }.each do |consumer, app_events|
31
32
  end
32
33
  puts
33
34
  end
34
-
35
35
  end
36
36
  puts
37
37
  end
@@ -104,7 +104,7 @@ module Vault::Usage
104
104
  # ...}},
105
105
  # ...]}
106
106
  # ```
107
- def usage_for_user(user_hid, start_time, stop_time, exclude=nil)
107
+ def usage_for_user(user_hid, start_time, stop_time, exclude=nil, callback_url = nil)
108
108
  unless start_time.zone.eql?('UTC')
109
109
  raise InvalidTimeError.new('Start time must be in UTC.')
110
110
  end
@@ -113,12 +113,16 @@ module Vault::Usage
113
113
  end
114
114
  path = "/users/#{user_hid}/usage/#{iso_format(start_time)}/" +
115
115
  "#{iso_format(stop_time)}"
116
+ query = {}
116
117
  unless exclude.nil? || exclude.empty?
117
- query = {exclude: exclude.join(',')}
118
+ query[:exclude] = exclude.join(',')
118
119
  end
120
+ query[:callback_url] = callback_url if callback_url
119
121
  connection = Excon.new(@url)
120
122
  response = connection.get(path: path, expects: [200], query: query)
121
- events = JSON.parse(response.body, {symbolize_keys: true})
123
+ payload = JSON.parse(response.body, {symbolize_keys: true})
124
+ return payload[:job_id] if payload[:job_id]
125
+ events = payload[:events]
122
126
  events.each do |event|
123
127
  event.each do |key, value|
124
128
  event[key] = parse_date(value) if date?(value)
@@ -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.1'
5
+ VERSION = '0.0.4'
6
6
  end
7
7
  end
8
8
  end
@@ -1,6 +1,3 @@
1
- require 'bundler'
2
- Bundler.require :default, ENV['RACK_ENV'].to_sym
3
-
4
1
  require 'excon'
5
2
  require 'yajl/json_gem'
6
3
 
data/test/client_test.rb CHANGED
@@ -47,7 +47,8 @@ class ClientTest < Vault::TestCase
47
47
  Excon.stub(method: :put) do |request|
48
48
  assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
49
49
  request[:headers]['Authorization'])
50
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
50
+ assert_equal('vault-usage.herokuapp.com', request[:host])
51
+ assert_equal('443', request[:port])
51
52
  assert_equal("/products/#{@product_name}/usage/#{@app_hid}" +
52
53
  "/events/#{@event_id}/open/#{iso_format(@start_time)}",
53
54
  request[:path])
@@ -103,7 +104,8 @@ class ClientTest < Vault::TestCase
103
104
  Excon.stub(method: :put) do |request|
104
105
  assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
105
106
  request[:headers]['Authorization'])
106
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
107
+ assert_equal('vault-usage.herokuapp.com', request[:host])
108
+ assert_equal('443', request[:port])
107
109
  assert_equal("/products/#{@product_name}/usage/#{@app_hid}" +
108
110
  "/events/#{@event_id}/close/#{iso_format(@stop_time)}",
109
111
  request[:path])
@@ -144,12 +146,13 @@ class ClientTest < Vault::TestCase
144
146
  Excon.stub(method: :get) do |request|
145
147
  assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
146
148
  request[:headers]['Authorization'])
147
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
149
+ assert_equal('vault-usage.herokuapp.com', request[:host])
150
+ assert_equal('443', request[:port])
148
151
  assert_equal("/users/#{@user_hid}/usage/#{iso_format(@start_time)}/" +
149
152
  "#{iso_format(@stop_time)}",
150
153
  request[:path])
151
154
  Excon.stubs.pop
152
- {status: 200, body: JSON.generate([])}
155
+ {status: 200, body: JSON.generate({events: []})}
153
156
  end
154
157
  assert_equal([], @client.usage_for_user(@user_hid, @start_time,
155
158
  @stop_time))
@@ -161,12 +164,22 @@ class ClientTest < Vault::TestCase
161
164
  Excon.stub(method: :get) do |request|
162
165
  assert_equal({exclude: 'platform:dyno:physical'}, request[:query])
163
166
  Excon.stubs.pop
164
- {status: 200, body: JSON.generate([])}
167
+ {status: 200, body: JSON.generate({events: []})}
165
168
  end
166
169
  assert_equal([], @client.usage_for_user(@user_hid, @start_time, @stop_time,
167
170
  ['platform:dyno:physical']))
168
171
  end
169
172
 
173
+ def test_usage_for_user_with_callback_url
174
+ Excon.stub(method: :get) do |request|
175
+ assert_equal({callback_url: 'http://example.com'}, request[:query])
176
+ Excon.stubs.pop
177
+ {status: 200, body: JSON.generate({job_id: 'DEADBEEF'})}
178
+ end
179
+ assert_equal('DEADBEEF',
180
+ @client.usage_for_user(@user_hid, @start_time, @stop_time, nil,'http://example.com'))
181
+ end
182
+
170
183
  # Client.usage_for_user comma-separates product names, when many are
171
184
  # provided in the exclusion list, and passes them to the server using a
172
185
  # single query argument.
@@ -175,7 +188,7 @@ class ClientTest < Vault::TestCase
175
188
  assert_equal({exclude: 'platform:dyno:physical,addons:memcache:100mb'},
176
189
  request[:query])
177
190
  Excon.stubs.pop
178
- {status: 200, body: JSON.generate([])}
191
+ {status: 200, body: JSON.generate({events: []})}
179
192
  end
180
193
  assert_equal([], @client.usage_for_user(@user_hid, @start_time, @stop_time,
181
194
  ['platform:dyno:physical',
@@ -186,9 +199,9 @@ class ClientTest < Vault::TestCase
186
199
  # not passing one at all.
187
200
  def test_usage_for_user_with_empty_exclude
188
201
  Excon.stub(method: :get) do |request|
189
- assert_equal(nil, request[:query])
202
+ assert_equal({}, request[:query])
190
203
  Excon.stubs.pop
191
- {status: 200, body: JSON.generate([])}
204
+ {status: 200, body: JSON.generate({events: []})}
192
205
  end
193
206
  assert_equal([], @client.usage_for_user(@user_hid, @start_time, @stop_time,
194
207
  []))
@@ -205,7 +218,7 @@ class ClientTest < Vault::TestCase
205
218
  start_time: iso_format(@start_time),
206
219
  stop_time: iso_format(@stop_time),
207
220
  detail: {}}]
208
- {status: 200, body: JSON.generate(events)}
221
+ {status: 200, body: JSON.generate({events: events})}
209
222
  end
210
223
  assert_equal([{id: @event_id,
211
224
  product: @product_name,
@@ -256,7 +269,8 @@ class ClientTest < Vault::TestCase
256
269
  Excon.stub(method: :put) do |request|
257
270
  assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
258
271
  request[:headers]['Authorization'])
259
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
272
+ assert_equal('vault-usage.herokuapp.com', request[:host])
273
+ assert_equal('443', request[:port])
260
274
  assert_equal("/users/#{@user_hid}/apps/#{@app_hid}/open/#{@event_id}" +
261
275
  "/#{iso_format(@start_time)}",
262
276
  request[:path])
@@ -300,7 +314,8 @@ class ClientTest < Vault::TestCase
300
314
  Excon.stub(method: :put) do |request|
301
315
  assert_equal('Basic dXNlcm5hbWU6c2VjcmV0',
302
316
  request[:headers]['Authorization'])
303
- assert_equal('vault-usage.herokuapp.com:443', request[:host_port])
317
+ assert_equal('vault-usage.herokuapp.com', request[:host])
318
+ assert_equal('443', request[:port])
304
319
  assert_equal("/users/#{@user_hid}/apps/#{@app_hid}/close/#{@event_id}" +
305
320
  "/#{iso_format(@stop_time)}",
306
321
  request[:path])
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.files = `git ls-files`.split($/)
15
15
  gem.test_files = gem.files.grep('^(test|spec|features)/')
16
16
  gem.require_paths = ["lib"]
17
+ gem.executables = ['vault-usage']
17
18
 
18
19
  gem.add_dependency 'excon'
19
20
  gem.add_dependency 'yajl-ruby'
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.1
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-21 00:00:00.000000000 Z
13
+ date: 2013-05-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: excon
@@ -64,7 +64,8 @@ description: Client for Vault::Usage
64
64
  email:
65
65
  - csquared@heroku.com
66
66
  - jkakar@heroku.com
67
- executables: []
67
+ executables:
68
+ - vault-usage
68
69
  extensions: []
69
70
  extra_rdoc_files: []
70
71
  files:
@@ -96,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
97
  version: '0'
97
98
  segments:
98
99
  - 0
99
- hash: 3440025206376780543
100
+ hash: 255738031400131991
100
101
  required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  none: false
102
103
  requirements:
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  version: '0'
106
107
  segments:
107
108
  - 0
108
- hash: 3440025206376780543
109
+ hash: 255738031400131991
109
110
  requirements: []
110
111
  rubyforge_project:
111
112
  rubygems_version: 1.8.23