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)
@access_token = access_token || ENV['DOCBASE_ACCESS_TOKEN']
self.team = team
@url = url || DEFAULT_URL
end
|
Instance Attribute Details
#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
46
47
48
49
50
51
52
|
# File 'lib/docbase/client.rb', line 46
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
86
87
88
|
# File 'lib/docbase/client.rb', line 86
def archive_post(id)
connection.put("/teams/#{team!}/posts/#{id}/archive")
end
|
94
95
96
97
98
99
100
|
# File 'lib/docbase/client.rb', line 94
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
42
43
44
|
# File 'lib/docbase/client.rb', line 42
def create_group(params)
connection.post("/teams/#{team!}/groups", params)
end
|
#create_post(params) ⇒ Object
70
71
72
|
# File 'lib/docbase/client.rb', line 70
def create_post(params)
connection.post("/teams/#{team!}/posts", params)
end
|
102
103
104
|
# File 'lib/docbase/client.rb', line 102
def (id)
connection.delete("/teams/#{team!}/comments/#{id}")
end
|
#delete_post(id) ⇒ Object
82
83
84
|
# File 'lib/docbase/client.rb', line 82
def delete_post(id)
connection.delete("/teams/#{team!}/posts/#{id}")
end
|
#group(id) ⇒ Object
38
39
40
|
# File 'lib/docbase/client.rb', line 38
def group(id)
connection.get("/teams/#{team!}/groups/#{id}")
end
|
#groups ⇒ Object
34
35
36
|
# File 'lib/docbase/client.rb', line 34
def groups
connection.get("/teams/#{team!}/groups")
end
|
#post(id) ⇒ Object
62
63
64
|
# File 'lib/docbase/client.rb', line 62
def post(id)
connection.get("/teams/#{team!}/posts/#{id}")
end
|
#posts(q: '*', page: 1, per_page: 20) ⇒ Object
66
67
68
|
# File 'lib/docbase/client.rb', line 66
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
54
55
56
57
58
59
60
|
# File 'lib/docbase/client.rb', line 54
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
|
30
31
32
|
# File 'lib/docbase/client.rb', line 30
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
|
#teams ⇒ Object
22
23
24
|
# File 'lib/docbase/client.rb', line 22
def teams
connection.get('/teams')
end
|
#unarchive_post(id) ⇒ Object
90
91
92
|
# File 'lib/docbase/client.rb', line 90
def unarchive_post(id)
connection.put("/teams/#{team!}/posts/#{id}/unarchive")
end
|
#update_post(params) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/docbase/client.rb', line 74
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
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/docbase/client.rb', line 106
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
26
27
28
|
# File 'lib/docbase/client.rb', line 26
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
|