Class: DocBase::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/docbase/client.rb
Defined Under Namespace
Classes: NotSetPostIdError, NotSetTeamError
Constant Summary
collapse
- DEFAULT_URL =
'https://api.docbase.io'
- USER_AGENT =
"DocBase Ruby Gem #{DocBase::VERSION}"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(access_token: nil, url: nil, team: nil) ⇒ Client
Returns a new instance of Client.
11
12
13
14
15
|
# File 'lib/docbase/client.rb', line 11
def initialize(access_token: nil, url: nil, team: nil)
self.access_token = access_token
self.team = team
@url = url || DEFAULT_URL
end
|
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
9
10
11
|
# File 'lib/docbase/client.rb', line 9
def access_token
@access_token
end
|
#team ⇒ Object
Returns the value of attribute team.
9
10
11
|
# File 'lib/docbase/client.rb', line 9
def team
@team
end
|
Instance Method Details
#add_users_to_group(params) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/docbase/client.rb', line 42
def add_users_to_group(params)
group_id = params[:group_id].to_i
raise NotSetTeamError if group_id <= 0
users_params = except(params, :group_id)
connection.post("/teams/#{team!}/groups/#{group_id}/users", users_params)
end
|
#archive_post(id) ⇒ Object
82
83
84
|
# File 'lib/docbase/client.rb', line 82
def archive_post(id)
connection.put("/teams/#{team!}/posts/#{id}/archive")
end
|
90
91
92
93
94
95
96
|
# File 'lib/docbase/client.rb', line 90
def (params)
post_id = params[:post_id].to_i
raise NotSetTeamError if post_id <= 0
= except(params, :post_id)
connection.post("/teams/#{team!}/posts/#{post_id}/comments", params)
end
|
#create_group(params) ⇒ Object
38
39
40
|
# File 'lib/docbase/client.rb', line 38
def create_group(params)
connection.post("/teams/#{team!}/groups", params)
end
|
#create_post(params) ⇒ Object
66
67
68
|
# File 'lib/docbase/client.rb', line 66
def create_post(params)
connection.post("/teams/#{team!}/posts", params)
end
|
98
99
100
|
# File 'lib/docbase/client.rb', line 98
def (id)
connection.delete("/teams/#{team!}/comments/#{id}")
end
|
#delete_post(id) ⇒ Object
78
79
80
|
# File 'lib/docbase/client.rb', line 78
def delete_post(id)
connection.delete("/teams/#{team!}/posts/#{id}")
end
|
#group(id) ⇒ Object
34
35
36
|
# File 'lib/docbase/client.rb', line 34
def group(id)
connection.get("/teams/#{team!}/groups/#{id}")
end
|
#groups ⇒ Object
30
31
32
|
# File 'lib/docbase/client.rb', line 30
def groups
connection.get("/teams/#{team!}/groups")
end
|
#post(id) ⇒ Object
58
59
60
|
# File 'lib/docbase/client.rb', line 58
def post(id)
connection.get("/teams/#{team!}/posts/#{id}")
end
|
#posts(q: '*', page: 1, per_page: 20) ⇒ Object
62
63
64
|
# File 'lib/docbase/client.rb', line 62
def posts(q: '*', page: 1, per_page: 20)
connection.get("/teams/#{team!}/posts", q: q, page: page, per_page: per_page)
end
|
#remove_users_from_group(params) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/docbase/client.rb', line 50
def remove_users_from_group(params)
group_id = params[:group_id].to_i
raise NotSetTeamError if group_id <= 0
users_params = except(params, :group_id)
connection.delete("/teams/#{team!}/groups/#{group_id}/users", users_params)
end
|
26
27
28
|
# File 'lib/docbase/client.rb', line 26
def tags
connection.get("/teams/#{team!}/tags")
end
|
#team! ⇒ Object
17
18
19
20
|
# File 'lib/docbase/client.rb', line 17
def team!
raise NotSetTeamError unless @team
@team
end
|
#unarchive_post(id) ⇒ Object
86
87
88
|
# File 'lib/docbase/client.rb', line 86
def unarchive_post(id)
connection.put("/teams/#{team!}/posts/#{id}/unarchive")
end
|
#update_post(params) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/docbase/client.rb', line 70
def update_post(params)
post_id = params[:id].to_i
raise NotSetTeamError if post_id <= 0
post_params = except(params, :id)
connection.patch("/teams/#{team!}/posts/#{post_id}", post_params)
end
|
#upload(paths) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/docbase/client.rb', line 102
def upload(paths)
paths = [paths] unless paths.instance_of?(Array)
params = paths.map do |path|
file = File.new(path, 'r+b')
{
name: file.path.split('/').last,
content: Base64.strict_encode64(file.read),
}
end
connection.post("/teams/#{team!}/attachments", params)
end
|
#users(q: nil, page: 1, per_page: 100, include_user_groups: false) ⇒ Object
22
23
24
|
# File 'lib/docbase/client.rb', line 22
def users(q: nil, page: 1, per_page: 100, include_user_groups: false)
connection.get("/teams/#{team!}/users", q: q, page: page, per_page: per_page, include_user_groups: include_user_groups)
end
|