class Teambition2::Client
Teambiton Client
Constants
- API_ENDPOINT
- OAUTH2_ENDPOINT
Attributes
callback_url[RW]
key[RW]
secret[RW]
token[RW]
Public Class Methods
new(key, secret, callback_url)
click to toggle source
# File lib/teambition2/client.rb, line 17 def initialize(key, secret, callback_url) @key = key @secret = secret @callback_url = callback_url end
Public Instance Methods
access_token(code)
click to toggle source
# File lib/teambition2/client.rb, line 36 def access_token(code) r = HTTP.post URI.join(OAUTH2_ENDPOINT, '/oauth2/access_token'), form: { client_id: @key, client_secret: @secret, code: code } @token = r.parse(:json)['access_token'] end
delete(path, form = {})
click to toggle source
# File lib/teambition2/client.rb, line 80 def delete(path, form = {}) uri = URI.join(API_ENDPOINT, path) r = request.delete uri, form: form r.parse(:json) end
get(path, params = {})
click to toggle source
# File lib/teambition2/client.rb, line 62 def get(path, params = {}) uri = URI.join(API_ENDPOINT, path) r = request.get uri, params: params r.parse(:json) end
post(path, form = {})
click to toggle source
# File lib/teambition2/client.rb, line 68 def post(path, form = {}) uri = URI.join(API_ENDPOINT, path) r = request.post uri, form: form r.parse(:json) end
put(path, form = {})
click to toggle source
# File lib/teambition2/client.rb, line 74 def put(path, form = {}) uri = URI.join(API_ENDPOINT, path) r = request.put uri, form: form r.parse(:json) end
valid_token?()
click to toggle source
# File lib/teambition2/client.rb, line 46 def valid_token? uri = URI.join(OAUTH2_ENDPOINT, "/api/applications/#{@client_key}/tokens/check") r = request.get uri, params: params case r.code when 200 true when 400 raise Teambition2::ParamError when 403 raise Teambition2::NoPermissionError end false end
Private Instance Methods
request()
click to toggle source
# File lib/teambition2/client.rb, line 86 def request HTTP.headers(authorization: "OAuth2 #{@token}") end