Class: DocBase::Client
- Inherits:
-
Object
- Object
- DocBase::Client
- Defined in:
- lib/docbase/client.rb
Defined Under Namespace
Classes: NotSetPostIdError, NotSetTeamError, TooManyRequestError
Constant Summary collapse
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#retry_on_rate_limit_exceeded ⇒ Object
Returns the value of attribute retry_on_rate_limit_exceeded.
-
#team ⇒ Object
Returns the value of attribute team.
Instance Method Summary collapse
- #add_users_to_group(params) ⇒ Object
- #archive_post(id) ⇒ Object
- #attachment(id) ⇒ Object
- #comments(post_id, page: 1, per_page: 20, order: 'asc', created_after: nil, created_before: nil) ⇒ Object
- #create_comment(params) ⇒ Object
- #create_good_job(post_id, params = {}) ⇒ Object
- #create_group(params) ⇒ Object
- #create_post(params) ⇒ Object
- #delete_comment(id) ⇒ Object
- #delete_good_job(post_id, good_job_id) ⇒ Object
- #delete_post(id) ⇒ Object
- #delete_user(id) ⇒ Object
- #good_jobs(post_id, page: 1, per_page: 100, order: 'asc', created_after: nil, created_before: nil) ⇒ Object
- #group(id) ⇒ Object
- #groups(name: nil, page: 1, per_page: 100) ⇒ Object
-
#initialize(access_token: nil, url: nil, team: nil, retry_on_rate_limit_exceeded: false) ⇒ Client
constructor
A new instance of Client.
- #post(id) ⇒ Object
- #posts(q: '*', page: 1, per_page: 20) ⇒ Object
- #profile ⇒ Object
- #remove_users_from_group(params) ⇒ Object
- #tags ⇒ Object
- #team! ⇒ Object
- #unarchive_post(id) ⇒ Object
- #update_post(params) ⇒ Object
- #update_post_body(params) ⇒ Object
- #upload(paths) ⇒ Object
- #user_groups(user_id, page: 1, per_page: 20) ⇒ Object
- #users(q: nil, page: 1, per_page: 100) ⇒ Object
Constructor Details
#initialize(access_token: nil, url: nil, team: nil, retry_on_rate_limit_exceeded: false) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 |
# File 'lib/docbase/client.rb', line 12 def initialize(access_token: nil, url: nil, team: nil, retry_on_rate_limit_exceeded: false) self.access_token = access_token self.team = team @url = url || DEFAULT_URL self.retry_on_rate_limit_exceeded = retry_on_rate_limit_exceeded end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/docbase/client.rb', line 10 def access_token @access_token end |
#retry_on_rate_limit_exceeded ⇒ Object
Returns the value of attribute retry_on_rate_limit_exceeded.
10 11 12 |
# File 'lib/docbase/client.rb', line 10 def retry_on_rate_limit_exceeded @retry_on_rate_limit_exceeded end |
#team ⇒ Object
Returns the value of attribute team.
10 11 12 |
# File 'lib/docbase/client.rb', line 10 def team @team end |
Instance Method Details
#add_users_to_group(params) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/docbase/client.rb', line 64 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) request(method: :post, path: "/teams/#{team!}/groups/#{group_id}/users", params: users_params) end |
#archive_post(id) ⇒ Object
112 113 114 |
# File 'lib/docbase/client.rb', line 112 def archive_post(id) request(method: :put, path: "/teams/#{team!}/posts/#{id}/archive") end |
#attachment(id) ⇒ Object
182 183 184 |
# File 'lib/docbase/client.rb', line 182 def (id) request(method: :get, path: "/teams/#{team!}/attachments/#{id}", for_binary: true) end |
#comments(post_id, page: 1, per_page: 20, order: 'asc', created_after: nil, created_before: nil) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/docbase/client.rb', line 120 def comments(post_id, page: 1, per_page: 20, order: 'asc', created_after: nil, created_before: nil) request( method: :get, path: "/teams/#{team!}/posts/#{post_id}/comments", params: { page: page, per_page: per_page, order: order, created_after: created_after, created_before: created_before, } ) end |
#create_comment(params) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/docbase/client.rb', line 134 def create_comment(params) post_id = params[:post_id].to_i raise NotSetPostIdError if post_id <= 0 comment_params = except(params, :post_id) request(method: :post, path: "/teams/#{team!}/posts/#{post_id}/comments", params: comment_params) end |
#create_good_job(post_id, params = {}) ⇒ Object
160 161 162 |
# File 'lib/docbase/client.rb', line 160 def create_good_job(post_id, params = {}) request(method: :post, path: "/teams/#{team!}/posts/#{post_id}/good_jobs", params: params) end |
#create_group(params) ⇒ Object
60 61 62 |
# File 'lib/docbase/client.rb', line 60 def create_group(params) request(method: :post, path: "/teams/#{team!}/groups", params: params) end |
#create_post(params) ⇒ Object
88 89 90 |
# File 'lib/docbase/client.rb', line 88 def create_post(params) request(method: :post, path: "/teams/#{team!}/posts", params: params) end |
#delete_comment(id) ⇒ Object
142 143 144 |
# File 'lib/docbase/client.rb', line 142 def delete_comment(id) request(method: :delete, path: "/teams/#{team!}/comments/#{id}") end |
#delete_good_job(post_id, good_job_id) ⇒ Object
164 165 166 |
# File 'lib/docbase/client.rb', line 164 def delete_good_job(post_id, good_job_id) request(method: :delete, path: "/teams/#{team!}/posts/#{post_id}/good_jobs/#{good_job_id}") end |
#delete_post(id) ⇒ Object
108 109 110 |
# File 'lib/docbase/client.rb', line 108 def delete_post(id) request(method: :delete, path: "/teams/#{team!}/posts/#{id}") end |
#delete_user(id) ⇒ Object
44 45 46 |
# File 'lib/docbase/client.rb', line 44 def delete_user(id) request(method: :delete, path: "/teams/#{team!}/users/#{id}") end |
#good_jobs(post_id, page: 1, per_page: 100, order: 'asc', created_after: nil, created_before: nil) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/docbase/client.rb', line 146 def good_jobs(post_id, page: 1, per_page: 100, order: 'asc', created_after: nil, created_before: nil) request( method: :get, path: "/teams/#{team!}/posts/#{post_id}/good_jobs", params: { page: page, per_page: per_page, order: order, created_after: created_after, created_before: created_before, } ) end |
#group(id) ⇒ Object
56 57 58 |
# File 'lib/docbase/client.rb', line 56 def group(id) request(method: :get, path: "/teams/#{team!}/groups/#{id}") end |
#groups(name: nil, page: 1, per_page: 100) ⇒ Object
52 53 54 |
# File 'lib/docbase/client.rb', line 52 def groups(name: nil, page: 1, per_page: 100) request(method: :get, path: "/teams/#{team!}/groups", params: { name: name, page: page, per_page: per_page }) end |
#post(id) ⇒ Object
80 81 82 |
# File 'lib/docbase/client.rb', line 80 def post(id) request(method: :get, path: "/teams/#{team!}/posts/#{id}") end |
#posts(q: '*', page: 1, per_page: 20) ⇒ Object
84 85 86 |
# File 'lib/docbase/client.rb', line 84 def posts(q: '*', page: 1, per_page: 20) request(method: :get, path: "/teams/#{team!}/posts", params: { q: q, page: page, per_page: per_page }) end |
#profile ⇒ Object
24 25 26 |
# File 'lib/docbase/client.rb', line 24 def profile request(method: :get, path: "/teams/#{team!}/profile") end |
#remove_users_from_group(params) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/docbase/client.rb', line 72 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) request(method: :delete, path: "/teams/#{team!}/groups/#{group_id}/users", params: users_params) end |
#tags ⇒ Object
48 49 50 |
# File 'lib/docbase/client.rb', line 48 def request(method: :get, path: "/teams/#{team!}/tags") end |
#team! ⇒ Object
19 20 21 22 |
# File 'lib/docbase/client.rb', line 19 def team! raise NotSetTeamError unless @team @team end |
#unarchive_post(id) ⇒ Object
116 117 118 |
# File 'lib/docbase/client.rb', line 116 def unarchive_post(id) request(method: :put, path: "/teams/#{team!}/posts/#{id}/unarchive") end |
#update_post(params) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/docbase/client.rb', line 92 def update_post(params) post_id = params[:id].to_i raise NotSetPostIdError if post_id <= 0 post_params = except(params, :id) request(method: :patch, path: "/teams/#{team!}/posts/#{post_id}", params: post_params) end |
#update_post_body(params) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/docbase/client.rb', line 100 def update_post_body(params) post_id = params[:id].to_i raise NotSetPostIdError if post_id <= 0 body_params = except(params, :id) request(method: :patch, path: "/teams/#{team!}/posts/#{post_id}/body", params: body_params) end |
#upload(paths) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/docbase/client.rb', line 168 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 request(method: :post, path: "/teams/#{team!}/attachments", params: params) end |
#user_groups(user_id, page: 1, per_page: 20) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/docbase/client.rb', line 36 def user_groups(user_id, page: 1, per_page: 20) request( method: :get, path: "/teams/#{team!}/users/#{user_id}/groups", params: { page: page, per_page: per_page } ) end |
#users(q: nil, page: 1, per_page: 100) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/docbase/client.rb', line 28 def users(q: nil, page: 1, per_page: 100) request( method: :get, path: "/teams/#{team!}/users", params: { q: q, page: page, per_page: per_page } ) end |