boxr 0.16.0 → 0.17.0

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: 494422846efc6e36fe295cb8dc4dd7bdf9114a6c
4
- data.tar.gz: 55240e038b71694c743f95a12f76d0ddbb0c2a91
3
+ metadata.gz: 8ae5afb3d84f050d0294084395417af4b38e3036
4
+ data.tar.gz: 9e2e2a339d4839e4ce2f7a8d1a2fd191ef64a834
5
5
  SHA512:
6
- metadata.gz: 79e4e5e6423dab11ac3c7a4b67d4fd16027bdb32961a61537f1cdcf557f17fa1bb93e4964a084ad466b170b2c75abf9528c6cf10a97d287afa64abde0511751f
7
- data.tar.gz: b5770b393db4da331af34a32b9a2454e7efb55c3ed0ffbfc3d67ac8e3ca6d52f0bb351013f69a7ac658699498affb05567523b05303e4aa5d3e98ce66255bf7d
6
+ metadata.gz: f3bdf146ed55c4da53f519a6df8b1cda0c979be4c05b4b4232bc8852aca4435473953a7346f8455062fd571aac301409f751fc6ab6a92878ee500f8b34bec91a
7
+ data.tar.gz: 1462e2544c327bc4fc4ced82426ee8be6ceb853dbcb84b530a7b07456e6a67bb8a6f5d75e71fb918e8d0fe6ae022a352a2ae68d9f59d384dda4f7a5ea629765c
@@ -6,10 +6,9 @@ client = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'])
6
6
 
7
7
  now = Time.now
8
8
  start_date = now - (60*60*24) #one day ago
9
- end_date = now
10
9
 
11
10
  puts "fetching historic enterprise events..."
12
- result = client.enterprise_events(created_after: start_date, created_before: end_date)
11
+ result = client.enterprise_events(created_after: start_date, created_before: now)
13
12
 
14
13
  ap result.events.each{|event| ap event; puts;}
15
14
  output={count: result.events.count, next_stream_position: result.next_stream_position}
@@ -0,0 +1,54 @@
1
+ require 'dotenv'; Dotenv.load("../.env")
2
+ require 'boxr'
3
+ require 'twilio-ruby' #make sure you 'gem install twilio-ruby'
4
+
5
+ # Get your Account Sid, Auth Token, and phone number from twilio.com/user/account
6
+ TWILIO_PHONE_NUMBER= ENV['TWILIO_PHONE_NUMBER']
7
+ BOX_TRIGGER_EVENT = 'UPLOAD'
8
+
9
+ @twilio_client = Twilio::REST::Client.new(ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN'])
10
+ @box_client = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'])
11
+
12
+ def send_sms_to_box_user(recipient, message)
13
+ phone = @box_client.user(recipient, fields: [:phone]).phone
14
+ unless phone.nil? || phone.empty?
15
+ begin
16
+ full_phone = "+1#{phone}"
17
+ @twilio_client.account.messages.create(
18
+ from: ENV['TWILIO_PHONE_NUMBER'],
19
+ to: full_phone,
20
+ body: message
21
+ )
22
+ puts "Sent SMS to user #{recipient.name} at #{full_phone}"
23
+ rescue Twilio::REST::RequestError => e
24
+ puts e.message
25
+ end
26
+ end
27
+ end
28
+
29
+ #need to look back in time to make sure we get a valid stream position;
30
+ #normally your app will be persisting the last known stream position and you wouldn't have to look this up
31
+ now = Time.now
32
+ start_date = now - (60*60*24) #one day ago
33
+ result = @box_client.enterprise_events(created_after: start_date, created_before: now)
34
+
35
+ #now that we have the latest stream position let's start monitoring in real-time
36
+ @box_client.enterprise_events_stream(result.next_stream_position, event_type: BOX_TRIGGER_EVENT) do |result|
37
+ if result.events.count==0
38
+ puts "no new #{BOX_TRIGGER_EVENT} events..."
39
+ else
40
+ puts "detected #{result.events.count} new #{BOX_TRIGGER_EVENT}"
41
+ result.events.each do |e|
42
+ folder = @box_client.folder(e.source.parent)
43
+ message = "Document '#{e.source.item_name}' uploaded to folder '#{folder.name}' by #{e.created_by.name}"
44
+
45
+ #first notify the folder owner
46
+ send_sms_to_box_user(folder.owned_by, message)
47
+
48
+ #now notify collaborators
49
+ user_collabs = @box_client.folder_collaborations(folder).select{|c| c.accessible_by.type=='user'}
50
+ user_collabs.each{|c| send_sms_to_box_user(c.accessible_by, message)}
51
+ end
52
+ end
53
+ end
54
+
@@ -1,10 +1,12 @@
1
1
  module Boxr
2
2
  class Client
3
3
 
4
- def folder_collaborations(folder)
4
+ def folder_collaborations(folder, fields: [])
5
5
  folder_id = ensure_id(folder)
6
+ query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
6
7
  uri = "#{FOLDERS_URI}/#{folder_id}/collaborations"
7
- collaborations, response = get(uri)
8
+
9
+ collaborations, response = get(uri, query: query)
8
10
  collaborations['entries']
9
11
  end
10
12
 
@@ -52,8 +54,9 @@ module Boxr
52
54
  end
53
55
 
54
56
  #these are pending collaborations for the current user; use the As-User Header to request for different users
55
- def pending_collaborations
56
- query = {status: :pending}
57
+ def pending_collaborations(fields: [])
58
+ query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
59
+ query[:status] = :pending
57
60
  pending_collaborations, response = get(COLLABORATIONS_URI, query: query)
58
61
  pending_collaborations['entries']
59
62
  end
data/lib/boxr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "0.16.0"
2
+ VERSION = "0.17.0"
3
3
  end
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.16.0
4
+ version: 0.17.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-07 00:00:00.000000000 Z
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -166,6 +166,7 @@ files:
166
166
  - boxr.gemspec
167
167
  - examples/enterprise_events.rb
168
168
  - examples/oauth.rb
169
+ - examples/use_events_to_send_sms.rb
169
170
  - examples/user_events.rb
170
171
  - lib/boxr.rb
171
172
  - lib/boxr/auth.rb