module Spearly module Auth class Client def initialize(token) @token = token end def create_team(params) uri = "#{ENV['SPEARLY_API_URL']}/teams" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.post(uri_parsed, params.as_json, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 201 JSON.parse(res.body)['data'] else {} end end def get_team(team_id) uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.get(uri_parsed, nil, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 200 JSON.parse(res.body)['data'] else {} end end def get_teams(params = {}) uri = "#{ENV['SPEARLY_API_URL']}/teams" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.get(uri_parsed, params.as_json, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 200 JSON.parse(res.body)['data'] else [] end end def update_team(team_id, params) uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.put(uri_parsed, params.as_json, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 200 JSON.parse(res.body)['data'] else nil end end def regenerate_team_api_access_token(team_id) uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}/regenerate_api_access_token" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.post(uri_parsed, nil, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 200 JSON.parse(res.body)['data'] else nil end end def invite_user_to_team(team_id, params) uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}/invite" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.post(uri_parsed, params.as_json, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 201 JSON.parse(res.body)['data'] else nil end end def get_team_members(team_id) uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}/members" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.get(uri_parsed, nil, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 200 JSON.parse(res.body)['data'] else [] end end def get_team_features(team_id) uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}/features" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.get(uri_parsed, nil, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 200 JSON.parse(res.body)['data'] else {} end end end end end