cctv 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +18 -0
- data/lib/cctv.rb +1 -0
- data/lib/cctv/tracker.rb +71 -0
- data/lib/cctv/version.rb +3 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea5396890e6c5aa727614abd94c3c2b830083f49
|
4
|
+
data.tar.gz: 5a1cca3a9453dcf97dd9049b6f16d0afbf0af409
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c93c6da1488a45d597d00a49bae45873bf9e13f743943ed94609ef9b91e9f7d159a9a3877057ab0060221de356f9f50b5ac5a4fe8a30ffe7bd9ebe0fc4e8940
|
7
|
+
data.tar.gz: 0e267618fd34510585335c2d734ef7c4695d070029b4de1d1ce885f4c1d4a3601880588fc2f3eec8c2fd6160efa956249e1da0ae6e8242bb6af3bab2b3c7af1b
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Lawson Kurtz of Viget Labs
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'CCTV'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
Bundler::GemHelper.install_tasks
|
18
|
+
|
data/lib/cctv.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cctv/tracker'
|
data/lib/cctv/tracker.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'aws-sdk-core'
|
2
|
+
|
3
|
+
module Cctv
|
4
|
+
class Tracker
|
5
|
+
def initialize(table_name, aws_config = {})
|
6
|
+
@table_name = table_name.to_s
|
7
|
+
|
8
|
+
access_key_id = aws_config.fetch(:access_key_id) { env.fetch('AWS_ACCESS_KEY_ID') }
|
9
|
+
secret_access_key = aws_config.fetch(:secret_access_key) { env.fetch('AWS_SECRET_ACCESS_KEY') }
|
10
|
+
region = aws_config.fetch(:region) { env.fetch('AWS_REGION') }
|
11
|
+
|
12
|
+
@client = Aws::DynamoDB::Client.new(
|
13
|
+
access_key_id: access_key_id,
|
14
|
+
secret_access_key: secret_access_key,
|
15
|
+
region: region
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def record_activity(target, actor, additional_data = {})
|
20
|
+
client.put_item(
|
21
|
+
table_name: table_name,
|
22
|
+
item: {
|
23
|
+
timestamp: Time.now.utc.to_i.to_s,
|
24
|
+
actor: actor.to_s,
|
25
|
+
target: target.to_s
|
26
|
+
}.merge(additional_data),
|
27
|
+
return_values: 'NONE',
|
28
|
+
return_consumed_capacity: 'TOTAL',
|
29
|
+
return_item_collection_metrics: 'NONE',
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def view_activity(target, time_period_range, params = {})
|
34
|
+
limit = params.fetch(:limit, 25)
|
35
|
+
consistent_read = params.fetch(:consistent_read, false)
|
36
|
+
scan_index_forward = params.fetch(:scan_index_forward, true)
|
37
|
+
attributes_to_get = params.fetch(:attributes_to_get, nil)
|
38
|
+
|
39
|
+
select = (attributes_to_get && attributes_to_get == :all) ? 'SPECIFIC_ATTRIBUTES' : 'ALL_ATTRIBUTES'
|
40
|
+
|
41
|
+
client.query(
|
42
|
+
table_name: table_name,
|
43
|
+
select: select,
|
44
|
+
attributes_to_get: attributes_to_get,
|
45
|
+
limit: limit,
|
46
|
+
consistent_read: consistent_read,
|
47
|
+
key_conditions: {
|
48
|
+
'target' => {
|
49
|
+
attribute_value_list: [
|
50
|
+
target.to_s,
|
51
|
+
],
|
52
|
+
comparison_operator: 'EQ',
|
53
|
+
},
|
54
|
+
'timestamp' => {
|
55
|
+
attribute_value_list: [
|
56
|
+
(time_period_range.min.to_i).to_s,
|
57
|
+
(time_period_range.max.to_i).to_s
|
58
|
+
],
|
59
|
+
comparison_operator: 'BETWEEN'
|
60
|
+
}
|
61
|
+
},
|
62
|
+
scan_index_forward: true,
|
63
|
+
return_consumed_capacity: 'TOTAL',
|
64
|
+
).items
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
attr_reader :client, :table_name
|
70
|
+
end
|
71
|
+
end
|
data/lib/cctv/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cctv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lawson Kurtz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: CCTV is an ultra-performant, DynamoDB-backed activity tracker.
|
42
|
+
email:
|
43
|
+
- lawson.kurtz@viget.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- Rakefile
|
50
|
+
- lib/cctv.rb
|
51
|
+
- lib/cctv/tracker.rb
|
52
|
+
- lib/cctv/version.rb
|
53
|
+
homepage: https://github.com/vigetlabs/cctv
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.2.1
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: A DynamoDB-backed activity tracker
|
77
|
+
test_files: []
|
78
|
+
has_rdoc:
|