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
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, #update_task_list
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, #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.
23 24 25 26 27 28 29 30 |
# File 'lib/teamwork_api/client.rb', line 23 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.
14 15 16 |
# File 'lib/teamwork_api/client.rb', line 14 def api_key @api_key end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
15 16 17 |
# File 'lib/teamwork_api/client.rb', line 15 def host @host end |
Instance Method Details
#connection_options ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/teamwork_api/client.rb', line 32 def @connection_options ||= { url: @host, headers: { accept: 'application/json', user_agent: user_agent } } end |
#delete(path, params = {}) ⇒ Object
42 43 44 |
# File 'lib/teamwork_api/client.rb', line 42 def delete(path, params = {}) request(:delete, path, params) end |
#get(path, params = {}) ⇒ Object
46 47 48 |
# File 'lib/teamwork_api/client.rb', line 46 def get(path, params = {}) request(:get, path, params) end |
#patch(path, params = {}) ⇒ Object
64 65 66 |
# File 'lib/teamwork_api/client.rb', line 64 def patch(path, params = {}) request(:patch, path, params) end |
#post(path, params = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/teamwork_api/client.rb', line 50 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
60 61 62 |
# File 'lib/teamwork_api/client.rb', line 60 def put(path, params = {}) request(:put, path, params) end |
#user_agent ⇒ Object
68 69 70 |
# File 'lib/teamwork_api/client.rb', line 68 def user_agent @user_agent ||= "TeamworkApi Ruby Gem #{TeamworkApi::VERSION}" end |