boxr 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,119 +1,119 @@
1
1
  module Boxr
2
- class Client
3
-
4
- def folder_id(path)
5
- if(path.start_with?('/'))
6
- path = path.slice(1..-1)
7
- end
8
-
9
- path_folders = path.split('/')
10
-
11
- folder_id = path_folders.inject(Boxr::ROOT) do |parent_id, folder_name|
12
- folders = folder_items(parent_id, fields: [:id, :name]).folders
13
-
14
- begin
15
- folders.select{|f| f.name == folder_name}.first.id
16
- rescue
17
- raise BoxrException.new(boxr_message: "Folder not found: '#{folder_name}'")
18
- end
19
- end
20
- end
21
-
22
- def folder_items(folder_id, fields: [])
23
- query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
24
- uri = "#{FOLDERS_URI}/#{folder_id}/items"
25
-
26
- items = get_with_pagination uri, query: query, limit: FOLDER_ITEMS_LIMIT
27
- end
28
-
29
- def create_folder(name, parent_id)
30
- uri = "#{FOLDERS_URI}"
31
- attributes = {:name => name, :parent => {:id => parent_id}}
32
-
33
- created_folder, response = post uri, attributes
34
- created_folder
35
- end
36
-
37
- def folder(folder_id, fields: [])
38
- query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
39
- uri = "#{FOLDERS_URI}/#{folder_id}"
40
-
41
- folder, response = get uri, query: query
42
- folder
43
- end
44
-
45
- def update_folder(folder_id, name: nil, description: nil, parent_id: nil, shared_link: nil,
46
- folder_upload_email: nil, owned_by_id: nil, sync_state: nil, tags: nil,
47
- can_non_owners_invite: nil, if_match: nil)
48
- uri = "#{FOLDERS_URI}/#{folder_id}"
49
-
50
- attributes = {}
51
- attributes[:name] = name unless name.nil?
52
- attributes[:description] = description unless description.nil?
53
- attributes[:parent_id] = {id: parent_id} unless parent_id.nil?
54
- attributes[:shared_link] = shared_link unless shared_link.nil?
55
- attributes[:folder_upload_email] = folder_upload_email unless folder_upload_email.nil?
56
- attributes[:owned_by_id] = {owned_by: owned_by_id} unless owned_by_id.nil?
57
- attributes[:sync_state] = sync_state unless sync_state.nil?
58
- attributes[:tags] = tags unless tags.nil?
59
- attributes[:can_non_owners_invite] = can_non_owners_invite unless can_non_owners_invite.nil?
60
-
61
- updated_folder, response = put uri, attributes, if_match: if_match
62
- updated_folder
63
- end
64
-
65
- def delete_folder(folder_id, recursive: false, if_match: nil)
66
- uri = "#{FOLDERS_URI}/#{folder_id}"
67
- query = {:recursive => recursive}
68
-
69
- result, response = delete uri, query: query, if_match: if_match
70
- result
71
- end
72
-
73
- def copy_folder(folder_id, dest_folder_id, name: nil)
74
- uri = "#{FOLDERS_URI}/#{folder_id}/copy"
75
- attributes = {:parent => {:id => dest_folder_id}}
76
- attributes[:name] = name unless name.nil?
77
-
78
- new_folder, response = post uri, attributes
79
- new_folder
80
- end
81
-
82
- def create_shared_link_for_folder(folder_id, access: nil, unshared_at: nil, can_download: nil, can_preview: nil)
83
- uri = "#{FOLDERS_URI}/#{folder_id}"
84
- create_shared_link(uri, folder_id, access, unshared_at, can_download, can_preview)
85
- end
86
-
87
- def disable_shared_link_for_folder(folder_id)
88
- uri = "#{FOLDERS_URI}/#{folder_id}"
89
- disable_shared_link(uri, folder_id)
90
- end
91
-
92
- def trash(fields: [])
93
- uri = "#{FOLDERS_URI}/trash/items"
94
- query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
95
-
96
- items = get_with_pagination uri, query: query, limit: FOLDER_ITEMS_LIMIT
97
- end
98
-
99
- def trashed_folder(folder_id, fields: [])
100
- uri = "#{FOLDERS_URI}/#{folder_id}/trash"
101
- query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
102
-
103
- folder, response = get uri, query: query
104
- folder
105
- end
106
-
107
- def delete_trashed_folder(folder_id)
108
- uri = "#{FOLDERS_URI}/#{folder_id}/trash"
109
- result, response = delete uri
110
- result
111
- end
112
-
113
- def restore_trashed_folder(folder_id, name: nil, parent_id: nil)
114
- uri = "#{FOLDERS_URI}/#{folder_id}"
115
- restore_trashed_item(uri, name, parent_id)
116
- end
117
-
118
- end
2
+ class Client
3
+
4
+ def folder_id(path)
5
+ if(path.start_with?('/'))
6
+ path = path.slice(1..-1)
7
+ end
8
+
9
+ path_folders = path.split('/')
10
+
11
+ folder_id = path_folders.inject(Boxr::ROOT) do |parent_id, folder_name|
12
+ folders = folder_items(parent_id, fields: [:id, :name]).folders
13
+
14
+ begin
15
+ folders.select{|f| f.name == folder_name}.first.id
16
+ rescue
17
+ raise BoxrException.new(boxr_message: "Folder not found: '#{folder_name}'")
18
+ end
19
+ end
20
+ end
21
+
22
+ def folder_items(folder_id, fields: [])
23
+ query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
24
+ uri = "#{FOLDERS_URI}/#{folder_id}/items"
25
+
26
+ items = get_with_pagination uri, query: query, limit: FOLDER_ITEMS_LIMIT
27
+ end
28
+
29
+ def create_folder(name, parent_id)
30
+ uri = "#{FOLDERS_URI}"
31
+ attributes = {:name => name, :parent => {:id => parent_id}}
32
+
33
+ created_folder, response = post uri, attributes
34
+ created_folder
35
+ end
36
+
37
+ def folder(folder_id, fields: [])
38
+ query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
39
+ uri = "#{FOLDERS_URI}/#{folder_id}"
40
+
41
+ folder, response = get uri, query: query
42
+ folder
43
+ end
44
+
45
+ def update_folder(folder_id, name: nil, description: nil, parent_id: nil, shared_link: nil,
46
+ folder_upload_email_access: nil, owned_by_id: nil, sync_state: nil, tags: nil,
47
+ can_non_owners_invite: nil, if_match: nil)
48
+ uri = "#{FOLDERS_URI}/#{folder_id}"
49
+
50
+ attributes = {}
51
+ attributes[:name] = name unless name.nil?
52
+ attributes[:description] = description unless description.nil?
53
+ attributes[:parent_id] = {id: parent_id} unless parent_id.nil?
54
+ attributes[:shared_link] = shared_link unless shared_link.nil?
55
+ attributes[:folder_upload_email] = {access: folder_upload_email_access} unless folder_upload_email_access.nil?
56
+ attributes[:owned_by_id] = {owned_by: owned_by_id} unless owned_by_id.nil?
57
+ attributes[:sync_state] = sync_state unless sync_state.nil?
58
+ attributes[:tags] = tags unless tags.nil?
59
+ attributes[:can_non_owners_invite] = can_non_owners_invite unless can_non_owners_invite.nil?
60
+
61
+ updated_folder, response = put uri, attributes, if_match: if_match
62
+ updated_folder
63
+ end
64
+
65
+ def delete_folder(folder_id, recursive: false, if_match: nil)
66
+ uri = "#{FOLDERS_URI}/#{folder_id}"
67
+ query = {:recursive => recursive}
68
+
69
+ result, response = delete uri, query: query, if_match: if_match
70
+ result
71
+ end
72
+
73
+ def copy_folder(folder_id, dest_folder_id, name: nil)
74
+ uri = "#{FOLDERS_URI}/#{folder_id}/copy"
75
+ attributes = {:parent => {:id => dest_folder_id}}
76
+ attributes[:name] = name unless name.nil?
77
+
78
+ new_folder, response = post uri, attributes
79
+ new_folder
80
+ end
81
+
82
+ def create_shared_link_for_folder(folder_id, access: nil, unshared_at: nil, can_download: nil, can_preview: nil)
83
+ uri = "#{FOLDERS_URI}/#{folder_id}"
84
+ create_shared_link(uri, folder_id, access, unshared_at, can_download, can_preview)
85
+ end
86
+
87
+ def disable_shared_link_for_folder(folder_id)
88
+ uri = "#{FOLDERS_URI}/#{folder_id}"
89
+ disable_shared_link(uri, folder_id)
90
+ end
91
+
92
+ def trash(fields: [])
93
+ uri = "#{FOLDERS_URI}/trash/items"
94
+ query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
95
+
96
+ items = get_with_pagination uri, query: query, limit: FOLDER_ITEMS_LIMIT
97
+ end
98
+
99
+ def trashed_folder(folder_id, fields: [])
100
+ uri = "#{FOLDERS_URI}/#{folder_id}/trash"
101
+ query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
102
+
103
+ folder, response = get uri, query: query
104
+ folder
105
+ end
106
+
107
+ def delete_trashed_folder(folder_id)
108
+ uri = "#{FOLDERS_URI}/#{folder_id}/trash"
109
+ result, response = delete uri
110
+ result
111
+ end
112
+
113
+ def restore_trashed_folder(folder_id, name: nil, parent_id: nil)
114
+ uri = "#{FOLDERS_URI}/#{folder_id}"
115
+ restore_trashed_item(uri, name, parent_id)
116
+ end
117
+
118
+ end
119
119
  end
