boxr 0.1.1 → 0.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: 701cf0b13487355be79ee76e2a1e3c14f6b469e2
4
- data.tar.gz: 4be68b9d0ea475e149e15dbda0698651a6de8deb
3
+ metadata.gz: 313b4d35a06c5975bcc0486d8d0099cb74288d53
4
+ data.tar.gz: b691b2075b1bb74992222aeb945c9e0665ab8378
5
5
  SHA512:
6
- metadata.gz: a2a8c7de20cf50e9b1908663af64e438de58b23c6e1414e55ead210aa6b331f77160512760a72a50c89817e9433913c2cda99092ef32e21c102b4fa9d2547dce
7
- data.tar.gz: 9fa79592811db54ff842378f90c5801f3303bda768456f5297557cf5b23288f6fb7330a48850f4225ce0c87de761ba1eca64cf525c42e59513145374423934d6
6
+ metadata.gz: 007e990c0b663e9b1cfd26bc387f4352d75764a462cbbed1ecf5bc41028982189c7507ff1fb87e7ca7d8d58112d45b06a611dd0d2c429cb818bd8fc17a9cc94c
7
+ data.tar.gz: 39f0c09f87141e9a62780401979c0a76391e4f1109d99f0653b9e81e50a3a968651c09c47b54cc4fcfca229c6d7b1977cedd203b40b6740255ea9bd0fe684c58
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # Boxr
2
+ Boxr is a Ruby client library for the Box V2 Content API that covers 100% of the underlying REST API. Box employees affectionately refer to one another as Boxers, hence the name of this gem.
2
3
 
