boxr 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b149bf857a1d64b35578d649c769792c9569e1c2
4
- data.tar.gz: 1cba489db37903b1ceea8f90508687baf76521da
3
+ metadata.gz: 0379d9a2e8adda91ee993826569aad62126edc32
4
+ data.tar.gz: 293610fefe3d43d506fe1b0f1b724792ef77e2e1
5
5
  SHA512:
6
- metadata.gz: 6a9ff438d8b6a582d3e52bdea63457b874377b5c7290b945a3430241d308aa051cf6c9e0b4c8d929c273f411582d343f1c3ff7f79b3e217fccd27d61fe882e3b
7
- data.tar.gz: b6ffbfe77e2060e9d7a01d60eec9aca993181f22353282da8df4e86185d357f96eb4b0edff5af74adfb924bc5768a81dc20f61c2cf2e21882ebd8ba547d336f1
6
+ metadata.gz: 5756edcdb7821e4b2bad784e55d6359c1652a35e441eb6143be5bfb990800baeaeb88e7c8beba416ff3cb995e9ae7933504b0f5113d2526ad87c871bd92a8b42
7
+ data.tar.gz: 04d9a0b727ffd182e9e69be9995a9e53f81129369c05a611752ab646d3bcd33c2cc21ed153f844ce6c5614bfc23f6ae49d1db2adaed42b0561cd850dff03670e
data/README.md CHANGED
@@ -158,6 +158,10 @@ alias :file :file_from_id
158
158
 
159
159
  update_file(file, name: nil, description: nil, parent: nil, shared_link: nil, tags: nil, if_match: nil)
160
160
 
161
+ lock_file(file, expires_at: nil, is_download_prevented: false, if_match: nil)
162
+
163
+ unlock_file(file, if_match: nil)
164
+
161
165
  move_file(file, new_parent, name: nil, if_match: nil)
162
166
 
163
167
  download_file(file, version: nil, follow_redirect: true)
@@ -261,6 +265,12 @@ update_user(user, notify: nil, enterprise: true, name: nil, role: nil, language:
261
265
  can_see_managed_users: nil, status: nil, timezone: nil, is_exempt_from_device_limits: nil,
262
266
  is_exempt_from_login_verification: nil, is_exempt_from_reset_required: nil, is_external_collab_restricted: nil)
263
267
 
268
+ email_aliases_for_user(user)
269
+
270
+ add_email_alias_for_user(user, email)
271
+
272
+ remove_email_alias_for_user(user, email_alias)
273
+
264
274
  delete_user(user, notify: nil, force: nil)
