box_cli 0.1.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.
Files changed (60) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +7 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +97 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +81 -0
  7. data/Rakefile +22 -0
  8. data/bin/box +28 -0
  9. data/box-cli.gemspec +32 -0
  10. data/features/account_info_command.feature +12 -0
  11. data/features/cli.feature +21 -0
  12. data/features/create_folder_command.feature +11 -0
  13. data/features/delete_command.feature +21 -0
  14. data/features/info_command.feature +20 -0
  15. data/features/settings_command.feature +48 -0
  16. data/features/step_definitions/box.rb +43 -0
  17. data/features/step_definitions/environment.rb +12 -0
  18. data/features/support/box_helpers.rb +63 -0
  19. data/features/support/env.rb +6 -0
  20. data/features/support/hooks.rb +7 -0
  21. data/features/upload_command.feature +20 -0
  22. data/fixtures/cassettes/BoxCli_AccountInfoCommand/returns_account_info_for_good_credentials_and_an_api_key.json +1 -0
  23. data/fixtures/cassettes/BoxCli_CreateFolderCommand/creates_a_folder_when_none_by_that_name_already_exists.json +1 -0
  24. data/fixtures/cassettes/BoxCli_CreateFolderCommand/raises_an_exception_when_a_folder_by_that_name_already_exists.json +1 -0
  25. data/fixtures/cassettes/BoxCli_DeleteCommand/deletes_the_item_when_something_is_there.json +1 -0
  26. data/fixtures/cassettes/BoxCli_DeleteCommand/does_not_raise_an_exception_when_deleting_something_that_exists.json +1 -0
  27. data/fixtures/cassettes/BoxCli_DeleteCommand/raises_an_exception_when_there_is_nothing_to_delete.json +1 -0
  28. data/fixtures/cassettes/BoxCli_InfoCommand/provides_output_regarding_the_item_if_it_exists.json +1 -0
  29. data/fixtures/cassettes/BoxCli_InfoCommand/raises_an_exception_if_nothing_is_there.json +1 -0
  30. data/fixtures/cassettes/BoxCli_UploadCommand/raises_an_exception_when_a_file_by_that_name_already_exists.json +1 -0
  31. data/fixtures/cassettes/BoxCli_UploadCommand/uploads_a_file_when_none_by_that_name_already_exists.json +1 -0
  32. data/fixtures/cassettes/Generic_Box_Command/fails_for_a_bad_api_key.json +1 -0
  33. data/fixtures/cassettes/Generic_Box_Command/fails_for_bad_credentials.json +1 -0
  34. data/lib/box_cli/account_info_command.rb +7 -0
  35. data/lib/box_cli/auth_token_manager.rb +40 -0
  36. data/lib/box_cli/box_command.rb +13 -0
  37. data/lib/box_cli/command.rb +33 -0
  38. data/lib/box_cli/create_folder_command.rb +9 -0
  39. data/lib/box_cli/delete_command.rb +8 -0
  40. data/lib/box_cli/displayer.rb +10 -0
  41. data/lib/box_cli/hash_to_pretty.rb +28 -0
  42. data/lib/box_cli/info_command.rb +10 -0
  43. data/lib/box_cli/settings_command.rb +24 -0
  44. data/lib/box_cli/terminal.rb +13 -0
  45. data/lib/box_cli/upload_command.rb +8 -0
  46. data/lib/box_cli/version.rb +3 -0
  47. data/lib/box_cli/wrapper.rb +149 -0
  48. data/lib/box_cli.rb +27 -0
  49. data/spec/box_cli/account_info_command_spec.rb +8 -0
  50. data/spec/box_cli/box_command_spec.rb +51 -0
  51. data/spec/box_cli/create_folder_command_spec.rb +22 -0
  52. data/spec/box_cli/delete_command_spec.rb +27 -0
  53. data/spec/box_cli/generic_box_command_spec.rb +10 -0
  54. data/spec/box_cli/hash_to_pretty_spec.rb +57 -0
  55. data/spec/box_cli/info_command_spec.rb +22 -0
  56. data/spec/box_cli/settings_command_spec.rb +12 -0
  57. data/spec/box_cli/upload_command_spec.rb +30 -0
  58. data/spec/box_helpers.rb +40 -0
  59. data/spec/spec_helper.rb +41 -0
  60. metadata +332 -0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ tmp/
