Module: Boxr
- Defined in:
- lib/boxr.rb,
lib/boxr/auth.rb,
lib/boxr/files.rb,
lib/boxr/tasks.rb,
lib/boxr/users.rb,
lib/boxr/client.rb,
lib/boxr/errors.rb,
lib/boxr/events.rb,
lib/boxr/groups.rb,
lib/boxr/search.rb,
lib/boxr/folders.rb,
lib/boxr/version.rb,
lib/boxr/comments.rb,
lib/boxr/metadata.rb,
lib/boxr/collections.rb,
lib/boxr/shared_items.rb,
lib/boxr/collaborations.rb
Defined Under Namespace
Classes: BoxrError, Client
Constant Summary
collapse
- ROOT =
The root folder in Box is always identified by 0
0
- BOX_CLIENT =
HTTPClient.new
- JWT_GRANT_TYPE =
"urn:ietf:params:oauth:grant-type:jwt-bearer"
- VERSION =
"0.29.0"
Class Method Summary
collapse
-
.get_enterprise_token(private_key: , private_key_password: , enterprise_id: , client_id: , client_secret: ) ⇒ Object
-
.get_tokens(code = nil, grant_type: "authorization_code", assertion: nil, scope: nil, username: nil, client_id: , client_secret: ) ⇒ Object
(also: get_token)
-
.get_user_token(user_id, private_key: , private_key_password: , client_id: , client_secret: ) ⇒ Object
-
.oauth_url(state, host: "app.box.com", response_type: "code", scope: nil, folder_id: nil, client_id: ENV['BOX_CLIENT_ID']) ⇒ Object
-
.refresh_tokens(refresh_token, client_id: , client_secret: ) ⇒ Object
(also: refresh_token)
-
.revoke_tokens(token, client_id: , client_secret: ) ⇒ Object
(also: revoke_token)
-
.turn_off_debugging ⇒ Object
-
.turn_on_debugging(device = STDOUT) ⇒ Object
BOX_CLIENT.ssl_config.add_trust_ca(“/Users/cburnette/code/ssh-keys/dev_root_ca.pem”).
Class Method Details
.get_enterprise_token(private_key: , private_key_password: , enterprise_id: , client_id: , client_secret: ) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/boxr/auth.rb', line 27
def self.get_enterprise_token(private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'],
enterprise_id: ENV['BOX_ENTERPRISE_ID'], client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
unlocked_private_key = unlock_key(private_key, private_key_password)
assertion = jwt_assertion(unlocked_private_key, client_id, enterprise_id, "enterprise")
get_token(grant_type: JWT_GRANT_TYPE, assertion: assertion, client_id: client_id, client_secret: client_secret)
end
|
.get_tokens(code = nil, grant_type: "authorization_code", assertion: nil, scope: nil, username: nil, client_id: , client_secret: ) ⇒ Object
Also known as:
get_token
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/boxr/auth.rb', line 16
def self.get_tokens(code=nil, grant_type: "authorization_code", assertion: nil, scope: nil, username: nil, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
uri = "https://api.box.com/oauth2/token"
body = "grant_type=#{grant_type}&client_id=#{client_id}&client_secret=#{client_secret}"
body = body + "&code=#{code}" unless code.nil?
body = body + "&scope=#{scope}" unless scope.nil?
body = body + "&username=#{username}" unless username.nil?
body = body + "&assertion=#{assertion}" unless assertion.nil?
auth_post(uri, body)
end
|
.get_user_token(user_id, private_key: , private_key_password: , client_id: , client_secret: ) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/boxr/auth.rb', line 34
def self.get_user_token(user_id, private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'],
client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
unlocked_private_key = unlock_key(private_key, private_key_password)
assertion = jwt_assertion(unlocked_private_key, client_id, user_id, "user")
get_token(grant_type: JWT_GRANT_TYPE, assertion: assertion, client_id: client_id, client_secret: client_secret)
end
|
.oauth_url(state, host: "app.box.com", response_type: "code", scope: nil, folder_id: nil, client_id: ENV['BOX_CLIENT_ID']) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/boxr/auth.rb', line 5
def self.oauth_url(state, host: "app.box.com", response_type: "code", scope: nil, folder_id: nil, client_id: ENV['BOX_CLIENT_ID'])
template = Addressable::Template.new("https://{host}/api/oauth2/authorize{?query*}")
query = {"response_type" => "#{response_type}", "state" => "#{state}", "client_id" => "#{client_id}"}
query["scope"] = "#{scope}" unless scope.nil?
query["folder_id"] = "#{folder_id}" unless folder_id.nil?
uri = template.expand({"host" => "#{host}", "query" => query})
uri
end
|
.refresh_tokens(refresh_token, client_id: , client_secret: ) ⇒ Object
Also known as:
refresh_token
41
42
43
44
45
46
|
# File 'lib/boxr/auth.rb', line 41
def self.refresh_tokens(refresh_token, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
uri = "https://api.box.com/oauth2/token"
body = "grant_type=refresh_token&refresh_token=#{refresh_token}&client_id=#{client_id}&client_secret=#{client_secret}"
auth_post(uri, body)
end
|
.revoke_tokens(token, client_id: , client_secret: ) ⇒ Object
Also known as:
revoke_token
48
49
50
51
52
53
|
# File 'lib/boxr/auth.rb', line 48
def self.revoke_tokens(token, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
uri = "https://api.box.com/oauth2/revoke"
body = "client_id=#{client_id}&client_secret=#{client_secret}&token=#{token}"
auth_post(uri, body)
end
|
.turn_off_debugging ⇒ Object
70
71
72
73
74
|
# File 'lib/boxr.rb', line 70
def self.turn_off_debugging
BOX_CLIENT.debug_dev = nil
BOX_CLIENT.transparent_gzip_decompression = true
nil
end
|
.turn_on_debugging(device = STDOUT) ⇒ Object
BOX_CLIENT.ssl_config.add_trust_ca(“/Users/cburnette/code/ssh-keys/dev_root_ca.pem”)
64
65
66
67
68
|
# File 'lib/boxr.rb', line 64
def self.turn_on_debugging(device=STDOUT)
BOX_CLIENT.debug_dev = device
BOX_CLIENT.transparent_gzip_decompression = false
nil
end
|