-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathboxr.rb
89 lines (75 loc) · 1.92 KB
/
boxr.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'json'
require 'httpclient'
require 'hashie'
require 'addressable/template'
require 'jwt'
require 'securerandom'
require 'stringio'
require 'boxr/version'
require 'boxr/errors'
require 'boxr/client'
require 'boxr/shared_items'
require 'boxr/folders'
require 'boxr/files'
require 'boxr/chunked_uploads'
require 'boxr/comments'
require 'boxr/users'
require 'boxr/groups'
require 'boxr/collaborations'
require 'boxr/collections'
require 'boxr/search'
require 'boxr/tasks'
require 'boxr/metadata'
require 'boxr/events'
require 'boxr/auth'
require 'boxr/web_links'
require 'boxr/watermarking'
require 'boxr/webhooks'
require 'boxr/webhook_validator'
class BoxrCollection < Array
def files
collection_for_type('file')
end
def folders
collection_for_type('folder')
end
def web_links
collection_for_type('web_link')
end
private
def collection_for_type(type)
items = select { |i| i.type == type }
BoxrCollection.new(items)
end
end
class BoxrMash < Hashie::Mash
self.disable_warnings
def entries
self["entries"]
end
def size
self["size"]
end
end
module Boxr
#The root folder in Box is always identified by 0
ROOT = 0
#HTTPClient is high-performance, thread-safe, and supports persistent HTTPS connections
#http://bibwild.wordpress.com/2012/04/30/ruby-http-performance-shootout-redux/
BOX_CLIENT = HTTPClient.new
BOX_CLIENT.cookie_manager = nil
BOX_CLIENT.send_timeout = 3600 #one hour; needed for lengthy uploads
BOX_CLIENT.agent_name = "Boxr/#{Boxr::VERSION}"
BOX_CLIENT.transparent_gzip_decompression = true
#BOX_CLIENT.ssl_config.add_trust_ca("/Users/cburnette/code/ssh-keys/dev_root_ca.pem")
def self.turn_on_debugging(device=STDOUT)
BOX_CLIENT.debug_dev = device
BOX_CLIENT.transparent_gzip_decompression = false
nil
end
def self.turn_off_debugging
BOX_CLIENT.debug_dev = nil
BOX_CLIENT.transparent_gzip_decompression = true
nil
end
end