Class: TeamworkApi::Client
- Inherits:
-
Object
- Object
- TeamworkApi::Client
- Includes:
- API::Companies, API::People, API::ProjectOwner, API::Projects, API::TaskLists
- Defined in:
- lib/teamwork_api/client.rb
Overview
The main Teamwork client object
Constant Summary
Constants included from API::Projects
API::Projects::OPTIONAL_CREATE_ATTRIBUTES, API::Projects::OPTIONAL_GET_ATTRIBUTES, API::Projects::OPTIONAL_UPDATE_ATTRIBUTES
Constants included from API::People
API::People::OPTIONAL_GET_ATTRIBUTES, API::People::OPTIONAL_UPDATE_ATTRIBUTES
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
- #connection_options ⇒ Object
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(host, api_key = nil) ⇒ Client
constructor
A new instance of Client.
- #patch(path, params = {}) ⇒ Object
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
- #user_agent ⇒ Object
Methods included from API::TaskLists
#create_task_list, #delete_task_list, #task_list, #task_lists
Methods included from API::ProjectOwner
#project_owner, #set_project_owner
Methods included from API::Projects
#create_project, #delete_project, #project, #projects, #update_project
Methods included from API::People
#add_person_to_project, #people, #person, #set_permissions
Methods included from API::Companies
#companies, #company, #company_by_name
Constructor Details
#initialize(host, api_key = nil) ⇒ Client
Returns a new instance of Client.
26 27 28 29 30 31 32 33 |
# File 'lib/teamwork_api/client.rb', line 26 def initialize(host, api_key = nil) raise ArgumentError, 'host needs to be defined' if host.nil? || host.empty? @host = host @api_key = api_key @use_relative = check_subdirectory(host) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
17 18 19 |
# File 'lib/teamwork_api/client.rb', line 17 def api_key @api_key end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
18 19 20 |
# File 'lib/teamwork_api/client.rb', line 18 def host @host end |
Instance Method Details
#connection_options ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/teamwork_api/client.rb', line 35 def @connection_options ||= { url: @host, headers: { accept: 'application/json', user_agent: user_agent } } end |
#delete(path, params = {}) ⇒ Object
45 46 47 |
# File 'lib/teamwork_api/client.rb', line 45 def delete(path, params = {}) request(:delete, path, params) end |
#get(path, params = {}) ⇒ Object
49 50 51 |
# File 'lib/teamwork_api/client.rb', line 49 def get(path, params = {}) request(:get, path, params) end |
#patch(path, params = {}) ⇒ Object
67 68 69 |
# File 'lib/teamwork_api/client.rb', line 67 def patch(path, params = {}) request(:patch, path, params) end |
#post(path, params = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/teamwork_api/client.rb', line 53 def post(path, params = {}) response = request(:post, path, params) case response.status when 200, 201, 204 response.body else raise TeamworkApi::Error, response.body end end |
#put(path, params = {}) ⇒ Object
63 64 65 |
# File 'lib/teamwork_api/client.rb', line 63 def put(path, params = {}) request(:put, path, params) end |
#user_agent ⇒ Object
71 72 73 |
# File 'lib/teamwork_api/client.rb', line 71 def user_agent @user_agent ||= "TeamworkApi Ruby Gem #{TeamworkApi::VERSION}" end |