@@ -1,78 +1,78 @@
1
1
  module Boxr
2
- class Client
2
+ class Client
3
3
 
4
- def groups(fields: [])
5
- query = build_fields_query(fields, GROUP_FIELDS_QUERY)
6
- groups = get_with_pagination(GROUPS_URI, query: query)
7
- end
4
+ def groups(fields: [])
5
+ query = build_fields_query(fields, GROUP_FIELDS_QUERY)
6
+ groups = get_with_pagination(GROUPS_URI, query: query)
7
+ end
8
8
 
9
- def create_group(name)
10
- attributes = {name: name}
11
- new_group, response = post(GROUPS_URI, attributes)
12
- new_group
13
- end
9
+ def create_group(name)
10
+ attributes = {name: name}
11
+ new_group, response = post(GROUPS_URI, attributes)
12
+ new_group
13
+ end
14
14
 
15
- def update_group(group_id, name)
16
- uri = "#{GROUPS_URI}/#{group_id}"
17
- attributes = {name: name}
15
+ def update_group(group_id, name)
16
+ uri = "#{GROUPS_URI}/#{group_id}"
17
+ attributes = {name: name}
18
18
 
19
- updated_group, response = put(uri, attributes)
20
- updated_group
21
- end
19
+ updated_group, response = put(uri, attributes)
20
+ updated_group
21
+ end
22
22
 