6
+ *.DS_Store
7
+ coverage/*
8
+ *.sw[op]
9
+ tags
10
+ !.keep
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.8.7"
4
+ - "1.9.2"
5
+ - "1.9.3"
6
+ env:
7
+ - BOX_CLI_API_KEY=abodaciouskey BOX_CLI_USER=barack@whitehouse.gov BOX_CLI_PASSWORD=bananatime
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ box_cli (0.1.0)
5
+ active_support
6
+ box-api
7
+ commander
8
+ highline (~> 1.6.15)
9
+ mechanize
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ active_support (3.0.0)
15
+ activesupport (= 3.0.0)
16
+ activesupport (3.0.0)
17
+ aruba (0.4.11)
18
+ childprocess (>= 0.2.3)
19
+ cucumber (>= 1.1.1)
20
+ ffi (>= 1.0.11)
21
+ rspec (>= 2.7.0)
22
+ bourne (1.2.0)
23
+ mocha (= 0.12.3)
24
+ box-api (0.2.2)
25
+ httmultiparty (~> 0.3.6)
26
+ builder (3.1.4)
27
+ childprocess (0.3.6)
28
+ ffi (~> 1.0, >= 1.0.6)
29
+ commander (4.1.2)
30
+ highline (~> 1.6.11)
31
+ cucumber (1.2.1)
32
+ builder (>= 2.1.2)
33
+ diff-lcs (>= 1.1.3)
34
+ gherkin (~> 2.11.0)
35
+ json (>= 1.4.6)
36
+ diff-lcs (1.1.3)
37
+ domain_name (0.5.4)
38
+ unf (~> 0.0.3)
39
+ fakeweb (1.3.0)
40
+ ffi (1.1.5)
41
+ gherkin (2.11.5)
42
+ json (>= 1.4.6)
43
+ highline (1.6.15)
44
+ httmultiparty (0.3.8)
45
+ httparty (>= 0.7.3)
46
+ multipart-post
47
+ httparty (0.9.0)
48
+ multi_json (~> 1.0)
49
+ multi_xml
50
+ json (1.7.5)
51
+ mechanize (2.5.1)
52
+ domain_name (~> 0.5, >= 0.5.1)
53
+ mime-types (~> 1.17, >= 1.17.2)
54
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
55
+ net-http-persistent (~> 2.5, >= 2.5.2)
56
+ nokogiri (~> 1.4)
57
+ ntlm-http (~> 0.1, >= 0.1.1)
58
+ webrobots (~> 0.0, >= 0.0.9)
59
+ metaclass (0.0.1)
60
+ mime-types (1.19)
61
+ mocha (0.12.3)
62
+ metaclass (~> 0.0.1)
63
+ multi_json (1.3.6)
64
+ multi_xml (0.5.1)
65
+ multipart-post (1.1.5)
66
+ net-http-digest_auth (1.2.1)
67
+ net-http-persistent (2.8)
68
+ nokogiri (1.5.5)
69
+ ntlm-http (0.1.1)
70
+ rake (0.9.2.2)
71
+ rspec (2.11.0)
72
+ rspec-core (~> 2.11.0)
73
+ rspec-expectations (~> 2.11.0)
74
+ rspec-mocks (~> 2.11.0)
75
+ rspec-core (2.11.1)
76
+ rspec-expectations (2.11.3)
77
+ diff-lcs (~> 1.1.3)
78
+ rspec-mocks (2.11.3)
79
+ unf (0.0.5)
80
+ unf_ext
81
+ unf_ext (0.0.5)
82
+ vcr (2.2.5)
83
+ webrobots (0.0.13)
84
+
85
+ PLATFORMS
86
+ ruby
87
+
88
+ DEPENDENCIES
89
+ aruba (~> 0.4.11)
90
+ bourne (~> 1.2.0)
91
+ box_cli!
92
+ cucumber (~> 1.2.1)
93
+ fakeweb (~> 1.3.0)
94
+ mocha (~> 0.12.3)
95
+ rake (~> 0.9.2)
96
+ rspec (~> 2.11.0)
97
+ vcr (~> 2.2.5)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Iora Health
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+
2
+ # box_cli
3
+
4
+ box_cli provides a basic and minimal command-line interface to Box (<https://www.box.com/>). It is not written by Box; use at your own risk. We hope that eventually Box will provide their own command-line interfaces for Linux, BSD, OS/X, Windows, etc. Until then, this may help.
5
+
6
+ [![Build Status](https://api.travis-ci.org/IoraHealth/box_cli.png)](https://travis-ci.org/IoraHealth/box_cli)
7
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/IoraHealth/box_cli)
8
+
9
+ ## Install
10
+
11
+ Install the gem:
12
+
13
+ gem install box_cli
14
+
15
+ ## Usage
16
+
17
+ After installing the gem, you can run the command `box` to use the application. For help, type
18
+
19
+ box --help
20
+
21
+ NOTE: All of the commands that communicate with Box require an API key and user credentials. To obtain your own Box API key, read the documentation here: <http://developers.box.net/w/page/12923956/ApiOverview#GettingStartedwiththeBoxAPI> -- We do not ship an API key with this gem, because you may be
22
+ working off of a forked copy.
23
+
24
+ When a command requires an API key and user credentials, it will find them in the following order:
25
+
26
+ 1. It will find the values in the options `--api_key`, `--user`, and `--password`
27
+ 2. Failing that, it will check for environment variables `BOX_CLI_API_KEY`, `BOX_CLI_USER`, and `BOX_CLI_PASSWORD`
28
+ 3. Failing that, it will prompt for the value from the keyboard
29
+
30
+ You may define each of these options separately. In other words, if you define only the environment variables `BOX_CLI_API_KEY` and `BOX_CLI_USER`, you will
31
+ be prompted only for the password.
32
+
33
+ The most commonly-used commands are:
34
+
35
+ box info path
36
+ box upload file path
37
+ box download path
38
+ box delete path
39
+ box account_info
40
+
41
+ The commands adhere fairly closely to the Box API, as defined by the list of calls in the right sidebar at the developer site: <http://developers.box.net/w/page/12923956/ApiOverview>. For example, `box account_info` might produce an interaction similar to this:
42
+
43
+ $ box account_info
44
+ Status: get_account_info_ok
45
+ User:
46
+ Login: john@iorahealth.com
47
+ Email: john@iorahealth.com
48
+ Access: 11756654
49
+ User: 11756654
50
+ Space amount: 21474836480
51
+ Space used: 1657381056
52
+ Max upload size: 2147483647
53
+
54
+ To understand what the status value "get_account_info_ok" means, consult the documentation for the API call that corresponds to the command (i.e., <http://developers.box.net/w/page/12923928/ApiFunction_get_account_info>).
55
+
56
+ ## Testing
57
+
58
+ To run all tests that don't require exercising box directly, set the BOX_CLI_* environment variables. Unless they are
59
+ set to something, the console will be prompted for values. The values don't have to be realistic.
60
+
61
+ BOX_CLI_API_KEY=abodaciouskey BOX_CLI_USER=barack@whitehouse.gov BOX_CLI_PASSWORD=bananatime bundle exec rake
62
+
63
+ Many of the Cucumber features require a *working* Box API key and user credentials, which should be defined through environment variables. The default rake task excludes all features tagged with `@requires_authorization` so that TravisCI will not exercise the actual service. This means that if you make changes in features, you should verify by running cucumber directly (not through rake) with your own key, user, and password:
64
+
65
+ BOX_CLI_API_KEY=pzay0j0o2psakijtm9ysn2jjd2ho7qg5 BOX_CLI_USER=box_cli_testing@iorahealth.com BOX_CLI_PASSWORD=secretpassword01 bundle exec cucumber
66
+
67
+ NOTE: If you recreate the VCR cassettes, make sure to invalidate your API key and credentials before making a pull request or anything else that would reveal your key or credentials. While we've set VCR to filter out these sensitive data, don't run the risk of something getting captured.
68
+
69
+ ## Contributing to box_cli
70
+
71
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
72
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
73
+ * Fork the project.
74
+ * Start a feature/bugfix branch.
75
+ * Commit and push until you are happy with your contribution.
76
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
77
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
78
+
79
+ ## Copyright
80
+
81
+ Copyright (c) 2012 Iora Health. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'cucumber/rake/task'
5
+
6
+ desc 'Default: run specs and features'
7
+ task :default => [:spec, :cucumber]
8
+
9
+ desc 'Run specs'
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.rspec_opts = ['--color', '--format progress']
12
+ t.pattern = 'spec/box_cli/**/*_spec.rb'
13
+ end
14
+
15
+ desc 'Run cucumber features'
16
+ Cucumber::Rake::Task.new do |t|
17
+ t.cucumber_opts = [
18
+ '--tags', '~@wip',
19
+ '--tags', '~@requires_authorization',
20
+ '--format', (ENV['CUCUMBER_FORMAT'] || 'progress')
21
+ ]
22
+ end
data/bin/box ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'commander/import'
4
+ require 'box_cli'
5
+
6
+ program :version, BoxCli::VERSION
7
+ program :description, 'CLI for box'
8
+ program :help_formatter, :compact
9
+ program :help, 'Note', "When a file item and a folder item have the same name, generic commands such as 'delete' will delete the file first."
10
+
11
+ global_option '-k', '--api_key API_KEY', String, 'api key'
12
+ global_option '-u', '--user USER', String, 'username or email address'
13
+ global_option '-p', '--password PASSWORD', String, 'password'
14
+
15
+ def make_command(name, syntax, description)
16
+ command name do |c|
17
+ c.syntax = syntax
18
+ c.description = description
19
+ c.action { |args, options| exit BoxCli.dispatch(c.name, options, args) }
20
+ end
21
+ end
22
+
23
+ make_command :account_info, 'box account_info', 'Show account information'
24
+ make_command :create_folder, 'box create_folder folder_name', 'Create a folder named folder_name in the root folder'
25
+ make_command :delete, 'box delete path', 'Delete whatever is at path'
26
+ make_command :info, 'box info [path]', 'Show info for path (default: root)'
27
+ make_command :settings, 'box settings', 'Show settings'
28
+ make_command :upload, 'box upload path folder_path', 'Upload the file at path to folder_path'
data/box-cli.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', 'lib'), __FILE__)
2
+ require 'box_cli/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'box_cli'
6
+ s.version = BoxCli::VERSION
7
+ s.date = Time.now.utc.strftime('%Y-%m-%d')
8
+ s.summary = 'CLI for box'
9
+ s.description = 'CLI for box'
10
+ s.authors = ['Iora Health']
11
+ s.email = 'rubygems@iorahealth.com'
12
+ s.files = `git ls-files`.split("\n")
13
+ s.homepage = 'https://github.com/IoraHealth/box_cli'
14
+ s.rdoc_options = ['--charset=UTF-8']
15
+ s.require_paths = ['lib']
16
+ s.test_files = `git ls-files spec`.split("\n")
17
+ s.add_dependency 'box-api'
18
+ s.add_dependency 'active_support'
19
+ s.add_dependency 'commander'
20
+ s.add_dependency 'highline', '~> 1.6.15'
21
+ s.add_dependency 'mechanize'
22
+ s.executables << 'box'
23
+
24
+ s.add_development_dependency 'aruba', '~> 0.4.11'
25
+ s.add_development_dependency 'bourne', '~> 1.2.0'
26
+ s.add_development_dependency 'cucumber', '~> 1.2.1'
27
+ s.add_development_dependency 'fakeweb', '~> 1.3.0'
28
+ s.add_development_dependency 'mocha', '~> 0.12.3'
29
+ s.add_development_dependency 'rake', '~> 0.9.2'
30
+ s.add_development_dependency 'rspec', '~> 2.11.0'
31
+ s.add_development_dependency 'vcr', '~> 2.2.5'
32
+ end
@@ -0,0 +1,12 @@
1
+ Feature: account_info command
2
+
3
+ In order to use box from the command line
4
+ As a CLI user
5
+ I want to be able to see my account info
6
+
7
+ @requires_authorization
8
+ Scenario: Get account info
9
+ When I've set the box cli env variables
10
+ And I run `box account_info`
11
+ Then the output should match /Space used:\s+\d+/
12
+ And the exit status should be 0
@@ -0,0 +1,21 @@
1
+ Feature: cli basics
2
+
3
+ In order to use box from the command line
4
+ As a CLI user
5
+ I want to be able to run box and specify some options
6
+
7
+ Scenario: use the box command with no command
8
+ When I run `box`
9
+ Then the exit status should be 1
10
+
11
+ Scenario: use the box command with an unrecognized command
12
+ When I run `box foobar`
13
+ Then the exit status should be 1
14
+
15
+ Scenario: use the box command with a valid command
16
+ When I run `box --version`
17
+ Then the exit status should be 0
18
+
19
+ Scenario: use the box command to get help
20
+ When I run `box help`
21
+ Then the output should contain "CLI for box"
@@ -0,0 +1,11 @@
1
+ Feature: create folder command
2
+
3
+ In order to use box from the command line
4
+ As a CLI user
5
+ I want to be able to create a folder
6
+
7
+ @requires_authorization
8
+ Scenario: create a new folder
9
+ When I've set the box cli env variables
10
+ And I create a temporary folder at box
11
+ And there should be something at the temporary path
@@ -0,0 +1,21 @@
1
+ Feature: delete command
2
+
3
+ In order to use box from the command line
4
+ As a CLI user
5
+ I want to be able to delete files and folders
6
+
7
+ @requires_authorization
8
+ Scenario: delete a folder
9
+ When I've set the box cli env variables
10
+ And I create a temporary folder at box
11
+ And I run `box delete` on the temporary path
12
+ Then the exit status should be 0
13
+ And there should be nothing at the temporary path
14
+
15
+ @requires_authorization
16
+ Scenario: delete a file
17
+ When I've set the box cli env variables
18
+ And I create a temporary file at box
19
+ And I run `box delete` on the temporary path
20
+ Then the exit status should be 0
21
+ And there should be nothing at the temporary path
@@ -0,0 +1,20 @@
1
+ Feature: info command
2
+
3
+ In order to use box from the command line
4
+ As a CLI user
5
+ I want to be able to see info for what's at a path
6
+
7
+ @requires_authorization
8
+ Scenario: get info about root
9
+ When I've set the box cli env variables
10
+ And I run `box info`
11
+ Then the output should match /^Type: folder\s+Data:\s+Id: 0$/
12
+ And the exit status should be 0
13
+
14
+ @requires_authorization
15
+ Scenario: get info about a folder
16
+ When I've set the box cli env variables
17
+ And I create a temporary folder at box
18
+ And I run `box info` on the temporary path
19
+ Then the output should match /^Type: folder\s+Data:/
20
+ And the exit status should be 0
@@ -0,0 +1,48 @@
1
+ Feature: settings command
2
+
3
+ In order to use box from the command line
4
+ As a CLI user
5
+ I want to be able to show settings
6
+
7
+ Scenario: show all settings
8
+ When I run `box settings --user john --password 123456 --api_key abc`
9
+ Then the output should match:
10
+ """
11
+ api_key: abc
12
+ password: 123456
13
+ user: john
14
+ """
15
+
16
+ Scenario: show all settings and arguments
17
+ When I run `box settings --user john --password 123456 --api_key abc arg2 arg1`
18
+ Then the output should match:
19
+ """
20
+ api_key: abc
21
+ password: 123456
22
+ user: john
23
+ .*
24
+ arg2
25
+ arg1
26
+ """
27
+
28
+ Scenario: show settings when defined by environment variables
29
+ When I unset all env variables matching /BOX_CLI_/
30
+ And I set env variable "BOX_CLI_USER" to "john"
31
+ And I run `box settings --password 123456 --api_key abc`
32
+ Then the output should match:
33
+ """
34
+ api_key: abc
35
+ password: 123456
36
+ user: john
37
+ """
38
+
39
+ Scenario: Have explicit setting override environment variable
40
+ When I unset all env variables matching /BOX_CLI_/
41
+ And I set env variable "BOX_CLI_USER" to "john"
42
+ And I run `box settings --password 123456 --api_key abc --user booboo`
43
+ Then the output should match:
44
+ """
45
+ api_key: abc
46
+ password: 123456
47
+ user: booboo
48
+ """
@@ -0,0 +1,43 @@
1
+ require 'box_cli/wrapper'
2
+
3
+ When /^I create a temporary folder at box$/ do
4
+ setup_filename
5
+ box_wrapper.create_folder(box_path)
6
+ end
7
+
8
+ When /^I create a local temporary file$/ do
9
+ create_local_file
10
+ end
11
+
12
+ When /^I create a temporary file at box$/ do
13
+ create_local_file
14
+ box_wrapper.upload(local_filename, '/')
15
+ end
16
+
17
+ Then /^there should be something at the temporary path$/ do
18
+ box_wrapper.info(box_path)
19
+ end
20
+
21
+ Then /^there should be nothing at the temporary path$/ do
22
+ begin
23
+ box_wrapper.info(box_path)
24
+ raise "Expected nothing at '#{box_path}'"
25
+ rescue BoxCli::NotFound
26
+ end
27
+ end
28
+
29
+ When /^I run `box delete` on the temporary path$/ do
30
+ step "I run `box delete #{box_path}`"
31
+ end
32
+
33
+ When /^I run `box info` on the temporary path$/ do
34
+ step "I run `box info #{box_path}`"
35
+ end
36
+
37
+ When /^I run `box upload` for a local temporary file$/ do
38
+ step "I run `box upload #{local_filename} /`"
39
+ end
40
+
41
+ When /^I create a folder named "(.*?)"$/ do |folder_name|
42
+ step "I run `box create_folder #{folder_name}`"
43
+ end
@@ -0,0 +1,12 @@
1
+ When /^I unset all env variables matching \/([^\/]*)\/$/ do |regexp|
2
+ ENV.keys.find_all { |k| k =~ Regexp.new(regexp) }.each { |k| ENV[k] = nil }
3
+ end
4
+
5
+ When /^I set env variable "(\w+)" to "([^"]*)"$/ do |var, value|
6
+ ENV[var] = value
7
+ end
8
+
9
+ When /^I've set the box cli env variables$/ do
10
+ required_env_vars = ['BOX_CLI_API_KEY', 'BOX_CLI_USER', 'BOX_CLI_PASSWORD']
11
+ raise "\n\n* You must define the env variables #{required_env_vars.join(', ')} *\n\n\n" unless required_env_vars.all? { |v| !ENV[v].nil? }
12
+ end
@@ -0,0 +1,63 @@
1
+ require 'box_cli/auth_token_manager'
2
+ require 'box_cli/wrapper'
3
+
4
+ module BoxHelpers
5
+ attr_reader :box_path, :local_filename
6
+
7
+ def setup_filename
8
+ @box_path = "box_cli_" + Digest::MD5.hexdigest(Time.now.strftime('%FT%T.%N%:z') + rand.to_s).tap do |path|
9
+ # Ensure that there's nothing there
10
+ delete_all_at_path(path)
11
+ end
12
+ end
13
+
14
+ def box_wrapper
15
+ @box_wrapper ||= BoxCli::Wrapper.new(ENV['BOX_CLI_API_KEY'], ENV['BOX_CLI_USER'], ENV['BOX_CLI_PASSWORD'])
16
+ end
17
+
18
+ def create_local_file
19
+ setup_filename
20
+ @local_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'tmp', @box_path))
21
+ FileUtils.touch @local_filename
22
+ @filenames ||= []
23
+ @filenames << @local_filename
24
+ end
25
+
26
+ private
27
+
28
+ def delete_all_at_path(path)
29
+ # Twice, because a file and a folder can live at the same path
30
+ delete_at_path(path)
31
+ delete_at_path(path)
32
+ end
33
+
34
+ def delete_at_path(path)
35
+ begin
36
+ box_wrapper.delete(path)
37
+ rescue BoxCli::NotFound
38
+ rescue Box::Api::Unknown # Sometimes deletion is in progress?
39
+ end
40
+ end
41
+ end
42
+
43
+ def box_before
44
+ @save_env = {
45
+ :box_cli_api_key => ENV['BOX_CLI_API_KEY'],
46
+ :box_cli_user => ENV['BOX_CLI_USER'],
47
+ :box_cli_password => ENV['BOX_CLI_PASSWORD']
48
+ }
49
+ end
50
+
51
+ def box_after
52
+ if @box_path
53
+ delete_all_at_path(@box_path)
54
+ end
55
+
56
+ FileUtils.rm @filenames if @filenames
57
+
58
+ ENV['BOX_CLI_API_KEY'] = @save_env[:box_cli_api_key]
59
+ ENV['BOX_CLI_USER'] = @save_env[:box_cli_user]
60
+ ENV['BOX_CLI_PASSWORD'] = @save_env[:box_cli_password]
61
+ end
62
+
63
+ World(BoxHelpers)
@@ -0,0 +1,6 @@
1
+ require 'aruba/cucumber'
2
+
3
+ Before('@requires_authorization') do
4
+ @aruba_timeout_seconds = 10
5
+ @aruba_io_wait_seconds = 10
6
+ end
@@ -0,0 +1,7 @@
1
+ Before do
2
+ box_before
3
+ end
4
+
5
+ After do
6
+ box_after
7
+ end
@@ -0,0 +1,20 @@
1
+ Feature: upload command
2
+
3
+ In order to use box from the command line
4
+ As a CLI user
5
+ I want to be able to upload a file to a path
6
+
7
+ @requires_authorization
8
+ Scenario: upload a file
9
+ When I've set the box cli env variables
10
+ And I create a local temporary file
11
+ And I run `box upload` for a local temporary file
12
+ Then the exit status should be 0
13
+
14
+ @requires_authorization
15
+ Scenario: upload a file when one already exists with the same name
16
+ When I've set the box cli env variables
17
+ And I create a local temporary file
18
+ And I run `box upload` for a local temporary file
19
+ And I run `box upload` for a local temporary file
20
+ Then the exit status should be 1