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
66
67
68
69
70
71
72
|
# File 'lib/docbase/client.rb', line 66
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
50
51
52
|
# File 'lib/docbase/client.rb', line 50
def create_post(params)
connection.post("/teams/#{team!}/posts", params)
end
|
74
75
76
|
# File 'lib/docbase/client.rb', line 74
def (id)
connection.delete("/teams/#{team!}/comments/#{id}")
end
|
#delete_post(id) ⇒ Object
62
63
64
|
# File 'lib/docbase/client.rb', line 62
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
42
43
44
|
# File 'lib/docbase/client.rb', line 42
def post(id)
connection.get("/teams/#{team!}/posts/#{id}")
end
|
#posts(q: '*', page: 1, per_page: 20) ⇒ Object
46
47
48
|
# File 'lib/docbase/client.rb', line 46
def posts(q: '*', page: 1, per_page: 20)
connection.get("/teams/#{team!}/posts", q: q, page: page, per_page: per_page)
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
|
#teams ⇒ Object
22
23
24
|
# File 'lib/docbase/client.rb', line 22
def teams
connection.get('/teams')
end
|
#update_post(params) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/docbase/client.rb', line 54
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
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/docbase/client.rb', line 78
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
|