3
- PLEASE NOTE: I need to complete this README with much more detailed instructions. However, feel free to try it out. The integration test suite is achieving 95% code coverage. Thanks!
4
+ The purpose of this gem is to provide a clear, efficient, and intentional method of interacting with the Box Content API. As with any SDK that wraps a REST API, it is important to fully understand the Box Content API at the REST endpoint level. You are strongly encouraged to read through the Box documentation located [here](https://developers.box.com/docs/).
4
5
 
5
- ## Installation
6
+ The full RubyDocs for Boxr can be found [here](http://www.rubydoc.info/gems/boxr). You are also encouraged to rely heavily on the source code found in the [lib/boxr](https://github.com/cburnette/boxr/tree/master/lib/boxr) directory of this gem, as well as on the integration test found [here](https://github.com/cburnette/boxr/blob/master/spec/boxr_spec.rb).
6
7
 
8
+ ## Installation
7
9
  Add this line to your application's Gemfile:
8
10
 
9
11
  ```ruby
@@ -19,10 +21,9 @@ Or install it yourself as:
19
21
  $ gem install boxr
20
22
 
21
23
  ## Usage
24
+ Super-fast instructions:
22
25
 
23
- Super-fast instructions for now (much more to come):
24
-
25
- 1. go to https://developers.box.com
26
+ 1. go to http://developers.box.com
26
27
  2. find or create your Box Content API app for testing
27
28
  3. click 'Edit Application'
28
29
  4. check the boxes for 'Read and write all files and folders' and 'Manage an enterprise'
@@ -32,11 +33,62 @@ Super-fast instructions for now (much more to come):
32
33
  ```ruby
33
34
  require 'boxr'
34
35
 
35
- client = Boxr::Client.new({BOX_DEVELOPER_TOKEN})
36
+ client = Boxr::Client.new('{BOX_DEVELOPER_TOKEN}')
36
37
  items = client.folder_items(Boxr::ROOT)
37
38
  items.each {|i| puts i.name}
38
39
  ```
39
40
 
41
+ ### Creating a client
42
+ There are a few different ways to create a Boxr client. The simplest is to use a Box Developer Token (you generate these from your Box app's General Information page). They last for 60 minutes and you don't have to go through OAuth2.
43
+ ```ruby
44
+ client = Boxr::Client.new('yPDWOvnumUFaKIMrNBg6PGJpWXC0oaFW')
45
+
46
+ # Alternatively, you can set an environment variable called BOX_DEVELOPER_TOKEN to
47
+ # the value of your current token. By default, Boxr will look for that.
48
+
49
+ client = Boxr::Client.new #uses ENV['BOX_DEVELOPER_TOKEN']
50
+ ```
51
+
52
+ The next way is to use an access token retrieved after going through the OAuth2 process. If your application is going to handle refreshing the tokens in a scheduled way (more on this later) then this is the way to go.
53
+ ```ruby
54
+ client = Boxr::Client.new('v2eAXqhZ28WIEpIWeAJcmyamLLt77icP') #a valid OAuth2 access token
55
+
56
+ # Boxr will raise an error if this token becomes invalid. It is up to your application to generate
57
+ # a new pair of access and refresh tokens in a timely manner.
58
+ ```
59
+
60
+ If you want Boxr to automatically refresh the tokens once the access token becomes invalid you can supply a refresh token, along with your client_id and client_secret, and a block that will get invoked when the refresh occurs.
61
+ ```ruby
62
+ token_refresh_callback = lambda {|access, refresh, identifier| some_method_that_saves_them(access, refresh)}
63
+ client = Boxr::Client.new('zX3UjFwNerOy5PSWc2WI8aJgMHtAjs8T',
64
+ refresh_token: 'dvfzfCQoIcRi7r4Yeuar7mZnaghGWexXlX89sBaRy1hS9e5wFroVVOEM6bs0DwPQ',
65
+ client_id: 'kplh54vfeagt6jmi4kddg4xdswwvrw8y',
66
+ client_secret: 'sOsm9ZZ8L8svwrn9FsdulLQVwDizKueU',
67
+ &token_refresh_callback)
68
+
69
+ # By default Boxr will look for client_id and client_secret in your environment variables as
70
+ # BOX_CLIENT_ID and BOX_CLIENT_SECRET, respectively. You can omit the two optional parameters above
71
+ # if those are present.
72
+
73
+ # Additionally, you can provide one other parameter called identifier. This can be used, for example, to
74
+ # hold the id of the user associated with this Boxr client. When the callback is invoked this value
75
+ # will be provided.
76
+ ```
77
+
78
+ ### A quick example
79
+ Before diving into detailed documentation, let's take a look at how to accomplish a simple task with Boxr. This script will find a specific folder given its path, upload a file to that folder, and create an open shared link to that file.
80
+ ```ruby
81
+ require 'boxr'
82
+
83
+ client = Boxr::Client.new #using ENV['BOX_DEVELOPER_TOKEN']
84
+
85
+ folder = client.folder_from_path('/some/directory/structure')
86
+ file = client.upload_file('test.txt', folder.id)
87
+ file = client.create_shared_link_for_file(file.id, access: :open)
88
+ puts "Shared Link: #{file.shared_link.url}"
89
+ ```
90
+
91
+
40
92
  ## Contributing
41
93
 
42
94
  1. Fork it ( https://github.com/cburnette/boxr/fork )
data/lib/boxr/files.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Boxr
2
2
  class Client
3
3
 
4
- def file_id(path)
4
+ def file_from_path(path)
5
5
  if(path.start_with?('/'))
6
6
  path = path.slice(1..-1)
7
7
  end
@@ -9,15 +9,12 @@ module Boxr
9
9
  path_items = path.split('/')
10
10
  file_name = path_items.slice!(-1)
11
11
 
12
- folder_id = folder_id(path_items.join('/'))
12
+ folder = folder_from_path(path_items.join('/'))
13
13
 
14
- files = folder_items(folder_id, fields: [:id, :name])
15
-
16
- begin
17
- files.select{|f| f.name == file_name}.first.id
18
- rescue
19
- raise BoxrException.new(boxr_message: "File not found: '#{file_name}'")
20
- end
14
+ files = folder_items(folder.id, fields: [:id, :name]).files
15
+ file = files.select{|f| f.name == file_name}.first
16
+ raise BoxrException.new(boxr_message: "File not found: '#{file_name}'") if file.nil?
17
+ file
21
18
  end
22
19
 
23
20
  def file(file_id, fields: [])
data/lib/boxr/folders.rb CHANGED
@@ -1,21 +1,19 @@
1
1
  module Boxr
2
2
  class Client
3
3
 
4
- def folder_id(path)
4
+ def folder_from_path(path)
5
5
  if(path.start_with?('/'))
6
6
  path = path.slice(1..-1)
7
7
  end
8
8
 
9
9
  path_folders = path.split('/')
10
10
 
11
- folder_id = path_folders.inject(Boxr::ROOT) do |parent_id, folder_name|
12
- folders = folder_items(parent_id, fields: [:id, :name]).folders
13
-
14
- begin
15
- folders.select{|f| f.name == folder_name}.first.id
16
- rescue
17
- raise BoxrException.new(boxr_message: "Folder not found: '#{folder_name}'")
18
- end
11
+ root_folder = Hashie::Mash.new({id: Boxr::ROOT})
12
+ folder = path_folders.inject(root_folder) do |parent_folder, folder_name|
13
+ folders = folder_items(parent_folder.id, fields: [:id, :name]).folders
14
+ folder = folders.select{|f| f.name == folder_name}.first
15
+ raise BoxrException.new(boxr_message: "Folder not found: '#{folder_name}'") if folder.nil?
16
+ folder
19
17
  end
20
18
  end
21
19
 
data/lib/boxr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/spec/boxr_spec.rb CHANGED
@@ -29,7 +29,7 @@ describe Boxr::Client do
29
29
  COMMENT_MESSAGE = 'this is a comment'
30
30
  REPLY_MESSAGE = 'this is a comment reply'
31
31
  CHANGED_COMMENT_MESSAGE = 'this comment has been changed'
32
- TEST_USER_LOGIN = "test-boxr-user@example.com"
32
+ TEST_USER_LOGIN = "test-boxr-user@#{('a'..'z').to_a.shuffle[0,10].join}.com" #needs to be unique across anyone running this test
33
33
  TEST_USER_NAME = "Test Boxr User"
34
34
  TEST_GROUP_NAME= "Test Boxr Group"
35
35
  TEST_TASK_MESSAGE = "Please review"
@@ -46,7 +46,7 @@ describe Boxr::Client do
46
46
  @test_folder_id = new_folder.id
47
47
 
48
48
  all_users = BOX_CLIENT.all_users
49
- test_user = all_users.find{|u| u.login == TEST_USER_LOGIN}
49
+ test_user = all_users.find{|u| u.name == TEST_USER_NAME}
50
50
  if(test_user)
51
51
  BOX_CLIENT.delete_user(test_user.id, force: true)
52
52
  end
@@ -62,9 +62,9 @@ describe Boxr::Client do
62
62
  end
63
63
 
64
64
  it 'invokes folder operations' do
65
- puts "get folder id using path"
66
- folder_id = BOX_CLIENT.folder_id(TEST_FOLDER_NAME)
67
- expect(folder_id).to eq(@test_folder_id)
65
+ puts "get folder using path"
66
+ folder = BOX_CLIENT.folder_from_path(TEST_FOLDER_NAME)
67
+ expect(folder.id).to eq(@test_folder_id)
68
68
 
69
69
  puts "get folder info"
70
70
  folder = BOX_CLIENT.folder(@test_folder_id)
@@ -125,9 +125,9 @@ describe Boxr::Client do
125
125
  expect(new_file.name).to eq(TEST_FILE_NAME)
126
126
  test_file_id = new_file.id
127
127
 
128
- puts "get file id using path"
129
- file_id = BOX_CLIENT.file_id("/#{TEST_FOLDER_NAME}/#{TEST_FILE_NAME}")
130
- expect(file_id).to eq(test_file_id)
128
+ puts "get file using path"
129
+ file = BOX_CLIENT.file_from_path("/#{TEST_FOLDER_NAME}/#{TEST_FILE_NAME}")
130
+ expect(file.id).to eq(test_file_id)
131
131
 
132
132
  puts "get file download url"
133
133
  download_url = BOX_CLIENT.download_url(test_file_id)
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.1.1
4
+ version: 0.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: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler