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
|
# File 'lib/alucma.rb', line 7
def self.init(hash)
if !hash.class == "Hash"
return { :error => "Invalid input. Input must be a hash." }
end
if hash[:access_token]
return Client.new(hash)
end
if !hash[:client_id] || !hash[:client_secret]
return { :error => "Missing parameters. Must Client ID and Client Secret" }
end
url = "http://api.foundry.att.net:9001/oauth/client_credential/accesstoken?grant_type=client_credentials"
= { "Content-Type" => "application/x-www-form-urlencoded" }
payload = "client_id=#{hash[:client_id]}&client_secret=#{hash[:client_secret]}"
resp = Http.post(url,,payload)
auth = JSON.parse(resp) || {}
if auth["status"] == "approved"
return Client.new(auth)
else
return { :error => "OAuth not approved." }
end
end
|