teamwork_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0597cc1425bbb361d139fa9ac0577254f9d32deaf6b1a4cf992aa19072fc5862'
4
+ data.tar.gz: cbf693e0a516dc312bdb2d0ba288d574c7ad092d39ed0b2a7742b6b29fa2e3aa
5
+ SHA512:
6
+ metadata.gz: 5ffe58e4e966e152eb1acd524875c9271c45182e91562390fdf5618418450367c4138d6a6abef1e38c703df712a842e8c24273c6645758e16595173c1b4fa57a
7
+ data.tar.gz: b7c0842c00c364b9fb19078611b39e3f61a0f131dba16faa39157fea9c7c1924f86f3050920955c5344da9f7251fbef183b8a494402edc12900f6ff5cc0bb84d
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ .bundle
2
+ .yardoc
3
+ _yardoc
4
+ bin/
5
+ coverage
6
+ doc/
7
+ pkg
8
+ tmp
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # rbenv
14
+ .rbenv-gemsets
15
+ .ruby-version
16
+
17
+ .env
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ Exclude:
4
+ - 'spec/**/**/*.rb'
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: 'ruby'
2
+
3
+ before_install:
4
+ - 'gem update --system'
5
+ - 'gem install bundler'
6
+
7
+ rvm:
8
+ - '2.5.5'
9
+ - '2.6.2'
10
+
11
+ script: 'bundle exec rake'
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nick@codevader.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in teamwork_api.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ teamwork_api (0.1.0)
5
+ faraday (~> 0.9)
6
+ faraday_middleware (~> 0.10)
7
+ rack (>= 1.6)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.0)
13
+ diff-lcs (1.3)
14
+ docile (1.3.1)
15
+ faraday (0.15.4)
16
+ multipart-post (>= 1.2, < 3)
17
+ faraday_middleware (0.13.1)
18
+ faraday (>= 0.7.4, < 1.0)
19
+ jaro_winkler (1.5.2)
20
+ json (2.2.0)
21
+ multipart-post (2.1.0)
22
+ parallel (1.17.0)
23
+ parser (2.6.3.0)
24
+ ast (~> 2.4.0)
25
+ psych (3.1.0)
26
+ rack (2.0.7)
27
+ rainbow (3.0.0)
28
+ rake (10.5.0)
29
+ rspec (3.8.0)
30
+ rspec-core (~> 3.8.0)
31
+ rspec-expectations (~> 3.8.0)
32
+ rspec-mocks (~> 3.8.0)
33
+ rspec-core (3.8.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-expectations (3.8.3)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-mocks (3.8.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.8.0)
41
+ rspec-support (3.8.0)
42
+ rubocop (0.67.2)
43
+ jaro_winkler (~> 1.5.1)
44
+ parallel (~> 1.10)
45
+ parser (>= 2.5, != 2.5.1.1)
46
+ psych (>= 3.1.0)
47
+ rainbow (>= 2.2.2, < 4.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 1.4.0, < 1.6)
50
+ ruby-progressbar (1.10.0)
51
+ simplecov (0.16.1)
52
+ docile (~> 1.1)
53
+ json (>= 1.8, < 3)
54
+ simplecov-html (~> 0.10.0)
55
+ simplecov-html (0.10.2)
56
+ unicode-display_width (1.5.0)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 1.16)
63
+ rake (~> 10.0)
64
+ rspec (~> 3.4)
65
+ rubocop (~> 0.67.2)
66
+ simplecov (~> 0.11)
67
+ teamwork_api!
68
+
69
+ BUNDLED WITH
70
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Nick Coyne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # TeamworkApi
2
+
3
+ [![Code Climate](https://codeclimate.com/github/100yrs/teamwork_api.png)][codeclimate]
4
+
5
+ [codeclimate]: https://codeclimate.com/github/100yrs/teamwork_api
6
+
7
+ The Teamwork API gem allows you to consume the Teamwork API
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'teamwork_api'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install teamwork_api
24
+
25
+ ## Usage
26
+
27
+ Over time this project intends to have a full Teamwork API. At the moment there are only a
28
+ few endpoints available:
29
+
30
+ ```ruby
31
+ client = TeamworkApi::Client.new('https://yoursite.teamwork.com')
32
+ client.api_key = 'YOUR_API_KEY'
33
+
34
+ # Project endpoints
35
+ client.projects #=> Gets all projects
36
+ client.project(57) #=> Gets the project with id 57
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/teamwork_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
58
+
59
+ ## Code of Conduct
60
+
61
+ Everyone interacting in the TeamworkApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/100yrs/teamwork_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require 'rubocop/rake_task'
7
+ RuboCop::RakeTask.new(:rubocop)
8
+
9
+ task test: :spec
10
+ task lint: :rubocop
11
+ task default: [:spec, :lint]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "teamwork_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ module TeamworkApi
2
+ module API
3
+ module Companies
4
+ def company(company_id)
5
+ response = get "/companies/#{company_id}.json"
6
+ response.body['company']
7
+ end
8
+
9
+ def companies
10
+ response = get '/companies.json'
11
+ response.body['companies']
12
+ end
13
+
14
+ def company_by_name(company_name)
15
+ companies.select { |c| c['name'] == company_name }.first
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,69 @@
1
+ module TeamworkApi
2
+ module API
3
+ def self.params(args)
4
+ Params.new(args)
5
+ end
6
+
7
+ class Params
8
+ def initialize(args)
9
+ raise ArgumentError.new('Required to be initialized with a Hash') unless
10
+ args.is_a? Hash
11
+ @args = args
12
+ @required = []
13
+ @optional = []
14
+ @defaults = {}
15
+ end
16
+
17
+ def required(*keys)
18
+ @required.concat(keys)
19
+ self
20
+ end
21
+
22
+ def optional(*keys)
23
+ @optional.concat(keys)
24
+ self
25
+ end
26
+
27
+ def default(args)
28
+ args.each do |k, v|
29
+ @defaults[k] = v
30
+ end
31
+ self
32
+ end
33
+
34
+ def to_h
35
+ h = {}
36
+
37
+ @required.each do |k|
38
+ h[k] = @args[k]
39
+ raise ArgumentError.new("#{k} is required but not specified") unless
40
+ h[k]
41
+ end
42
+
43
+ @optional.each do |k|
44
+ h[k] = @args[k] if @args.include?(k)
45
+ end
46
+
47
+ @defaults.each do |k, v|
48
+ @args.key?(k) ? h[k] = @args[k] : h[k] = v
49
+ end
50
+
51
+ caseify_keys(h)
52
+ end
53
+
54
+ def caseify_keys(h)
55
+ caseified_hash = {}
56
+ h.each do |k, v|
57
+ if k =~ /-/
58
+ key = k.to_s
59
+ else
60
+ key = k.to_s.camelize(:lower)
61
+ end
62
+ caseified_hash[key] = v
63
+ end
64
+
65
+ caseified_hash
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,47 @@
1
+ module TeamworkApi
2
+ module API
3
+ module People
4
+ def add_person_to_project(project_id, person_id)
5
+ response =
6
+ put "projects/#{project_id}/people.json",
7
+ { add: { userIdList: person_id } }
8
+ response.body['STATUS']
9
+ end
10
+
11
+ def set_permissions(project_id, person_id, args)
12
+ args =
13
+ API.params(args)
14
+ .optional(
15
+ :'edit-all-tasks',
16
+ :'view-messages-and-files',
17
+ :'view-tasks-and-milestones',
18
+ :'view-time',
19
+ :'view-notebooks',
20
+ :'view-risk-register',
21
+ :'view-invoices',
22
+ :'view-links',
23
+ :'view-links',
24
+ :'add-tasks',
25
+ :'add-milestones',
26
+ :'add-taskLists',
27
+ :'add-messages',
28
+ :'add-files',
29
+ :'add-time',
30
+ :'add-notebooks',
31
+ :'add-links',
32
+ :'set-privacy',
33
+ :'set-privacy',
34
+ :'is-observing',
35
+ :'can-be-assigned-to-tasks-and-milestones',
36
+ :'project-administrator',
37
+ :'add-people-to-project'
38
+ ).to_h
39
+
40
+ response =
41
+ put "projects/#{project_id}/people/#{person_id}.json",
42
+ permissions: args
43
+ response.body
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,22 @@
1
+ module TeamworkApi
2
+ module API
3
+ module ProjectOwner
4
+ def project_owner(project_id)
5
+ response = get "projects/#{project_id}.json",
6
+ project: { include_project_owner: true }
7
+ response[:project][:owner]
8
+ end
9
+
10
+ # This doesn't seem to work. Response is OK, but owner not set
11
+ def set_project_owner(project_id, args)
12
+ args =
13
+ API.params(args)
14
+ .required(:project_owner_id)
15
+ .to_h
16
+
17
+ response = put "projects/#{project_id}.json", project: args
18
+ response.body['STATUS']
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,77 @@
1
+ module TeamworkApi
2
+ module API
3
+ module Projects
4
+ def create_project(args)
5
+ args =
6
+ API.params(args)
7
+ .required(:name)
8
+ .default('category-id': '0')
9
+ .optional(
10
+ :description,
11
+ :start_date,
12
+ :end_date,
13
+ :company_id,
14
+ :new_company,
15
+ :'harvest-timers-enabled',
16
+ :tags,
17
+ :reply_by_email_enabled,
18
+ :privacy_enabled
19
+ ).to_h
20
+
21
+ response = post 'projects.json', project: args
22
+ response['id']
23
+ end
24
+
25
+ def update_project(project_id, args)
26
+ args =
27
+ API.params(args)
28
+ .optional(
29
+ :name,
30
+ :description,
31
+ :start_date,
32
+ :end_date,
33
+ :company_id,
34
+ :new_company,
35
+ :status,
36
+ :'category-id',
37
+ :'harvest-timers-enabled',
38
+ :tags,
39
+ :reply_by_email_enabled,
40
+ :privacy_enabled,
41
+ :'use-tasks',
42
+ :'use-messages',
43
+ :'use-time',
44
+ :'use-risk-register',
45
+ :'use-billing',
46
+ :'use-milestones',
47
+ :'use-files',
48
+ :'use-notebook',
49
+ :'use-links',
50
+ :default_privacy
51
+ ).to_h
52
+
53
+ response = put "projects/#{project_id}.json", project: args
54
+ response['id']
55
+ end
56
+
57
+ def project(project_id, args = {})
58
+ if args.present?
59
+ args = { project: args }
60
+ else
61
+ args = {}
62
+ end
63
+ response = get "/projects/#{project_id}.json", args
64
+ response.body['project']
65
+ end
66
+
67
+ def projects
68
+ response = get '/projects.json'
69
+ response.body['projects']
70
+ end
71
+
72
+ def delete_project(project_id)
73
+ delete "/projects/#{project_id}.json"
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,41 @@
1
+ module TeamworkApi
2
+ module API
3
+ module TaskLists
4
+ def create_task_list(project_id, args)
5
+ args =
6
+ API.params(args)
7
+ .required(:name)
8
+ .optional(
9
+ :private,
10
+ :pinned,
11
+ :'milestone-id',
12
+ :description,
13
+ :'todo-list-template-id',
14
+ :'todo-list-template-start-date',
15
+ :'todo-list-template-keep-off-weekends',
16
+ :'todo-list-template-assignments'
17
+ ).to_h
18
+
19
+ response = post "projects/#{project_id}/tasklists.json", tasklist: args
20
+ response['TASKLISTID']
21
+ end
22
+
23
+ def update_task_list(task_list_id, args)
24
+ end
25
+
26
+ def task_list(task_list_id)
27
+ response = get "/tasklists/#{task_list_id}.json"
28
+ response.body['tasklist']
29
+ end
30
+
31
+ def task_lists
32
+ response = get '/tasklists.json'
33
+ response.body['tasklists']
34
+ end
35
+
36
+ def delete_task_list(task_list_id)
37
+ delete "/tasklists/#{task_list_id}.json"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,136 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'json'
4
+ require 'uri'
5
+ require 'teamwork_api/version'
6
+ require 'teamwork_api/api/companies'
7
+ require 'teamwork_api/api/people'
8
+ require 'teamwork_api/api/projects'
9
+ require 'teamwork_api/api/project_owner'
10
+ require 'teamwork_api/api/task_lists'
11
+
12
+ module TeamworkApi
13
+ class Client
14
+ attr_accessor :api_key
15
+ attr_reader :host
16
+
17
+ include TeamworkApi::API::Companies
18
+ include TeamworkApi::API::People
19
+ include TeamworkApi::API::Projects
20
+ include TeamworkApi::API::ProjectOwner
21
+ include TeamworkApi::API::TaskLists
22
+
23
+ def initialize(host, api_key = nil)
24
+ raise ArgumentError, 'host needs to be defined' if
25
+ host.nil? || host.empty?
26
+
27
+ @host = host
28
+ @api_key = api_key
29
+ @use_relative = check_subdirectory(host)
30
+ end
31
+
32
+ def connection_options
33
+ @connection_options ||= {
34
+ url: @host,
35
+ headers: {
36
+ accept: 'application/json',
37
+ user_agent: user_agent
38
+ }
39
+ }
40
+ end
41
+
42
+ def delete(path, params = {})
43
+ request(:delete, path, params)
44
+ end
45
+
46
+ def get(path, params = {})
47
+ request(:get, path, params)
48
+ end
49
+
50
+ def post(path, params = {})
51
+ response = request(:post, path, params)
52
+ case response.status
53
+ when 200, 201, 204
54
+ response.body
55
+ else
56
+ raise TeamworkApi::Error, response.body
57
+ end
58
+ end
59
+
60
+ def put(path, params = {})
61
+ request(:put, path, params)
62
+ end
63
+
64
+ def patch(path, params = {})
65
+ request(:patch, path, params)
66
+ end
67
+
68
+ def user_agent
69
+ @user_agent ||= "TeamworkApi Ruby Gem #{TeamworkApi::VERSION}"
70
+ end
71
+
72
+ private
73
+
74
+ def connection
75
+ @connection ||= Faraday.new connection_options do |conn|
76
+ # Follow redirects
77
+ conn.use FaradayMiddleware::FollowRedirects, limit: 5
78
+ # Use JSON for request
79
+ conn.request :json
80
+ # Allow uploading of files
81
+ conn.request :multipart
82
+ # Convert request params to "www-form-encoded"
83
+ conn.request :url_encoded
84
+ # Log requests and responses to $stdout
85
+ # conn.response :logger
86
+ # Parse responses as JSON
87
+ conn.use FaradayMiddleware::ParseJson, content_type: 'application/json'
88
+ # Use Faraday's default HTTP adapter
89
+ conn.adapter Faraday.default_adapter
90
+ end
91
+ end
92
+
93
+ def request(method, path, params = {})
94
+ unless Hash === params
95
+ params = params.to_h if params.respond_to? :to_h
96
+ end
97
+ path = @use_relative ? path.sub(/^\//, '') : path
98
+
99
+ connection.headers[:cache_control] = 'no-cache'
100
+ connection.basic_auth(api_key, '')
101
+ response = connection.send(method.to_sym, path, params)
102
+ handle_error(response)
103
+ response.env
104
+ rescue Faraday::Error::ClientError, JSON::ParserError
105
+ raise TeamworkApi::Error
106
+ end
107
+
108
+ def handle_error(response)
109
+ case response.status
110
+ when 403
111
+ raise TeamworkApi::UnauthenticatedError.new(
112
+ response.env[:body],
113
+ response.env
114
+ )
115
+ when 404, 410
116
+ raise TeamworkApi::NotFoundError.new(response.env[:body], response.env)
117
+ when 422
118
+ raise TeamworkApi::UnprocessableEntity.new(
119
+ response.env[:body],
120
+ response.env
121
+ )
122
+ when 429
123
+ raise TeamworkApi::TooManyRequests.new(
124
+ response.env[:body],
125
+ response.env
126
+ )
127
+ when 500...600
128
+ raise TeamworkApi::Error.new(response.env[:body])
129
+ end
130
+ end
131
+
132
+ def check_subdirectory(host)
133
+ URI(host).request_uri != '/'
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,39 @@
1
+ module TeamworkApi
2
+ class TeamworkError < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize(message, response = nil)
6
+ super(message)
7
+ @response = response
8
+ end
9
+ end
10
+
11
+ class Error < TeamworkError
12
+ attr_reader :wrapped_exception
13
+
14
+ # Initializes a new Error object
15
+ #
16
+ # @param exception [Exception, String]
17
+ # @return [TeamworkApi::Error]
18
+ def initialize(exception = $!)
19
+ @wrapped_exception = exception
20
+ if exception.respond_to?(:message)
21
+ super(exception.message)
22
+ else
23
+ super(exception.to_s)
24
+ end
25
+ end
26
+ end
27
+
28
+ class UnauthenticatedError < TeamworkError
29
+ end
30
+
31
+ class NotFoundError < TeamworkError
32
+ end
33
+
34
+ class UnprocessableEntity < TeamworkError
35
+ end
36
+
37
+ class TooManyRequests < TeamworkError
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module TeamworkApi
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'teamwork_api/version'
2
+
3
+ module TeamworkApi
4
+ require 'teamwork_api/api/params'
5
+ require 'teamwork_api/client'
6
+ require 'teamwork_api/error'
7
+ require 'teamwork_api/version'
8
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler/setup'
2
+ require 'teamwork_api'
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = '.rspec_status'
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.describe TeamworkApi do
2
+ it 'has a version number' do
3
+ expect(TeamworkApi::VERSION).not_to be nil
4
+ end
5
+
6
+ it 'does something useful' do
7
+ expect(false).to eq(true)
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'teamwork_api/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'teamwork_api'
7
+ spec.version = TeamworkApi::VERSION
8
+ spec.authors = ['Nick Coyne']
9
+ spec.email = ['nick@100yea.rs']
10
+
11
+ spec.summary = 'Allows access to the Teamwork API'
12
+ spec.description = 'Teamwork API'
13
+ spec.homepage = 'http://github.com/100yrs/teamwork_api'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'faraday', '~> 0.9'
22
+ spec.add_dependency 'faraday_middleware', '~> 0.10'
23
+ spec.add_dependency 'rack', '>= 1.6'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.4'
28
+ spec.add_development_dependency 'rubocop', '~> 0.67.2'
29
+ spec.add_development_dependency 'simplecov', '~> 0.11'
30
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teamwork_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick Coyne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.67.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.67.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.11'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.11'
125
+ description: Teamwork API
126
+ email:
127
+ - nick@100yea.rs
128
+ executables:
129
+ - console
130
+ - setup
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - ".rubocop.yml"
137
+ - ".travis.yml"
138
+ - CODE_OF_CONDUCT.md
139
+ - Gemfile
140
+ - Gemfile.lock
141
+ - LICENSE.txt
142
+ - README.md
143
+ - Rakefile
144
+ - bin/console
145
+ - bin/setup
146
+ - lib/teamwork_api.rb
147
+ - lib/teamwork_api/api/companies.rb
148
+ - lib/teamwork_api/api/params.rb
149
+ - lib/teamwork_api/api/people.rb
150
+ - lib/teamwork_api/api/project_owner.rb
151
+ - lib/teamwork_api/api/projects.rb
152
+ - lib/teamwork_api/api/task_lists.rb
153
+ - lib/teamwork_api/client.rb
154
+ - lib/teamwork_api/error.rb
155
+ - lib/teamwork_api/version.rb
156
+ - spec/spec_helper.rb
157
+ - spec/teamwork_api_spec.rb
158
+ - teamwork_api.gemspec
159
+ homepage: http://github.com/100yrs/teamwork_api
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.7.6.2
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Allows access to the Teamwork API
183
+ test_files:
184
+ - spec/spec_helper.rb
185
+ - spec/teamwork_api_spec.rb