boxr 1.1.0 → 1.2.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: dabf6e02613d429dee655d87eaacacdd8bba2386
4
- data.tar.gz: d5f56cea3324cdadc93ace1b5d06aaf57f127f0b
3
+ metadata.gz: 6b219a0546f48304aa3786f78c7fee4633b2a93e
4
+ data.tar.gz: 24e175d1d4d4164c7d9fe493ffe58e9961e6ee68
5
5
  SHA512:
6
- metadata.gz: 5560f56757e1b129227fc0303fdb708054dc673f04afb262dc83dd4efe547f254c58d5ac71b4c9924990d18d1ba5e4e217ce4aa8c5ff7e56e02a91197f748fec
7
- data.tar.gz: dea07c12287232c34ca1be07d38c9a6b34677ca5d3048c35ac23b09004115e67091c53eb4c5d0e110606a89d5d27741a7f5b230e756cb25c6fdfb426f2f1ce21
6
+ metadata.gz: a1ae72b408546796a1f22e3870afd2b2adecc2cd8016269d64df8849662dbf8eeb45e076987cbe9f8ad88a199403be98896e01fd491905f84798a3fc9a2028b4
7
+ data.tar.gz: 5532462b58dca43097386ba4ccdf52d0f04b3f318dbe160548903075bc333a3433023c4223ee8a2a929fd0462a8a0b99f296be9311e05b06bbfcbb1b9268a7cb
data/README.md CHANGED
@@ -368,6 +368,16 @@ enterprise_metadata
368
368
 
369
369
  metadata_schema(scope, template_key)
