boxr 0.0.1

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.
@@ -0,0 +1,29 @@
1
+ module Boxr
2
+ class Client
3
+
4
+ def create_metadata(file_id, metadata, type: :properties)
5
+ uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
6
+ metadata, response = post uri, metadata, content_type: "application/json"
7
+ metadata
8
+ end
9
+
10
+ def metadata(file_id, type: :properties)
11
+ uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
12
+ metadata, response = get uri
13
+ metadata
14
+ end
15
+
16
+ def update_metadata(file_id, updates, type: :properties)
17
+ uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
18
+ metadata, response = put uri, updates, content_type: "application/json-patch+json"
19
+ metadata
20
+ end
21
+
22
+ def delete_metadata(file_id, type: :properties)
23
+ uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
24
+ result, response = delete uri
25
+ result
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ module Boxr
2
+ class Client
3
+
4
+ def search(query, scope: nil, file_extensions: nil, created_at_range: nil, updated_at_range: nil, size_range: nil,
5
+ owner_user_ids: nil, ancestor_folder_ids: nil, content_types: nil, type: nil,
6
+ limit: 30, offset: 0)
7
+
8
+ query = {query: query}
9
+ query[:scope] = scope unless scope.nil?
10
+ query[:file_extensions] = file_extensions unless file_extensions.nil?
11
+ query[:created_at_range] = created_at_range unless created_at_range.nil?
12
+ query[:updated_at_range] = updated_at_range unless updated_at_range.nil?
13
+ query[:size_range] = size_range unless size_range.nil?
14
+ query[:owner_user_ids] = owner_user_ids unless owner_user_ids.nil?
15
+ query[:ancestor_folder_ids] = ancestor_folder_ids unless ancestor_folder_ids.nil?
16
+ query[:content_types] = content_types unless content_types.nil?
17
+ query[:type] = type unless type.nil?
18
+ query[:limit] = limit unless limit.nil?
19
+ query[:offset] = offset unless offset.nil?
20
+
21
+ results, response = get SEARCH_URI, query: query
22
+ [results["entries"],results.total_count]
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module Boxr
2
+ class Client
3
+
4
+ def shared_item(shared_link, shared_link_password: nil)
5
+ box_api_header = "shared_link=#{shared_link}"
6
+ box_api_header += "&shared_link_password=#{shared_link_password}" unless shared_link_password.nil?
7
+
8
+ file_or_folder, response = get(SHARED_ITEMS_URI, box_api_header: box_api_header)
9
+ file_or_folder
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,77 @@
1
+ module Boxr
2
+ class Client
3
+
4
+ def create_task(file_id, action: :review, message: nil, due_at: nil)
5
+ attributes = {item: {type: :file, id: file_id}}
6
+ attributes[:action] = action unless action.nil?
7
+ attributes[:message] = message unless message.nil?
8
+ attributes[:due_at] = due_at.to_datetime.rfc3339 unless due_at.nil?
9
+
10
+ new_task, response = post TASKS_URI, attributes
11
+ new_task
12
+ end
13
+
14
+ def task(task_id)
15
+ uri = "#{TASKS_URI}/#{task_id}"
16
+ task, response = get uri
17
+ task
18
+ end
19
+
20
+ def update_task(task_id, action: :review, message: nil, due_at: nil)
21
+ uri = "#{TASKS_URI}/#{task_id}"
22
+ attributes = {}
23
+ attributes[:action] = action unless action.nil?
24
+ attributes[:message] = message unless message.nil?
25
+ attributes[:due_at] = due_at.to_datetime.rfc3339 unless due_at.nil?
26
+
27
+ task, response = put uri, attributes
28
+ task
29
+ end
30
+
31
+ def delete_task(task_id)
32
+ uri = "#{TASKS_URI}/#{task_id}"
33
+ result, response = delete uri
34
+ result
35
+ end
36
+
37
+ def task_assignments(task_id)
38
+ uri = "#{TASKS_URI}/#{task_id}/assignments"
39
+ assignments, response = get uri
40
+ assignments['entries']
41
+ end
42
+
43
+ def create_task_assignment(task_id, assign_to_id: nil, assign_to_login: nil)
44
+ attributes = {task: {type: :task, id: "#{task_id}"}}
45
+
46
+ attributes[:assign_to] = {}
47
+ attributes[:assign_to][:login] = assign_to_login unless assign_to_login.nil?
48
+ attributes[:assign_to][:id] = assign_to_id unless assign_to_id.nil?
49
+
50
+ new_task_assignment, response = post TASK_ASSIGNMENTS_URI, attributes
51
+ new_task_assignment
52
+ end
53
+
54
+ def task_assignment(task_id)
55
+ uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
56
+ task_assignment, response = get uri
57
+ task_assignment
58
+ end
59
+
60
+ def delete_task_assignment(task_id)
61
+ uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
62
+ result, response = delete uri
63
+ result
64
+ end
65
+
66
+ def update_task_assignment(task_id, message: nil, resolution_state: nil)
67
+ uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
68
+ attributes = {}
69
+ attributes[:message] = message unless message.nil?
70
+ attributes[:resolution_state] = resolution_state unless resolution_state.nil?
71
+
72
+ updated_task, respons = put uri, attributes
73
+ updated_task
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,92 @@
1
+ module Boxr
2
+ class Client
3
+
4
+ def current_user(fields: [])
5
+ uri = "#{USERS_URI}/me"
6
+ query = build_fields_query(fields, USER_FIELDS_QUERY)
7
+ user, response = get(uri, query: query)
8
+ user
9
+ end
10
+
11
+ def user(user_id, fields: [])
12
+ uri = "#{USERS_URI}/#{user_id}"
13
+ query = build_fields_query(fields, USER_FIELDS_QUERY)
14
+ user, response = get(uri, query: query)
15
+ user
16
+ end
17
+
18
+ def all_users(filter_term: nil, fields: [])
19
+ uri = USERS_URI
20
+ query = build_fields_query(fields, USER_FIELDS_QUERY)
21
+ query[:filter_term] = filter_term unless filter_term.nil?
22
+ users, response = get_with_pagination(uri, query: query)
23
+ end
24
+
25
+ def create_user(login, name, role: nil, language: nil, is_sync_enabled: nil, job_title: nil,
26
+ phone: nil, address: nil, space_amount: nil, tracking_codes: nil,
27
+ can_see_managed_users: nil, is_external_collab_restricted: nil, status: nil, timezone: nil,
28
+ is_exempt_from_device_limits: nil, is_exempt_from_login_verification: nil)
29
+
30
+ uri = USERS_URI
31
+ attributes = {login: login, name: name}
32
+ attributes[:role] = role unless role.nil?
33
+ attributes[:language] = language unless language.nil?
34
+ attributes[:is_sync_enabled] = is_sync_enabled unless is_sync_enabled.nil?
35
+ attributes[:job_title] = job_title unless job_title.nil?
36
+ attributes[:phone] = phone unless phone.nil?
37
+ attributes[:address] = address unless address.nil?
38
+ attributes[:space_amount] = space_amount unless space_amount.nil?
39
+ attributes[:tracking_codes] = tracking_codes unless tracking_codes.nil?
40
+ attributes[:can_see_managed_users] = can_see_managed_users unless can_see_managed_users.nil?
41
+ attributes[:is_external_collab_restricted] = is_external_collab_restricted unless is_external_collab_restricted.nil?
42
+ attributes[:status] = status unless status.nil?
43
+ attributes[:timezone] = timezone unless timezone.nil?
44
+ attributes[:is_exempt_from_device_limits] = is_exempt_from_device_limits unless is_exempt_from_device_limits.nil?
45
+ attributes[:is_exempt_from_login_verification] = is_exempt_from_login_verification unless is_exempt_from_login_verification.nil?
46
+
47
+ new_user, response = post(uri, attributes)
48
+ new_user
49
+ end
50
+
51
+ def update_user(user_id, notify: nil, enterprise: true, name: nil, role: nil, language: nil, is_sync_enabled: nil,
52
+ job_title: nil, phone: nil, address: nil, space_amount: nil, tracking_codes: nil,
53
+ can_see_managed_users: nil, status: nil, timezone: nil, is_exempt_from_device_limits: nil,
54
+ is_exempt_from_login_verification: nil, is_exempt_from_reset_required: nil, is_external_collab_restricted: nil)
55
+
56
+ uri = "#{USERS_URI}/#{user_id}"
57
+ query = {notify: notify} unless notify.nil?
58
+
59
+ attributes = {}
60
+ attributes[:enterprise] = nil if enterprise.nil? #this is a special condition where setting this to nil means to roll this user out of the enterprise
61
+ attributes[:name] = name unless name.nil?
62
+ attributes[:role] = role unless role.nil?
63
+ attributes[:language] = language unless language.nil?
64
+ attributes[:is_sync_enabled] = is_sync_enabled unless is_sync_enabled.nil?
65
+ attributes[:job_title] = job_title unless job_title.nil?
66
+ attributes[:phone] = phone unless phone.nil?
67
+ attributes[:address] = address unless address.nil?
68
+ attributes[:space_amount] = space_amount unless space_amount.nil?
69
+ attributes[:tracking_codes] = tracking_codes unless tracking_codes.nil?
70
+ attributes[:can_see_managed_users] = can_see_managed_users unless can_see_managed_users.nil?
71
+ attributes[:status] = status unless status.nil?
72
+ attributes[:timezone] = timezone unless timezone.nil?
73
+ attributes[:is_exempt_from_device_limits] = is_exempt_from_device_limits unless is_exempt_from_device_limits.nil?
74
+ attributes[:is_exempt_from_login_verification] = is_exempt_from_login_verification unless is_exempt_from_login_verification.nil?
75
+ attributes[:is_exempt_from_reset_required] = is_exempt_from_reset_required unless is_exempt_from_reset_required.nil?
76
+ attributes[:is_external_collab_restricted] = is_external_collab_restricted unless is_external_collab_restricted.nil?
77
+
78
+ updated_user, response = put(uri, attributes, query: query)
79
+ updated_user
80
+ end
81
+
82
+ def delete_user(user_id, notify: nil, force: nil)
83
+ uri = "#{USERS_URI}/#{user_id}"
84
+ query = {}
85
+ query[:notify] = notify unless notify.nil?
86
+ query[:force] = force unless force.nil?
87
+ result, response = delete(uri, query: query)
88
+ result
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ module Boxr
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Boxr do
4
+
5
+ #follow the directions in .env.example to set up your BOX_DEVELOPER_TOKEN
6
+ BOX_CLIENT = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'])
7
+
8
+ #uncomment this line to see the HTTP request and response debug info
9
+ #BOX_CLIENT.debug_device = STDOUT
10
+
11
+ it 'lists folder items' do
12
+ items = BOX_CLIENT.folder_items(Boxr::ROOT)
13
+ expect(items).to be_a Array
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ require 'dotenv'; Dotenv.load
2
+ require 'boxr'
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boxr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chad Burnette
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: oj
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.11'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httpclient
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.5'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hashie
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.3'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.3'
111
+ description: ''
112
+ email:
113
+ - chadburnette@me.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".env.example"
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - boxr.gemspec
125
+ - lib/boxr.rb
126
+ - lib/boxr/client.rb
127
+ - lib/boxr/collaborations.rb
128
+ - lib/boxr/comments.rb
129
+ - lib/boxr/exceptions.rb
130
+ - lib/boxr/files.rb
131
+ - lib/boxr/folders.rb
132
+ - lib/boxr/groups.rb
133
+ - lib/boxr/metadata.rb
134
+ - lib/boxr/search.rb
135
+ - lib/boxr/shared_items.rb
136
+ - lib/boxr/tasks.rb
137
+ - lib/boxr/users.rb
138
+ - lib/boxr/version.rb
139
+ - spec/boxr_spec.rb
140
+ - spec/spec_helper.rb
141
+ homepage: https://github.com/cburnette/boxr
142
+ licenses:
143
+ - MIT
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.4.1
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: A Ruby client library for the Box V2 Content API that covers 100% of the
165
+ underlying REST API.
166
+ test_files:
167
+ - spec/boxr_spec.rb
168
+ - spec/spec_helper.rb