boxr 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/boxr.gemspec +1 -1
- data/examples/enterprise_events.rb +15 -3
- data/examples/user_events.rb +6 -7
- data/lib/boxr/events.rb +17 -6
- data/lib/boxr/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 494422846efc6e36fe295cb8dc4dd7bdf9114a6c
|
4
|
+
data.tar.gz: 55240e038b71694c743f95a12f76d0ddbb0c2a91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79e4e5e6423dab11ac3c7a4b67d4fd16027bdb32961a61537f1cdcf557f17fa1bb93e4964a084ad466b170b2c75abf9528c6cf10a97d287afa64abde0511751f
|
7
|
+
data.tar.gz: b5770b393db4da331af34a32b9a2454e7efb55c3ed0ffbfc3d67ac8e3ca6d52f0bb351013f69a7ac658699498affb05567523b05303e4aa5d3e98ce66255bf7d
|
data/README.md
CHANGED
@@ -221,9 +221,11 @@ pending_collaborations()
|
|
221
221
|
```
|
222
222
|
#### [Events](https://developers.box.com/docs/#events)
|
223
223
|
```ruby
|
224
|
-
user_events(stream_position
|
224
|
+
user_events(stream_position, stream_type: :all, limit: 100)
|
225
225
|
|
226
|
-
enterprise_events(created_after, created_before)
|
226
|
+
enterprise_events(created_after: nil, created_before: nil, stream_position: 0, event_type: nil, limit: 100)
|
227
|
+
|
228
|
+
enterprise_events_stream(initial_stream_position, event_type: nil, limit: 100, refresh_period: 5)
|
227
229
|
```
|
228
230
|
#### [Shared Items](https://developers.box.com/docs/#shared-items)
|
229
231
|
```ruby
|
data/boxr.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "simplecov", "~> 0.9"
|
27
27
|
spec.add_development_dependency "dotenv", "~> 0.11"
|
28
28
|
spec.add_development_dependency "awesome_print"
|
29
|
-
spec.add_development_dependency "lru_redux"
|
29
|
+
spec.add_development_dependency "lru_redux", "~> 0.8"
|
30
30
|
|
31
31
|
spec.add_runtime_dependency "oj", "~> 2.11"
|
32
32
|
spec.add_runtime_dependency "httpclient", "~> 2.5"
|
@@ -8,6 +8,18 @@ now = Time.now
|
|
8
8
|
start_date = now - (60*60*24) #one day ago
|
9
9
|
end_date = now
|
10
10
|
|
11
|
-
puts "fetching enterprise events..."
|
12
|
-
|
13
|
-
|
11
|
+
puts "fetching historic enterprise events..."
|
12
|
+
result = client.enterprise_events(created_after: start_date, created_before: end_date)
|
13
|
+
|
14
|
+
ap result.events.each{|event| ap event; puts;}
|
15
|
+
output={count: result.events.count, next_stream_position: result.next_stream_position}
|
16
|
+
ap output
|
17
|
+
|
18
|
+
#now that we have the latest stream position let's start monitoring in real-time
|
19
|
+
puts "listening for new enterprise events..."
|
20
|
+
client.enterprise_events_stream(result.next_stream_position) do |result|
|
21
|
+
result.events.each{|e| puts e.event_type}
|
22
|
+
output={count: result.events.count, next_stream_position: result.next_stream_position}
|
23
|
+
ap output
|
24
|
+
puts "waiting..."
|
25
|
+
end
|
data/examples/user_events.rb
CHANGED
@@ -9,16 +9,15 @@ cache = LruRedux::Cache.new(1000)
|
|
9
9
|
stream_position = :now
|
10
10
|
loop do
|
11
11
|
puts "fetching events..."
|
12
|
-
event_response = client.user_events(stream_position
|
12
|
+
event_response = client.user_events(stream_position)
|
13
13
|
event_response.events.each do |event|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
cache[event.event_id] = true
|
14
|
+
#we need to de-dupe the events because we will receive multiple events with the same event_id; Box does this to ensure that we get the event
|
15
|
+
key = "/box-event/#{event.event_id}"
|
16
|
+
if (cache.fetch(key)==nil)
|
17
|
+
cache[key] = true
|
19
18
|
puts event.event_type
|
20
19
|
end
|
21
20
|
end
|
22
21
|
stream_position = event_response.next_stream_position
|
23
|
-
sleep
|
22
|
+
sleep 5
|
24
23
|
end
|
data/lib/boxr/events.rb
CHANGED
@@ -1,30 +1,41 @@
|
|
1
1
|
module Boxr
|
2
2
|
class Client
|
3
3
|
|
4
|
-
def user_events(stream_position
|
4
|
+
def user_events(stream_position, stream_type: :all, limit: 100)
|
5
5
|
query = {stream_position: stream_position, stream_type: stream_type, limit: limit}
|
6
6
|
|
7
7
|
events, response = get(EVENTS_URI, query: query)
|
8
8
|
Hashie::Mash.new({events: events["entries"], chunk_size: events["chunk_size"], next_stream_position: events["next_stream_position"]})
|
9
9
|
end
|
10
10
|
|
11
|
-
def enterprise_events(created_after, created_before, event_type: nil, limit: 100)
|
11
|
+
def enterprise_events(created_after: nil, created_before: nil, stream_position: 0, event_type: nil, limit: 100)
|
12
12
|
events = []
|
13
|
-
stream_position = 0
|
14
13
|
loop do
|
15
|
-
event_response =
|
14
|
+
event_response = get_enterprise_events(created_after, created_before, stream_position, event_type, limit)
|
16
15
|
event_response.events.each{|event| events << event}
|
17
16
|
stream_position = event_response.next_stream_position
|
18
17
|
|
19
18
|
break if event_response.events.empty?
|
20
19
|
end
|
21
|
-
events
|
20
|
+
Hashie::Mash.new({events: events, next_stream_position: stream_position})
|
21
|
+
end
|
22
|
+
|
23
|
+
def enterprise_events_stream(initial_stream_position, event_type: nil, limit: 100, refresh_period: 5)
|
24
|
+
stream_position = initial_stream_position
|
25
|
+
loop do
|
26
|
+
response = enterprise_events(stream_position: stream_position, event_type: event_type, limit: limit)
|
27
|
+
|
28
|
+
yield(response) if block_given?
|
29
|
+
|
30
|
+
stream_position = response.next_stream_position
|
31
|
+
sleep refresh_period
|
32
|
+
end
|
22
33
|
end
|
23
34
|
|
24
35
|
|
25
36
|
private
|
26
37
|
|
27
|
-
def
|
38
|
+
def get_enterprise_events(created_after, created_before, stream_position, event_type, limit)
|
28
39
|
query = {stream_position: stream_position, stream_type: :admin_logs, limit: limit}
|
29
40
|
query['event_type'] = event_type unless event_type.nil?
|
30
41
|
query['created_after'] = created_after.to_datetime.rfc3339 unless created_after.nil?
|
data/lib/boxr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Burnette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: lru_redux
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
103
|
+
version: '0.8'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
110
|
+
version: '0.8'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: oj
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|