23
- alias :rename_group :update_group
23
+ alias :rename_group :update_group
24
24
 
25
- def delete_group(group_id)
26
- uri = "#{GROUPS_URI}/#{group_id}"
27
- result, response = delete(uri)
28
- result
29
- end
25
+ def delete_group(group_id)
26
+ uri = "#{GROUPS_URI}/#{group_id}"
27
+ result, response = delete(uri)
28
+ result
29
+ end
30
30
 
31
- def group_memberships(group_id)
32
- uri = "#{GROUPS_URI}/#{group_id}/memberships"
33
- memberships = get_with_pagination(uri)
34
- end
31
+ def group_memberships(group_id)
32
+ uri = "#{GROUPS_URI}/#{group_id}/memberships"
33
+ memberships = get_with_pagination(uri)
34
+ end
35
35
 
36
- def group_memberships_for_user(user_id)
37
- uri = "#{USERS_URI}/#{user_id}/memberships"
38
- memberships = get_with_pagination(uri)
39
- end
36
+ def group_memberships_for_user(user_id)
37
+ uri = "#{USERS_URI}/#{user_id}/memberships"
38
+ memberships = get_with_pagination(uri)
39
+ end
40
40
 
41
- def group_memberships_for_me
42
- uri = "#{USERS_URI}/me/memberships"
43
- memberships = get_with_pagination(uri)
44
- end
41
+ def group_memberships_for_me
42
+ uri = "#{USERS_URI}/me/memberships"
43
+ memberships = get_with_pagination(uri)
44
+ end
45
45
 
46
- def group_membership(membership_id)
47
- uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
48
- membership, response = get(uri)
49
- membership
50
- end
46
+ def group_membership(membership_id)
47
+ uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
48
+ membership, response = get(uri)
49
+ membership
50
+ end
51
51
 
52
- def add_user_to_group(user_id, group_id, role: nil)
53
- attributes = {user: {id: user_id}, group: {id: group_id}}
54
- attributes[:role] = role unless role.nil?
55
- membership, response = post(GROUP_MEMBERSHIPS_URI, attributes)
56
- membership
57
- end
52
+ def add_user_to_group(user_id, group_id, role: nil)
53
+ attributes = {user: {id: user_id}, group: {id: group_id}}
54
+ attributes[:role] = role unless role.nil?
55
+ membership, response = post(GROUP_MEMBERSHIPS_URI, attributes)
56
+ membership
57
+ end
58
58
 
59
- def update_group_membership(membership_id, role)
60
- uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
61
- attributes = {role: role}
62
- updated_membership, response = put(uri, attributes)
63
- updated_membership
64
- end
59
+ def update_group_membership(membership_id, role)
60
+ uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
61
+ attributes = {role: role}
62
+ updated_membership, response = put(uri, attributes)
63
+ updated_membership
64
+ end
65
65
 
66
- def delete_group_membership(membership_id)
67
- uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
68
- result, response = delete(uri)
69
- result
70
- end
66
+ def delete_group_membership(membership_id)
67
+ uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
68
+ result, response = delete(uri)
69
+ result
70
+ end
71
71
 
72
- def group_collaborations(group_id)
73
- uri = "#{GROUPS_URI}/#{group_id}/collaborations"
74
- collaborations = get_with_pagination(uri)
75
- end
72
+ def group_collaborations(group_id)
73
+ uri = "#{GROUPS_URI}/#{group_id}/collaborations"
74
+ collaborations = get_with_pagination(uri)
75
+ end
76
76
 
77
- end
77
+ end
78
78
  end
@@ -1,29 +1,29 @@
1
1
  module Boxr
2
- class Client
2
+ class Client
3
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
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
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
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
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
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
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
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
27
 
28
- end
28
+ end
29
29
  end
@@ -1,26 +1,26 @@
1
1
  module Boxr
2
- class Client
2
+ class Client
3
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)
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
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?
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
20
 
21
- results, response = get SEARCH_URI, query: query
22
- results["entries"]
23
- end
21
+ results, response = get SEARCH_URI, query: query
22
+ results["entries"]
23
+ end
24
24
 
25
- end
25
+ end
26
26
  end