boxnet 0.0.11 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/boxnet.rb +129 -6
- data/lib/boxnet/version.rb +1 -1
- data/lib/file.rb +1 -27
- data/lib/file_node.rb +1 -37
- data/lib/file_tree.rb +1 -8
- data/lib/folder.rb +1 -20
- data/lib/result.rb +1 -14
- data/lib/ticket.rb +1 -13
- metadata +1 -1
data/lib/boxnet.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'json'
|
3
|
-
require 'result'
|
4
|
-
require 'file_node'
|
5
|
-
require 'file_tree'
|
6
|
-
require 'folder'
|
7
|
-
require 'file'
|
8
|
-
require 'ticket'
|
9
3
|
|
10
4
|
module BoxnetApi
|
11
5
|
class Client
|
@@ -45,4 +39,133 @@ module BoxnetApi
|
|
45
39
|
Result.new(raw_result)
|
46
40
|
end
|
47
41
|
end
|
42
|
+
|
43
|
+
class FileNode
|
44
|
+
attr :files, :folders
|
45
|
+
|
46
|
+
def process_node(data)
|
47
|
+
# return data.nil?
|
48
|
+
@files = []
|
49
|
+
@folders = []
|
50
|
+
|
51
|
+
if data.has_key?("folder")
|
52
|
+
puts "1" if data["folder"].nil?
|
53
|
+
self.folders << BoxnetApi::Folder.new(data["folder"])
|
54
|
+
elsif data.has_key?("folders")
|
55
|
+
folder = data["folders"]["folder"]
|
56
|
+
|
57
|
+
if folder.class == Array
|
58
|
+
folder.each do |f|
|
59
|
+
self.folders << BoxnetApi::Folder.new(f)
|
60
|
+
end
|
61
|
+
elsif folder.class == Hash
|
62
|
+
self.folders << BoxnetApi::Folder.new(folder)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
if data.has_key?("files")
|
67
|
+
file = data["files"]["file"]
|
68
|
+
|
69
|
+
if file.class == Array
|
70
|
+
file.each do |f|
|
71
|
+
self.files << BoxnetApi::File.new(f)
|
72
|
+
end
|
73
|
+
elsif file.class == Hash
|
74
|
+
self.files << BoxnetApi::File.new(file)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
class File < FileNode
|
82
|
+
attr :id, :name, :description, :file_count, :sha1, :size
|
83
|
+
attr :tags, :shared, :created, :updated, :user_id, :shared_link
|
84
|
+
attr :thumbnail, :small_thumbnail, :large_thumbnail, :larger_thumbnail, :preview_thumbnail
|
85
|
+
|
86
|
+
def initialize(data)
|
87
|
+
@id = data["id"]
|
88
|
+
@name = data["file_name"]
|
89
|
+
@description = data["description"]
|
90
|
+
@file_count = data["file_count"]
|
91
|
+
@sha1 = data["sha1"]
|
92
|
+
@size = data["size"]
|
93
|
+
@tags = data["tags"]
|
94
|
+
@shared = data["shared"]
|
95
|
+
@created = data["created"]
|
96
|
+
@updated = data["updated"]
|
97
|
+
@user_id = data["user_id"]
|
98
|
+
@shared_link = data["shared_link"]
|
99
|
+
@thumbnail = data["thumbnail"]
|
100
|
+
@small_thumbnail = data["small_thumbnail"]
|
101
|
+
@large_thumbnail = data["large_thumbnail"]
|
102
|
+
@larger_thumbnail = data["larger_thumbnail"]
|
103
|
+
@preview_thumbnail = data["preview_thumbnail"]
|
104
|
+
process_node(data)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
class Folder < FileNode
|
110
|
+
attr :id, :name, :description, :file_count, :user_id
|
111
|
+
attr :shared, :shared_link, :permission, :size, :created, :updated
|
112
|
+
|
113
|
+
def initialize(data)
|
114
|
+
@id = data["id"]
|
115
|
+
@name = data["name"]
|
116
|
+
@description = data["description"]
|
117
|
+
@file_count = data["file_count"]
|
118
|
+
@user_id = data["user_id"]
|
119
|
+
@shared = data["shared"]
|
120
|
+
@shared_link = data["shared_link"]
|
121
|
+
@permission = data["permission"]
|
122
|
+
@size = data["size"]
|
123
|
+
@created = data["created"]
|
124
|
+
@updated = data["updated"]
|
125
|
+
process_node(data)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
class Result
|
133
|
+
attr :raw_result, :file_tree
|
134
|
+
|
135
|
+
def initialize(raw_result)
|
136
|
+
@raw_result = raw_result
|
137
|
+
unless status == "Wrong input"
|
138
|
+
@file_tree = BoxnetApi::FileTree.new(raw_result)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def status
|
143
|
+
@raw_result["response"]["status"]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
class FileTree < FileNode
|
149
|
+
|
150
|
+
def initialize(raw_result)
|
151
|
+
tree_data = raw_result["response"]["tree"]
|
152
|
+
process_node(tree_data)
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
class Ticket
|
158
|
+
attr :ticket, :status
|
159
|
+
|
160
|
+
def initialize(data)
|
161
|
+
@ticket = data["response"]["ticket"]
|
162
|
+
@status = data["response"]["status"]
|
163
|
+
end
|
164
|
+
|
165
|
+
def url
|
166
|
+
"https://www.box.net/api/1.0/auth/#{@ticket}"
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
48
171
|
end
|
data/lib/boxnet/version.rb
CHANGED
data/lib/file.rb
CHANGED
@@ -1,29 +1,3 @@
|
|
1
1
|
module BoxnetApi
|
2
|
-
|
3
|
-
attr :id, :name, :description, :file_count, :sha1, :size
|
4
|
-
attr :tags, :shared, :created, :updated, :user_id, :shared_link
|
5
|
-
attr :thumbnail, :small_thumbnail, :large_thumbnail, :larger_thumbnail, :preview_thumbnail
|
6
|
-
|
7
|
-
def initialize(data)
|
8
|
-
@id = data["id"]
|
9
|
-
@name = data["file_name"]
|
10
|
-
@description = data["description"]
|
11
|
-
@file_count = data["file_count"]
|
12
|
-
@sha1 = data["sha1"]
|
13
|
-
@size = data["size"]
|
14
|
-
@tags = data["tags"]
|
15
|
-
@shared = data["shared"]
|
16
|
-
@created = data["created"]
|
17
|
-
@updated = data["updated"]
|
18
|
-
@user_id = data["user_id"]
|
19
|
-
@shared_link = data["shared_link"]
|
20
|
-
@thumbnail = data["thumbnail"]
|
21
|
-
@small_thumbnail = data["small_thumbnail"]
|
22
|
-
@large_thumbnail = data["large_thumbnail"]
|
23
|
-
@larger_thumbnail = data["larger_thumbnail"]
|
24
|
-
@preview_thumbnail = data["preview_thumbnail"]
|
25
|
-
process_node(data)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
2
|
+
|
29
3
|
end
|
data/lib/file_node.rb
CHANGED
@@ -1,40 +1,4 @@
|
|
1
1
|
module BoxnetApi
|
2
|
-
|
3
|
-
attr :files, :folders
|
4
|
-
|
5
|
-
def process_node(data)
|
6
|
-
# return data.nil?
|
7
|
-
@files = []
|
8
|
-
@folders = []
|
9
|
-
|
10
|
-
if data.has_key?("folder")
|
11
|
-
puts "1" if data["folder"].nil?
|
12
|
-
self.folders << BoxnetApi::Folder.new(data["folder"])
|
13
|
-
elsif data.has_key?("folders")
|
14
|
-
folder = data["folders"]["folder"]
|
15
|
-
|
16
|
-
if folder.class == Array
|
17
|
-
folder.each do |f|
|
18
|
-
self.folders << BoxnetApi::Folder.new(f)
|
19
|
-
end
|
20
|
-
elsif folder.class == Hash
|
21
|
-
self.folders << BoxnetApi::Folder.new(folder)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
if data.has_key?("files")
|
26
|
-
file = data["files"]["file"]
|
27
|
-
|
28
|
-
if file.class == Array
|
29
|
-
file.each do |f|
|
30
|
-
self.files << BoxnetApi::File.new(f)
|
31
|
-
end
|
32
|
-
elsif file.class == Hash
|
33
|
-
self.files << BoxnetApi::File.new(file)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
2
|
+
|
39
3
|
|
40
4
|
end
|
data/lib/file_tree.rb
CHANGED
data/lib/folder.rb
CHANGED
@@ -1,22 +1,3 @@
|
|
1
1
|
module BoxnetApi
|
2
|
-
|
3
|
-
attr :id, :name, :description, :file_count, :user_id
|
4
|
-
attr :shared, :shared_link, :permission, :size, :created, :updated
|
5
|
-
|
6
|
-
def initialize(data)
|
7
|
-
@id = data["id"]
|
8
|
-
@name = data["name"]
|
9
|
-
@description = data["description"]
|
10
|
-
@file_count = data["file_count"]
|
11
|
-
@user_id = data["user_id"]
|
12
|
-
@shared = data["shared"]
|
13
|
-
@shared_link = data["shared_link"]
|
14
|
-
@permission = data["permission"]
|
15
|
-
@size = data["size"]
|
16
|
-
@created = data["created"]
|
17
|
-
@updated = data["updated"]
|
18
|
-
process_node(data)
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
2
|
+
|
22
3
|
end
|
data/lib/result.rb
CHANGED
@@ -1,16 +1,3 @@
|
|
1
1
|
module BoxnetApi
|
2
|
-
|
3
|
-
attr :raw_result, :file_tree
|
4
|
-
|
5
|
-
def initialize(raw_result)
|
6
|
-
@raw_result = raw_result
|
7
|
-
unless status == "Wrong input"
|
8
|
-
@file_tree = BoxnetApi::FileTree.new(raw_result)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def status
|
13
|
-
@raw_result["response"]["status"]
|
14
|
-
end
|
15
|
-
end
|
2
|
+
|
16
3
|
end
|
data/lib/ticket.rb
CHANGED
@@ -1,15 +1,3 @@
|
|
1
1
|
module BoxnetApi
|
2
|
-
|
3
|
-
attr :ticket, :status
|
4
|
-
|
5
|
-
def initialize(data)
|
6
|
-
@ticket = data["response"]["ticket"]
|
7
|
-
@status = data["response"]["status"]
|
8
|
-
end
|
9
|
-
|
10
|
-
def url
|
11
|
-
"https://www.box.net/api/1.0/auth/#{@ticket}"
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
2
|
+
|
15
3
|
end
|