370
370
  ```
371
+ #### [Web Links](https://box-content.readme.io/reference#web-link-object)
372
+ ```ruby
373
+ create_web_link(url, parent, name: nil, description: nil)
374
+
375
+ get_web_link(web_link)
376
+
377
+ update_web_link(web_link_id, url: nil, parent: nil, name: nil, description: nil)
378
+
379
+ delete_web_link(web_link)
380
+ ```
371
381
  ## Contributing
372
382
 
373
383
  1. Fork it ( https://github.com/cburnette/boxr/fork )
data/Rakefile CHANGED
@@ -8,4 +8,3 @@ RSpec::Core::RakeTask.new(:spec) do |task|
8
8
  end
9
9
 
10
10
  task :default => :spec
11
-
data/bin/boxr CHANGED
@@ -6,4 +6,4 @@ require 'awesome_print'
6
6
  require 'irb'
7
7
 
8
8
  $boxr = Boxr::Client.new #uses ENV['BOX_DEVELOPER_TOKEN']
9
- IRB.start
9
+ IRB.start
@@ -21,6 +21,7 @@ require 'boxr/tasks'
21
21
  require 'boxr/metadata'
22
22
  require 'boxr/events'
23
23
  require 'boxr/auth'
24
+ require 'boxr/web_links'
24
25
 
25
26
  module Enumerable
26
27
  def files
@@ -58,7 +59,7 @@ module Boxr
58
59
  BOX_CLIENT.cookie_manager = nil
59
60
  BOX_CLIENT.send_timeout = 3600 #one hour; needed for lengthy uploads
60
61
  BOX_CLIENT.agent_name = "Boxr/#{Boxr::VERSION}"
61
- BOX_CLIENT.transparent_gzip_decompression = true
62
+ BOX_CLIENT.transparent_gzip_decompression = true
62
63
  #BOX_CLIENT.ssl_config.add_trust_ca("/Users/cburnette/code/ssh-keys/dev_root_ca.pem")
63
64
 
64
65
  def self.turn_on_debugging(device=STDOUT)
@@ -72,4 +73,4 @@ module Boxr
72
73
  BOX_CLIENT.transparent_gzip_decompression = true
73
74
  nil
74
75
  end
75
- end
76
+ end
@@ -1,5 +1,5 @@
1
1
  module Boxr
2
-
2
+
3
3
  class Client
4
4
 
5
5
  attr_reader :access_token, :refresh_token, :client_id, :client_secret, :identifier, :as_user_id
@@ -26,6 +26,7 @@ module Boxr
26
26
  FOLDER_METADATA_URI = "#{API_URI}/folders"
27
27
  METADATA_TEMPLATES_URI = "#{API_URI}/metadata_templates"
28
28
  EVENTS_URI = "#{API_URI}/events"
29
+ WEB_LINKS_URI = "#{API_URI}/web_links"
29
30
 
30
31
 
31
32
  DEFAULT_LIMIT = 100
@@ -35,13 +36,12 @@ module Boxr
35
36
  :size,:path_collection,:created_by,:modified_by,:trashed_at,:purged_at,
36
37
  :content_created_at,:content_modified_at,:owned_by,:shared_link,:folder_upload_email,
37
38
  :parent,:item_status,:item_collection,:sync_state,:has_collaborations,:permissions,:tags,
38
- :sha1,:shared_link,:version_number,:comment_count,:lock,:extension,:is_package,
39
- :expiring_embed_link, :can_non_owners_invite]
39
+ :sha1,:shared_link,:version_number,:comment_count,:lock,:extension,:is_package,:can_non_owners_invite]
40
40
  FOLDER_AND_FILE_FIELDS_QUERY = FOLDER_AND_FILE_FIELDS.join(',')
41
41
 
42
42
  COMMENT_FIELDS = [:type,:id,:is_reply_comment,:message,:tagged_message,:created_by,:created_at,:item,:modified_at]
43
43
  COMMENT_FIELDS_QUERY = COMMENT_FIELDS.join(',')
44
-
44
+
45
45
  TASK_FIELDS = [:type,:id,:item,:due_at,:action,:message,:task_assignment_collection,:is_completed,:created_by,:created_at]
46
46
  TASK_FIELDS_QUERY = TASK_FIELDS.join(',')
47
47
 
@@ -58,18 +58,18 @@ module Boxr
58
58
  GROUP_FIELDS_QUERY = GROUP_FIELDS.join(',')
59
59
 
60
60
  VALID_COLLABORATION_ROLES = ['editor','viewer','previewer','uploader','previewer uploader','viewer uploader','co-owner','owner']
61
-
62
61
 
63
- def initialize( access_token=ENV['BOX_DEVELOPER_TOKEN'],
64
- refresh_token: nil,
65
- client_id: ENV['BOX_CLIENT_ID'],
62
+
63
+ def initialize( access_token=ENV['BOX_DEVELOPER_TOKEN'],
64
+ refresh_token: nil,
65
+ client_id: ENV['BOX_CLIENT_ID'],
66
66
  client_secret: ENV['BOX_CLIENT_SECRET'],
67
67
  enterprise_id: ENV['BOX_ENTERPRISE_ID'],
68
- jwt_private_key: ENV['JWT_PRIVATE_KEY'],
68
+ jwt_private_key: ENV['JWT_PRIVATE_KEY'],
69
69
  jwt_private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'],
70
70
  jwt_public_key_id: ENV['JWT_PUBLIC_KEY_ID'],
71
- identifier: nil,
72
- as_user: nil,
71
+ identifier: nil,
72
+ as_user: nil,
73
73
  &token_refresh_listener)
74
74
 
75
75
  @access_token = access_token
@@ -121,7 +121,7 @@ module Boxr
121
121
  headers = standard_headers
122
122
  BOX_CLIENT.get(uri, query: query, header: headers, follow_redirect: follow_redirect)
123
123
  end
124
-
124
+
125
125
  if (res.status==200)
126
126
  body_json = Oj.load(res.body)
127
127
  total_count = body_json["total_count"]
@@ -161,7 +161,7 @@ module Boxr
161
161
  headers = standard_headers
162
162
  headers['If-Match'] = if_match unless if_match.nil?
163
163
  headers["Content-Type"] = content_type unless content_type.nil?
164
-
164
+
165
165
  BOX_CLIENT.put(uri, body: Oj.dump(body), query: query, header: headers)
166
166
  end
167
167
 
@@ -176,7 +176,7 @@ module Boxr
176
176
  res = with_auto_token_refresh do
177
177
  headers = standard_headers
178
178
  headers['If-Match'] = if_match unless if_match.nil?
179
-
179
+
180
180
  BOX_CLIENT.delete(uri, query: query, header: headers)
181
181
  end
182
182
 
@@ -282,7 +282,7 @@ module Boxr
282
282
  attributes = {}
283
283
  attributes[:name] = name unless name.nil?
284
284
  attributes[:parent] = {id: parent_id} unless parent_id.nil?
285
-
285
+
286
286
  restored_item, response = post(uri, attributes)
287
287
  restored_item
288
288
  end
@@ -307,4 +307,4 @@ module Boxr
307
307
 
308
308
  end
309
309
 
310
- end
310
+ end
@@ -50,7 +50,7 @@ module Boxr
50
50
 
51
51
  uri = "#{FOLDERS_URI}"
52
52
  attributes = {:name => name, :parent => {:id => parent_id}}
53
-
53
+
54
54
  created_folder, response = post(uri, attributes)
55
55
  created_folder
56
56
  end
@@ -71,7 +71,7 @@ module Boxr
71
71
  attributes[:folder_upload_email] = {access: folder_upload_email_access} unless folder_upload_email_access.nil?
72
72
  attributes[:owned_by] = {id: owned_by_id} unless owned_by_id.nil?
73
73
  attributes[:sync_state] = sync_state unless sync_state.nil?
74
- attributes[:tags] = tags unless tags.nil?
74
+ attributes[:tags] = tags unless tags.nil?
75
75
  attributes[:can_non_owners_invite] = can_non_owners_invite unless can_non_owners_invite.nil?
76
76
 
77
77
  updated_folder, response = put(uri, attributes, if_match: if_match)
@@ -133,7 +133,7 @@ module Boxr
133
133
  folder_id = ensure_id(folder)
134
134
  uri = "#{FOLDERS_URI}/#{folder_id}/trash"
135
135
  query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
136
-
136
+
137
137
  folder, response = get(uri, query: query)
138
138
  folder
139
139
  end
@@ -154,4 +154,4 @@ module Boxr
154
154
  end
155
155
 
156
156
  end
157
- end
157
+ end
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,62 @@
1
+ module Boxr
2
+ class Client
3
+
4
+ def create_web_link(url, parent, name: nil, description: nil)
5
+
6
+ parent_id = ensure_id(parent)
7
+ web_link_url = verify_url(url)
8
+ uri = "#{WEB_LINKS_URI}"
9
+
10
+ attributes = {}
11
+ attributes[:url] = web_link_url
12
+ attributes[:parent] = {:id => parent_id}
13
+ attributes[:name] = name unless name.nil?
14
+ attributes[:description] = description unless description.nil?
15
+
16
+ created_link, response = post(uri, attributes)
17
+ created_link
18
+ end
19
+
20
+ def get_web_link(web_link)
21
+
22
+ web_link_id = ensure_id(web_link)
23
+ uri = "#{WEB_LINKS_URI}/#{web_link_id}"
24
+
25
+ web_link, response = get(uri)
26
+ web_link
27
+ end
28
+
29
+ def update_web_link(web_link, url: nil, parent: nil, name: nil, description: nil)
30
+
31
+ web_link_id = ensure_id(web_link)
32
+ parent_id = ensure_id(parent)
33
+ uri = "#{WEB_LINKS_URI}/#{web_link_id}"
34
+
35
+ attributes = {}
36
+ attributes[:url] = url unless url.nil?
37
+ attributes[:name] = name unless name.nil?
38
+ attributes[:description] = description unless description.nil?
39
+ attributes[:parent] = {id: parent_id} unless parent_id.nil?
40
+
41
+ updated_web_link, response = put(uri, attributes)
42
+ updated_web_link
43
+ end
44
+
45
+ def delete_web_link(web_link)
46
+
47
+ web_link_id = ensure_id(web_link)
48
+ uri = "#{WEB_LINKS_URI}/#{web_link_id}"
49
+
50
+ result, response = delete(uri)
51
+ result
52
+ end
53
+
54
+ private
55
+
56
+ def verify_url(item)
57
+ return item if item.class == String and (item.include? 'https://' or item.include? 'http://')
58
+ raise BoxrError.new(boxr_message: "Invalid url. Must include 'http://' or 'https://'")
59
+ end
60
+
61
+ end
62
+ end
@@ -18,7 +18,7 @@ describe Boxr::Client do
18
18
  BOX_CLIENT = Boxr::Client.new #using ENV['BOX_DEVELOPER_TOKEN']
19
19
 
20
20
  #uncomment this line to see the HTTP request and response debug info in the rspec output
21
- #Boxr::turn_on_debugging
21
+ # Boxr::turn_on_debugging
22
22
 
23
23
  BOX_SERVER_SLEEP = 5
24
24
  TEST_FOLDER_NAME = 'Boxr Test'
@@ -34,6 +34,8 @@ describe Boxr::Client do
34
34
  TEST_USER_NAME = "Test Boxr User"
35
35
  TEST_GROUP_NAME= "Test Boxr Group"
36
36
  TEST_TASK_MESSAGE = "Please review"
37
+ TEST_WEB_URL = 'https://www.box.com'
38
+ TEST_WEB_URL2 = 'https://www.google.com'
37
39
 
38
40
  before(:each) do
39
41
  puts "-----> Resetting Box Environment"
@@ -62,8 +64,8 @@ describe Boxr::Client do
62
64
  end
63
65
  end
64
66
 
65
- #use this command to just execute this scenario
66
- #rake spec SPEC_OPTS="-e \"invokes folder operations"\"
67
+ # use this command to just execute this scenario
68
+ # rake spec SPEC_OPTS="-e \"invokes folder operations"\"
67
69
  it 'invokes folder operations' do
68
70
  puts "get folder using path"
69
71
  folder = BOX_CLIENT.folder_from_path(TEST_FOLDER_NAME)
@@ -244,6 +246,25 @@ describe Boxr::Client do
244
246
  expect(result).to eq({})
245
247
  end
246
248
 
249
+ #rake spec SPEC_OPTS="-e \"invokes web links operations"\"
250
+ it 'invokes web links operations' do
251
+ puts "create web link"
252
+ web_link = BOX_CLIENT.create_web_link(TEST_WEB_URL, '0', name: "my new link", description: "link description...")
253
+ expect(web_link.url).to eq(TEST_WEB_URL)
254
+
255
+ puts "get web link"
256
+ web_link_new = BOX_CLIENT.get_web_link(web_link)
257
+ expect(web_link_new.id).to eq(web_link.id)
258
+
259
+ puts "update web link"
260
+ updated_web_link = BOX_CLIENT.update_web_link(web_link, name: 'new name', description: 'new description', url: TEST_WEB_URL2)
261
+ expect(updated_web_link.url).to eq(TEST_WEB_URL2)
262
+
263
+ puts "delete web link"
264
+ result = BOX_CLIENT.delete_web_link(web_link)
265
+ expect(result).to eq({})
266
+ end
267
+
247
268
  #rake spec SPEC_OPTS="-e \"invokes user operations"\"
248
269
  it "invokes user operations" do
249
270
  puts "inspect current user"
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: 1.1.0
4
+ version: 1.2.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: 2016-05-18 00:00:00.000000000 Z
11
+ date: 2016-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -219,6 +219,7 @@ files:
219
219
  - lib/boxr/tasks.rb
220
220
  - lib/boxr/users.rb
221
221
  - lib/boxr/version.rb
222
+ - lib/boxr/web_links.rb
222
223
  - spec/boxr_spec.rb
223
224
  - spec/spec_helper.rb
224
225
  - spec/test_files/test file.txt