Module: Esa::ApiMethods

Included in:
Client
Defined in:
lib/esa/api_methods.rb

Defined Under Namespace

Classes: PathStringIO

Constant Summary collapse

HTTP_REGEX =
%r{^https?://}

Instance Method Summary collapse

Instance Method Details

#add_comment_star(comment_id, params = nil, headers = nil) ⇒ Object



89
90
91
# File 'lib/esa/api_methods.rb', line 89

def add_comment_star(comment_id, params = nil, headers = nil)
  send_post("/v1/teams/#{current_team!}/comments/#{comment_id}/star", params, headers)
end

#add_post_star(post_number, params = nil, headers = nil) ⇒ Object



77
78
79
# File 'lib/esa/api_methods.rb', line 77

def add_post_star(post_number, params = nil, headers = nil)
  send_post("/v1/teams/#{current_team!}/posts/#{post_number}/star", params, headers)
end

#add_watch(post_number, params = nil, headers = nil) ⇒ Object



101
102
103
# File 'lib/esa/api_methods.rb', line 101

def add_watch(post_number, params = nil, headers = nil)
  send_post("/v1/teams/#{current_team!}/posts/#{post_number}/watch", params, headers)
end

#comment(comment_id, params = nil, headers = nil) ⇒ Object



49
50
51
# File 'lib/esa/api_methods.rb', line 49

def comment(comment_id, params = nil, headers = nil)
  send_get("/v1/teams/#{current_team!}/comments/#{comment_id}", params, headers)
end

#comment_stargazers(comment_id, params = nil, headers = nil) ⇒ Object



85
86
87
# File 'lib/esa/api_methods.rb', line 85

def comment_stargazers(comment_id, params = nil, headers = nil)
  send_get("/v1/teams/#{current_team!}/comments/#{comment_id}/stargazers", params, headers)
end

#comments(post_number, params = nil, headers = nil) ⇒ Object



45
46
47
# File 'lib/esa/api_methods.rb', line 45

def comments(post_number,  params = nil, headers = nil)
  send_get("/v1/teams/#{current_team!}/posts/#{post_number}/comments", params, headers)
end

#create_comment(post_number, params = nil, headers = nil) ⇒ Object



53
54
55
# File 'lib/esa/api_methods.rb', line 53

def create_comment(post_number, params = nil, headers = nil)
  send_post("/v1/teams/#{current_team!}/posts/#{post_number}/comments", wrap(params, :comment), headers)
end

#create_post(params = nil, headers = nil) ⇒ Object



33
34
35
# File 'lib/esa/api_methods.rb', line 33

def create_post(params = nil, headers = nil)
  send_post("/v1/teams/#{current_team!}/posts", wrap(params, :post), headers)
end

#create_sharing(post_number, params = nil, headers = nil) ⇒ Object



65
66
67
# File 'lib/esa/api_methods.rb', line 65

def create_sharing(post_number, params = nil, headers = nil)
  send_post("/v1/teams/#{current_team!}/posts/#{post_number}/sharing", params, headers)
end

#delete_comment(comment_id, params = nil, headers = nil) ⇒ Object



61
62
63
# File 'lib/esa/api_methods.rb', line 61

def delete_comment(comment_id, params = nil, headers = nil)
  send_delete("/v1/teams/#{current_team!}/comments/#{comment_id}", params, headers)
end

#delete_comment_star(comment_id, params = nil, headers = nil) ⇒ Object



93
94
95
# File 'lib/esa/api_methods.rb', line 93

def delete_comment_star(comment_id, params = nil, headers = nil)
  send_delete("/v1/teams/#{current_team!}/comments/#{comment_id}/star", params, headers)
end

#delete_post(post_number, params = nil, headers = nil) ⇒ Object



41
42
43
# File 'lib/esa/api_methods.rb', line 41

def delete_post(post_number, params = nil, headers = nil)
  send_delete("/v1/teams/#{current_team!}/posts/#{post_number}", params, headers)
end

#delete_post_star(post_number, params = nil, headers = nil) ⇒ Object



81
82
83
# File 'lib/esa/api_methods.rb', line 81

def delete_post_star(post_number, params = nil, headers = nil)
  send_delete("/v1/teams/#{current_team!}/posts/#{post_number}/star", params, headers)
end

#delete_sharing(post_number, params = nil, headers = nil) ⇒ Object



69
70
71
# File 'lib/esa/api_methods.rb', line 69

def delete_sharing(post_number, params = nil, headers = nil)
  send_delete("/v1/teams/#{current_team!}/posts/#{post_number}/sharing", params, headers)
end

#delete_watch(post_number, params = nil, headers = nil) ⇒ Object



105
106
107
# File 'lib/esa/api_methods.rb', line 105

def delete_watch(post_number, params = nil, headers = nil)
  send_delete("/v1/teams/#{current_team!}/posts/#{post_number}/watch", params, headers)
end

#members(params = nil, headers = nil) ⇒ Object



21
22
23
# File 'lib/esa/api_methods.rb', line 21

def members(params = nil, headers = nil)
  send_get("/v1/teams/#{current_team!}/members", params, headers)
end

#post(post_number, params = nil, headers = nil) ⇒ Object



29
30
31
# File 'lib/esa/api_methods.rb', line 29

def post(post_number, params = nil, headers = nil)
  send_get("/v1/teams/#{current_team!}/posts/#{post_number}", params, headers)
end

#post_stargazers(post_number, params = nil, headers = nil) ⇒ Object



73
74
75
# File 'lib/esa/api_methods.rb', line 73

def post_stargazers(post_number, params = nil, headers = nil)
  send_get("/v1/teams/#{current_team!}/posts/#{post_number}/stargazers", params, headers)
end

#posts(params = nil, headers = nil) ⇒ Object



25
26
27
# File 'lib/esa/api_methods.rb', line 25

def posts(params = nil, headers = nil)
  send_get("/v1/teams/#{current_team!}/posts", params, headers)
end

#stats(params = nil, headers = nil) ⇒ Object



17
18
19
# File 'lib/esa/api_methods.rb', line 17

def stats(params = nil, headers = nil)
  send_get("/v1/teams/#{current_team!}/stats", params, headers)
end

#team(team_name, params = nil, headers = nil) ⇒ Object



13
14
15
# File 'lib/esa/api_methods.rb', line 13

def team(team_name, params = nil, headers = nil)
  send_get("/v1/teams/#{team_name}", params, headers)
end

#teams(params = nil, headers = nil) ⇒ Object



9
10
11
# File 'lib/esa/api_methods.rb', line 9

def teams(params = nil, headers = nil)
  send_get("/v1/teams", params, headers)
end

#update_comment(comment_id, params = nil, headers = nil) ⇒ Object



57
58
59
# File 'lib/esa/api_methods.rb', line 57

def update_comment(comment_id, params = nil, headers = nil)
  send_patch("/v1/teams/#{current_team!}/comments/#{comment_id}", wrap(params, :comment), headers)
end

#update_post(post_number, params = nil, headers = nil) ⇒ Object



37
38
39
# File 'lib/esa/api_methods.rb', line 37

def update_post(post_number, params = nil, headers = nil)
  send_patch("/v1/teams/#{current_team!}/posts/#{post_number}", wrap(params, :post), headers)
end

#upload_attachment(path_or_file_or_url, params = {}, headers = nil) ⇒ Object

beta



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/esa/api_methods.rb', line 119

def upload_attachment(path_or_file_or_url, params = {}, headers = nil)
  file = file_from(path_or_file_or_url)
  setup_params_for_upload(params, file)

  response = send_post("/v1/teams/#{current_team!}/attachments/policies", params, headers)
  return response unless response.status == 200

  attachment = response.body['attachment']
  form_data  = response.body['form'].merge(file: Faraday::UploadIO.new(file, params[:type]))

  s3_response = send_s3_request(:post, attachment['endpoint'], form_data)
  return s3_response unless s3_response.status == 204

  response.body.delete('form')
  response
end

#user(params = nil, headers = nil) ⇒ Object



5
6
7
# File 'lib/esa/api_methods.rb', line 5

def user(params = nil, headers = nil)
  send_get("/v1/user", params, headers)
end

#watchers(post_number, params = nil, headers = nil) ⇒ Object



97
98
99
# File 'lib/esa/api_methods.rb', line 97

def watchers(post_number, params = nil, headers = nil)
  send_get("/v1/teams/#{current_team!}/posts/#{post_number}/watchers", params, headers)
end