class Teamwork::Client

Public Class Methods

authenticated?() click to toggle source
# File lib/teamwork/client.rb, line 26
def self.authenticated?
  !Teamwork.subdomain.nil? || !Teamwork.api_key.nil?
end

Public Instance Methods

api_endpoint() click to toggle source
# File lib/teamwork/client.rb, line 22
def api_endpoint
  @api_endpoint ||= "http://#{Teamwork.subdomain}.teamworkpm.net/"
end
resources() click to toggle source
# File lib/teamwork/client.rb, line 30
def resources
  %w{links milestones files notebooks tasks}
end

Private Instance Methods

connection(endpoint = api_endpoint) click to toggle source
# File lib/teamwork/client.rb, line 70
def connection(endpoint = api_endpoint)
  Faraday.new endpoint do |c|
    c.request :multipart
    c.request :json
    c.request :url_encoded
    c.response :json, content_type: /\bjson$/
    c.adapter :net_http
    c.headers[:cache_control] = 'no-cache'
    c.basic_auth(Teamwork.api_key, '')
  end
end
delete_path(path, params = nil) click to toggle source
# File lib/teamwork/client.rb, line 62
def delete_path(path, params = nil)
  request(:delete, path, params)
end
get(path, params = nil) click to toggle source
# File lib/teamwork/client.rb, line 50
def get(path, params = nil)
  request(:get, path, params)
end
object_from_response(method, path, key, params = nil, format = ".json") click to toggle source
# File lib/teamwork/client.rb, line 42
def object_from_response(method, path, key, params = nil, format = ".json")
  Teamwork::Thing.new(response(method, path, key, params, format)[key])
end
objects_from_response(method, path, key, params = nil, format = ".json") click to toggle source
# File lib/teamwork/client.rb, line 36
def objects_from_response(method, path, key, params = nil, format = ".json")
  res = response(method, path, key, params, format)[key]
  return [] if res.nil?
  res.map { |item| Teamwork::Thing.new(item) }
end
post(path, params = nil) click to toggle source
# File lib/teamwork/client.rb, line 54
def post(path, params = nil)
  request(:post, path, params)
end
put(path, params = nil) click to toggle source
# File lib/teamwork/client.rb, line 58
def put(path, params = nil)
  request(:put, path, params)
end
request(method, path, parameters = {}) click to toggle source
# File lib/teamwork/client.rb, line 66
def request(method, path, parameters = {})
  connection.send(method.to_sym, path, parameters).env
end
response(method, path, key, params, format) click to toggle source
# File lib/teamwork/client.rb, line 46
def response(method, path, key, params, format)
  send(method.to_sym, "#{path}#{format}", params).body
end