teambition2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07f17d5d9c0ad7f8b7b11e489045443c61ecaeba
4
+ data.tar.gz: fa48f5a24f27c1a2348dec41fc32c6f99ebc6c83
5
+ SHA512:
6
+ metadata.gz: 0bf5b8967ee0c43a0bb3a69a90583fa2999dbabad665bec691e345bdf2d2ac2ffa4287f5e411cb1dd89e96404c3d4c55e75f3bb68c0734188aad5abee3676c02
7
+ data.tar.gz: a37d1f9665f75943ed48e4514433ea539a7218e5aabb05970767b5afce707e611fcb35a903950c4e3b136913b1535d73488879fcbd05d35479da5c7f94b68928
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -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 icyleaf.cn@gmail.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 teambition2.gemspec
6
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ teambition2 (0.1.0)
5
+ http (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ diff-lcs (1.3)
13
+ domain_name (0.5.20170404)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ http (3.0.0)
16
+ addressable (~> 2.3)
17
+ http-cookie (~> 1.0)
18
+ http-form_data (>= 2.0.0.pre.pre2, < 3)
19
+ http_parser.rb (~> 0.6.0)
20
+ http-cookie (1.0.3)
21
+ domain_name (~> 0.5)
22
+ http-form_data (2.0.0)
23
+ http_parser.rb (0.6.0)
24
+ public_suffix (3.0.1)
25
+ rake (10.5.0)
26
+ rspec (3.7.0)
27
+ rspec-core (~> 3.7.0)
28
+ rspec-expectations (~> 3.7.0)
29
+ rspec-mocks (~> 3.7.0)
30
+ rspec-core (3.7.0)
31
+ rspec-support (~> 3.7.0)
32
+ rspec-expectations (3.7.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-mocks (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-support (3.7.0)
39
+ unf (0.1.4)
40
+ unf_ext
41
+ unf_ext (0.0.7.4)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 1.16)
48
+ rake (~> 10.0)
49
+ rspec (~> 3.0)
50
+ teambition2!
51
+
52
+ BUNDLED WITH
53
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 icyleaf
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.
@@ -0,0 +1,58 @@
1
+ # Teambition2
2
+
3
+ 非官方 Teambition API SDK Ruby 版本。除了通用的请求以外,还简单封装了部分任务接口。
4
+
5
+ ## 安装
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'teambition2'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install teambition2
20
+
21
+ ## 用法
22
+
23
+ ```ruby
24
+ require 'teambition2'
25
+
26
+ # 初始化
27
+ client = Teambition2::Client.new "client_key", "client_secret", "callback_uri"
28
+
29
+ # 获取认证链接
30
+ client.authorize_url
31
+
32
+ # 获取令牌
33
+ client.access_token "code"
34
+
35
+ # 检查令牌是否有效
36
+ client.valid_token?
37
+
38
+ # 获取项目列表
39
+ client.projects
40
+
41
+ # 获取项目的任务分组列表
42
+ client.task_group "project_id"
43
+
44
+ # 在指定任务分组创建一个任务
45
+ client.create_task "group_id", "subject"
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/teambition2. 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.
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
55
+
56
+ ## Code of Conduct
57
+
58
+ Everyone interacting in the Teambition2 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/teambition2/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
5
+ require 'teambition2'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ require "teambition2/client"
2
+ require "teambition2/error"
3
+ require "teambition2/version"
4
+
5
+ module Teambition2
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,35 @@
1
+ module Teambition2
2
+ module API
3
+ module Project
4
+ def projects
5
+ get('/api/projects')
6
+ end
7
+
8
+ def project(project_id)
9
+ get("/api/projects/#{project_id}")
10
+ end
11
+
12
+ def project_task_groups(project_id)
13
+ get("/api/projects/#{project_id}/tasklists")
14
+ end
15
+
16
+ def project_tags(project_id)
17
+ get("/api/projects/#{project_id}/tags")
18
+ end
19
+
20
+ def project_search(name, key: 'name', limit: 1)
21
+ result = projects.select { |p| p[key].include?(name) }
22
+ return nil if result.empty?
23
+
24
+ case limit
25
+ when 0
26
+ result
27
+ when 1
28
+ result[0]
29
+ else
30
+ result.size >= limit ? result[0..limit] : result
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ module Teambition2
2
+ module API
3
+ module StageTemplate
4
+ def stage_templates
5
+ get('/api/stagetemplates')
6
+ end
7
+
8
+ def stage_template(title, key: 'title', limit: 1)
9
+ result = stage_templates.select { |p| p[key].include?(title) }
10
+ return nil if result.empty?
11
+
12
+ case limit
13
+ when 0
14
+ result
15
+ when 1
16
+ result[0]
17
+ else
18
+ result.size >= limit ? result[0..limit] : result
19
+ end
20
+ end
21
+
22
+ def create_stage_template(title, stages)
23
+ post('/api/stagetemplates', { title: title, stages: stages } )
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ module Teambition2
2
+ module API
3
+ module Tag
4
+ def tags(type, id)
5
+ get("/api/#{type}/#{id}/tags")
6
+ end
7
+
8
+ def tag(tag_id)
9
+ get("/api/tags/#{tag_id}")
10
+ end
11
+
12
+ def create_tag(project_id, tag)
13
+ post('/api/tags', {
14
+ 'name' => tag,
15
+ '_projectId' => project_id
16
+ })
17
+ end
18
+
19
+ def tag_search(type, id, name, limit: 1)
20
+ result = tags(type, id).select { |p| p['name'].include?(name) }
21
+ return nil if result.empty?
22
+
23
+ case limit
24
+ when 0
25
+ result
26
+ when 1
27
+ result[0]
28
+ else
29
+ result.size >= limit ? result[0..limit] : result
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ module Teambition2
2
+ module API
3
+ module Task
4
+ def create_task(group_id, content, tag_id: [])
5
+ post('/api/tasks', {
6
+ '_tasklistId' => group_id,
7
+ 'content' => content,
8
+ 'tagIds' => tag_id,
9
+ })
10
+ end
11
+
12
+ def project_tasks(project_id)
13
+ get("/api/projects/#{project_id}")
14
+ end
15
+
16
+ def stage_tasks(stage_id)
17
+ get("/api/stages/#{stage_id}/tasks")
18
+ end
19
+
20
+ def edit_task_tags(task_id, tags: [])
21
+ put("/api/tasks/#{task_id}/tagIds", 'tagIds[]' => tags)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ module Teambition2
2
+ module API
3
+ module TaskGroup
4
+ def task_group(group_id)
5
+ get("/api/tasklists/#{project_id}")
6
+ end
7
+
8
+ def create_task_group(project_id, title, template_id: nil, description: nil)
9
+ post('/api/tasklists', {
10
+ 'title' => title,
11
+ '_projectId' => project_id,
12
+ '_templateId' => template_id
13
+ })
14
+ end
15
+
16
+ def task_group_search(project_id, name, key: 'title', limit: 1)
17
+ result = get("/api/projects/#{project_id}/tasklists").select { |p| p[key].include?(name) }
18
+ return nil if result.empty?
19
+
20
+ case limit
21
+ when 0
22
+ result
23
+ when 1
24
+ result[0]
25
+ else
26
+ result.size >= limit ? result[0..limit] : result
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,96 @@
1
+ require 'teambition2/api/project'
2
+ require 'teambition2/api/task_group'
3
+ require 'teambition2/api/task'
4
+ require 'teambition2/api/stage_template'
5
+ require 'teambition2/api/tag'
6
+ require 'http'
7
+ require 'uri'
8
+
9
+ module Teambition2
10
+ # Teambiton Client
11
+ class Client
12
+ OAUTH2_ENDPOINT = 'https://account.teambition.com'.freeze
13
+ API_ENDPOINT = 'https://api.teambition.com'.freeze
14
+
15
+ attr_accessor :key, :secret, :callback_url, :token
16
+
17
+ def initialize(key, secret, callback_url)
18
+ @key = key
19
+ @secret = secret
20
+ @callback_url = callback_url
21
+ end
22
+
23
+ def authorize_url(state = nil, response_type = 'code')
24
+ uri = URI.join(OAUTH2_ENDPOINT, '/oauth2/authorize'.freeze)
25
+ params = {
26
+ client_id: @key,
27
+ redirect_uri: @callback_url,
28
+ response_type: response_type,
29
+ state: state
30
+ }
31
+
32
+ uri.query = URI.encode_www_form(params)
33
+ uri.to_s
34
+ end
35
+
36
+ def access_token(code)
37
+ r = HTTP.post URI.join(OAUTH2_ENDPOINT, '/oauth2/access_token'), form: {
38
+ client_id: @key,
39
+ client_secret: @secret,
40
+ code: code
41
+ }
42
+
43
+ @token = r.parse(:json)['access_token']
44
+ end
45
+
46
+ def valid_token?
47
+ uri = URI.join(OAUTH2_ENDPOINT, "/api/applications/#{@client_key}/tokens/check")
48
+ r = request.get uri, params: params
49
+
50
+ case r.code
51
+ when 200
52
+ true
53
+ when 400
54
+ raise Teambition2::ParamError
55
+ when 403
56
+ raise Teambition2::NoPermissionError
57
+ end
58
+
59
+ false
60
+ end
61
+
62
+ def get(path, params = {})
63
+ uri = URI.join(API_ENDPOINT, path)
64
+ r = request.get uri, params: params
65
+ r.parse(:json)
66
+ end
67
+
68
+ def post(path, form = {})
69
+ uri = URI.join(API_ENDPOINT, path)
70
+ r = request.post uri, form: form
71
+ r.parse(:json)
72
+ end
73
+
74
+ def put(path, form = {})
75
+ uri = URI.join(API_ENDPOINT, path)
76
+ r = request.put uri, form: form
77
+ r.parse(:json)
78
+ end
79
+
80
+ def delete(path, form = {})
81
+ uri = URI.join(API_ENDPOINT, path)
82
+ r = request.delete uri, form: form
83
+ r.parse(:json)
84
+ end
85
+
86
+ private def request
87
+ HTTP.headers(authorization: "OAuth2 #{@token}")
88
+ end
89
+
90
+ include API::Project
91
+ include API::TaskGroup
92
+ include API::Task
93
+ include API::StageTemplate
94
+ include API::Tag
95
+ end
96
+ end
@@ -0,0 +1,7 @@
1
+ module Teambition2
2
+ class Error < StandardError; end
3
+
4
+ class ParamError < Error; end
5
+
6
+ class NoPermissionError < Error; end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Teambition2
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "teambition2/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "teambition2"
8
+ spec.version = Teambition2::VERSION
9
+ spec.authors = ["icyleaf"]
10
+ spec.email = ["icyleaf.cn@gmail.com"]
11
+
12
+ spec.summary = %q{Teambiton API for Ruby}
13
+ spec.description = %q{Teambiton API for Ruby}
14
+ spec.homepage = "https://github.com/icyleaf/teambiton2"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.required_ruby_version = ">= 2.0.0"
24
+
25
+ spec.add_dependency "http", "~> 3.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teambition2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - icyleaf
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Teambiton API for Ruby
70
+ email:
71
+ - icyleaf.cn@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/teambition2.rb
85
+ - lib/teambition2/api/project.rb
86
+ - lib/teambition2/api/stage_template.rb
87
+ - lib/teambition2/api/tag.rb
88
+ - lib/teambition2/api/task.rb
89
+ - lib/teambition2/api/task_group.rb
90
+ - lib/teambition2/client.rb
91
+ - lib/teambition2/error.rb
92
+ - lib/teambition2/version.rb
93
+ - teambition2.gemspec
94
+ homepage: https://github.com/icyleaf/teambiton2
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.0.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.6.12
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Teambiton API for Ruby
118
+ test_files: []