-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyammer_api_wrapper.rb
47 lines (36 loc) · 1.08 KB
/
yammer_api_wrapper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module YammerAPIWrapper
YAMMER_API_BASE_URL = "https://www.yammer.com/api/v1/"
def self.get_networks(access_key)
call :get, "networks/current.json", access_key
end
def self.get_groups(access_key)
call :get, "groups.json", access_key
end
def self.get_oauth_keys(access_key)
call :get, "oauth/tokens.json", access_key
end
def self.post_message(access_key, group_id, message)
call :post, "messages.json", access_key, :body => message, :group_id => group_id
end
protected
def self.parse_result(result)
return false unless result && result.env[:status] == 200
JSON.load(result.body) rescue false
end
def self.http
@faraday ||= Faraday.new
end
def self.call(method, url, access_key, params={})
result = nil
case method.to_s.downcase
when "get"
result = http.get generate_url(url, access_key)
when "post"
result = http.post generate_url(url, access_key), params
end
parse_result(result)
end
def self.generate_url(url, access_key)
"#{YAMMER_API_BASE_URL}#{url}?access_token=#{access_key}"
end
end