265
275
  ```
266
276
  #### [Groups](https://developers.box.com/docs/#groups)
data/bin/boxr ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'boxr'
4
+ require 'dotenv'; Dotenv.load
5
+ require 'awesome_print'
6
+ require 'irb'
7
+
8
+ $boxr = Boxr::Client.new #uses ENV['BOX_DEVELOPER_TOKEN']
9
+ IRB.start
@@ -4,7 +4,7 @@ require 'awesome_print'
4
4
 
5
5
  client = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'])
6
6
 
7
- now = Time.now
7
+ now = Time.now.utc
8
8
  start_date = now - (60*60*24) #one day ago
9
9
 
10
10
  puts "fetching historic enterprise events..."
@@ -16,8 +16,8 @@ ap output
16
16
 
17
17
  #now that we have the latest stream position let's start monitoring in real-time
18
18
  puts "listening for new enterprise events..."
19
- client.enterprise_events_stream(result.next_stream_position) do |result|
20
- result.events.each{|e| puts e.event_type}
19
+ client.enterprise_events_stream(result.next_stream_position, refresh_period: 5) do |result|
20
+ result.events.each{|e| ap e}
21
21
  output={count: result.events.count, next_stream_position: result.next_stream_position}
22
22
  ap output
23
23
  puts "waiting..."
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  #need to look back in time to make sure we get a valid stream position;
35
35
  #normally your app will be persisting the last known stream position and you wouldn't have to look this up
36
- now = Time.now
36
+ now = Time.now.utc
37
37
  start_date = now - (60*60*24) #one day ago
38
38
  result = @box_client.enterprise_events(created_after: start_date, created_before: now)
39
39
 
@@ -56,7 +56,7 @@ end
56
56
 
57
57
  #need to look back in time to make sure we get a valid stream position;
58
58
  #normally your app will be persisting the last known stream position and you wouldn't have to look this up
59
- now = Time.now
59
+ now = Time.now.utc
60
60
  start_date = now - (60*60*24) #one day ago
61
61
  result = @box_client.enterprise_events(created_after: start_date, created_before: now)
62
62
 
data/lib/boxr.rb CHANGED
@@ -43,6 +43,7 @@ module Boxr
43
43
  #HTTPClient is high-performance, thread-safe, and supports persistent HTTPS connections
44
44
  #http://bibwild.wordpress.com/2012/04/30/ruby-http-performance-shootout-redux/
45
45
  BOX_CLIENT = HTTPClient.new
46
+ BOX_CLIENT.cookie_manager = nil
46
47
  BOX_CLIENT.send_timeout = 3600 #one hour; needed for lengthy uploads
47
48
  BOX_CLIENT.agent_name = "Boxr/#{Boxr::VERSION}"
48
49
  BOX_CLIENT.transparent_gzip_decompression = true
@@ -10,7 +10,6 @@ module Boxr
10
10
  collaborations['entries']
11
11
  end
12
12
 
13
- #make sure 'role' value is a string as Box has role values with spaces and dashes; e.g. 'previewer uploader'
14
13
  def add_collaboration(folder, accessible_by, role, fields: [], notify: nil)
15
14
  folder_id = ensure_id(folder)
16
15
  query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
data/lib/boxr/files.rb CHANGED
@@ -26,7 +26,7 @@ module Boxr
26
26
  end
27
27
  alias :file :file_from_id
28
28
 
29
- def update_file(file, name: nil, description: nil, parent: nil, shared_link: nil, tags: nil, if_match: nil)
29
+ def update_file(file, name: nil, description: nil, parent: nil, shared_link: nil, tags: nil, lock: nil, if_match: nil)
30
30
  file_id = ensure_id(file)
31
31
  parent_id = ensure_id(parent)
32
32
  uri = "#{FILES_URI}/#{file_id}"
@@ -37,6 +37,24 @@ module Boxr
37
37
  attributes[:parent] = {id: parent_id} unless parent_id.nil?
38
38
  attributes[:shared_link] = shared_link unless shared_link.nil?
39
39
  attributes[:tags] = tags unless tags.nil?
40
+ attributes[:lock] = lock unless lock.nil?
41
+
42
+ updated_file, response = put(uri, attributes, if_match: if_match)
43
+ updated_file
44
+ end
45
+
46
+ def lock_file(file, expires_at: nil, is_download_prevented: false, if_match: nil)
47
+ lock = {type: "lock"}
48
+ lock[:expires_at] = expires_at.to_datetime.rfc3339 unless expires_at.nil?
49
+ lock[:is_download_prevented] = is_download_prevented unless is_download_prevented.nil?
50
+
51
+ update_file(file, lock: lock, if_match: if_match)
52
+ end
53
+
54
+ def unlock_file(file, if_match: nil)
55
+ file_id = ensure_id(file)
56
+ uri = "#{FILES_URI}/#{file_id}"
57
+ attributes = {lock: nil}
40
58
 
41
59
  updated_file, response = put(uri, attributes, if_match: if_match)
42
60
  updated_file
data/lib/boxr/users.rb CHANGED
@@ -4,6 +4,7 @@ module Boxr
4
4
  def current_user(fields: [])
5
5
  uri = "#{USERS_URI}/me"
6
6
  query = build_fields_query(fields, USER_FIELDS_QUERY)
7
+
7
8
  user, response = get(uri, query: query)
8
9
  user
9
10
  end
@@ -13,6 +14,7 @@ module Boxr
13
14
  user_id = ensure_id(user_id)
14
15
  uri = "#{USERS_URI}/#{user_id}"
15
16
  query = build_fields_query(fields, USER_FIELDS_QUERY)
17
+
16
18
  user, response = get(uri, query: query)
17
19
  user
18
20
  end
@@ -28,6 +30,7 @@ module Boxr
28
30
  else
29
31
  query[:offset] = offset
30
32
  query[:limit] = limit
33
+
31
34
  users, response = get(uri, query: query)
32
35
  users['entries']
33
36
  end
@@ -97,9 +100,36 @@ module Boxr
97
100
  query = {}
98
101
  query[:notify] = notify unless notify.nil?
99
102
  query[:force] = force unless force.nil?
103
+
100
104
  result, response = delete(uri, query: query)
101
105
  result
102
106
  end
103
107
 
108
+ def email_aliases_for_user(user)
109
+ user_id = ensure_id(user)
110
+ uri = "#{USERS_URI}/#{user_id}/email_aliases"
111
+
112
+ aliases, response = get(uri)
113
+ aliases['entries']
114
+ end
115
+
116
+ def add_email_alias_for_user(user, email)
117
+ user_id = ensure_id(user)
118
+ uri = "#{USERS_URI}/#{user_id}/email_aliases"
119
+ attributes = {email: email}
120
+
121
+ updated_user, response = post(uri, attributes)
122
+ updated_user
123
+ end
124
+
125
+ def remove_email_alias_for_user(user, email_alias)
126
+ user_id = ensure_id(user)
127
+ email_alias_id = ensure_id(email_alias)
128
+ uri = "#{USERS_URI}/#{user_id}/email_aliases/#{email_alias_id}"
129
+
130
+ result, response = delete(uri)
131
+ result
132
+ end
133
+
104
134
  end
105
135
  end
data/lib/boxr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "0.19.0"
2
+ VERSION = "0.20.0"
3
3
  end
data/spec/boxr_spec.rb CHANGED
@@ -46,9 +46,9 @@ describe Boxr::Client do
46
46
  @test_folder = new_folder
47
47
 
48
48
  all_users = BOX_CLIENT.all_users
49
- test_user = all_users.find{|u| u.name == TEST_USER_NAME}
50
- if(test_user)
51
- BOX_CLIENT.delete_user(test_user, force: true)
49
+ test_users = all_users.select{|u| u.name == TEST_USER_NAME}
50
+ test_users.each do |u|
51
+ BOX_CLIENT.delete_user(u, force: true)
52
52
  end
53
53
  sleep BOX_SERVER_SLEEP
54
54
  test_user = BOX_CLIENT.create_user(TEST_USER_LOGIN, TEST_USER_NAME)
@@ -148,8 +148,24 @@ describe Boxr::Client do
148
148
 
149
149
  puts "update file"
150
150
  new_description = 'this file is used to test Boxr'
151
- updated_file_info = BOX_CLIENT.update_file(test_file, description: new_description)
151
+ tags = ['tag one','tag two']
152
+ updated_file_info = BOX_CLIENT.update_file(test_file, description: new_description, tags: tags)
152
153
  expect(updated_file_info.description).to eq(new_description)
154
+ tag_file_info = BOX_CLIENT.file(updated_file_info, fields: [:tags])
155
+ expect(tag_file_info.tags.length).to eq(2)
156
+
157
+ puts "lock file"
158
+ expires_at_utc = Time.now.utc + (60*60*24) #one day from now
159
+ locked_file = BOX_CLIENT.lock_file(test_file, expires_at: expires_at_utc, is_download_prevented: true)
160
+ locked_file = BOX_CLIENT.file(locked_file, fields: [:lock])
161
+ expect(locked_file.lock.type).to eq('lock')
162
+ expect(locked_file.lock.expires_at).to_not be_nil
163
+ expect(locked_file.lock.is_download_prevented).to eq(true)
164
+
165
+ puts "unlock file"
166
+ unlocked_file = BOX_CLIENT.unlock_file(locked_file)
167
+ unlocked_file = BOX_CLIENT.file(unlocked_file, fields: [:lock])
168
+ expect(unlocked_file.lock).to be_nil
153
169
 
154
170
  puts "download file"
155
171
  file = BOX_CLIENT.download_file(test_file)
@@ -236,12 +252,25 @@ describe Boxr::Client do
236
252
  test_user = all_users.find{|u| u.id == @test_user.id}
237
253
  expect(test_user).to_not be_nil
238
254
 
255
+ #create user is tested in the before method
256
+
239
257
  puts "update user"
240
258
  new_name = "Chuck Nevitt"
241
259
  user = BOX_CLIENT.update_user(@test_user, name: new_name)
242
260
  expect(user.name).to eq(new_name)
243
261
 
244
- #create user is tested in the before method
262
+ puts "add email alias for user"
263
+ email_alias = "test-boxr-user-alias@boxntest.com" #{('a'..'z').to_a.shuffle[0,10].join}.com"
264
+ new_alias = BOX_CLIENT.add_email_alias_for_user(@test_user, email_alias)
265
+ expect(new_alias.type).to eq('email_alias')
266
+
267
+ puts "get email aliases for user"
268
+ email_aliases = BOX_CLIENT.email_aliases_for_user(@test_user)
269
+ expect(email_aliases.first.id).to eq(new_alias.id)
270
+
271
+ puts "remove email alias for user"
272
+ result = BOX_CLIENT.remove_email_alias_for_user(@test_user, new_alias.id)
273
+ expect(result).to eq({})
245
274
 
246
275
  puts "delete user"
247
276
  result = BOX_CLIENT.delete_user(@test_user, force: true)
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.19.0
4
+ version: 0.20.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-25 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -167,7 +167,8 @@ dependencies:
167
167
  description: ''
168
168
  email:
169
169
  - chadburnette@me.com
170
- executables: []
170
+ executables:
171
+ - boxr
171
172
  extensions: []
172
173
  extra_rdoc_files: []
173
174
  files:
@@ -177,6 +178,7 @@ files:
177
178
  - LICENSE.txt
178
179
  - README.md
179
180
  - Rakefile
181
+ - bin/boxr
180
182
  - boxr.gemspec
181
183
  - examples/enterprise_events.rb
182
184
  - examples/oauth.rb