teambition_api 0.0.1

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
+ SHA1:
3
+ metadata.gz: c75e73c64a1b845277ad322471d3d3397dc51e19
4
+ data.tar.gz: 3c4cb7ae2cec7415b0f2f6c6df76530453e880fb
5
+ SHA512:
6
+ metadata.gz: 6fa02067ceadce7bd1e167becca40aee6608c60e9d4f25616837ed863508b6c82bd70b02cce311e77e5ecf77a41380b685e4203afa20050ca2ba206fb7c64f4a
7
+ data.tar.gz: bbcd0b0a5f5179607ac5a08de4ffd960fb8f17732d2e35ee3cc3f007dcc9000d8118f93a6153b1ff4a58af31a5fb341cb77a9b87ea7be96c1b6fc3e4c55fa6b7
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in teambition_api.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cmd: "bundle exec rspec" do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 402399938
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # TeambitionApi
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'teambition_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install teambition_api
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/teambition_api/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,29 @@
1
+ require "teambition_api/version"
2
+ require "teambition_api/configuration"
3
+ require "teambition_api/helpers/base"
4
+ require "teambition_api/helpers/organization"
5
+ require "teambition_api/helpers/oauth"
6
+ require "teambition_api/helpers/webhook"
7
+ require "teambition_api/helpers/project"
8
+ require "teambition_api/helpers/post"
9
+ require "teambition_api/helpers/collection"
10
+ require "logger"
11
+
12
+ module TeambitionApi
13
+ Error = Class.new(RuntimeError)
14
+ InvalidResponseError = Class.new(Error)
15
+
16
+ class << self
17
+ def setup
18
+ yield config
19
+ end
20
+
21
+ def config
22
+ @config ||= Configuration.new
23
+ end
24
+
25
+ def logger
26
+ @logger || Logger.new(STDOUT)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ module TeambitionApi
2
+ class Configuration
3
+ def oauth_server
4
+ @oauth_server ||= "https://account.teambition.com"
5
+ end
6
+
7
+ def oauth_server=(oauth_server)
8
+ @oauth_server = oauth_server
9
+ end
10
+
11
+ def server
12
+ @server ||= "https://api.teambition.com"
13
+ end
14
+
15
+ def server=(server)
16
+ @server = server
17
+ end
18
+
19
+ def client_key
20
+ @client_key ||= 'client_key'
21
+ end
22
+
23
+ def client_key=(client_key)
24
+ @client_key = client_key
25
+ end
26
+
27
+ def client_secret
28
+ @client_secret ||= 'client_secret'
29
+ end
30
+
31
+ def client_secret=(client_secret)
32
+ @client_secret = client_secret
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,61 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module TeambitionApi
5
+ module Helpers
6
+ module Base
7
+ def get(action, params, server = nil)
8
+ uri = URI.join(TeambitionApi.config.server, action)
9
+ unless server.nil?
10
+ uri = URI.join(server, action)
11
+ end
12
+ TeambitionApi.logger.info uri
13
+ TeambitionApi.logger.info params
14
+
15
+ uri.query = URI.encode_www_form(params) unless params.nil?
16
+ response = Net::HTTP.get_response(uri)
17
+
18
+ TeambitionApi.logger.info response
19
+
20
+ if response.is_a?(Net::HTTPSuccess)
21
+ result = JSON.parse(response.body)
22
+ else
23
+ result = nil
24
+ raise InvalidResponseError, "对方服务器无法正常访问,返回代码#{response.code}"
25
+ end
26
+
27
+ return result
28
+ end
29
+
30
+ def post(action, params, server = nil)
31
+ uri = URI.join(TeambitionApi.config.server, action)
32
+ unless server.nil?
33
+ uri = URI.join(server, action)
34
+ end
35
+
36
+ TeambitionApi.logger.info uri
37
+ TeambitionApi.logger.info params
38
+
39
+ request = Net::HTTP::Post.new(uri)
40
+ request["Content-Type"] = "application/json"
41
+ request.body = params.to_json
42
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
43
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
44
+ http.ssl_version = :SSLv3
45
+ http.request(request)
46
+ end
47
+
48
+ TeambitionApi.logger.info response.body
49
+
50
+ if response.is_a?(Net::HTTPSuccess)
51
+ result = JSON.parse(response.body)
52
+ else
53
+ result = nil
54
+ raise InvalidResponseError, "对方服务器无法正常访问,返回代码#{response.code}"
55
+ end
56
+
57
+ return result
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,24 @@
1
+ module TeambitionApi
2
+ module Helpers
3
+ class Oauth
4
+ extend TeambitionApi::Helpers::Base
5
+
6
+ ACTIONS_HASH = {
7
+ authorize: "/oauth2/authorize",
8
+ access_token: "/oauth2/access_token"
9
+ }
10
+
11
+
12
+ def self.authorize_url(callback_url, state)
13
+ server_url = "#{TeambitionApi.config.oauth_server}#{ACTIONS_HASH[:authorize]}?client_id=#{TeambitionApi.config.client_key}&redirect_uri=#{callback_url}&state=#{state}"
14
+ return server_url
15
+ end
16
+
17
+ def self.get_access_token(code)
18
+ params = { client_id: TeambitionApi.config.client_key, client_secret: TeambitionApi.config.client_secret, code: code }
19
+ result = post(ACTIONS_HASH[:access_token], params, TeambitionApi.config.oauth_server)
20
+ return result["access_token"]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module TeambitionApi
2
+ module Helpers
3
+ class Organization
4
+ extend TeambitionApi::Helpers::Base
5
+
6
+ ACTIONS_HASH = {
7
+ get_all: "/api/organizations"
8
+ }
9
+
10
+ def self.get_organizations(access_token)
11
+ params = { access_token: access_token }
12
+ get(ACTIONS_HASH[:get_all], params)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module TeambitionApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe "test oauth service" do
4
+ it "get authorize_url" do
5
+ data = TeambitionApi::Helpers::Oauth.authorize_url("https://kaapmvmdlu.localtunnel.me/")
6
+ p data
7
+ expect(data).not_to be_nil
8
+ end
9
+
10
+ it "get access_token" do
11
+ data = TeambitionApi::Helpers::Oauth.authorize_url("https://kaapmvmdlu.localtunnel.me/")
12
+
13
+
14
+ data = TeambitionApi::Helpers::Oauth.get_access_token("123")
15
+ p data
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "test organization service" do
4
+ it "get organizations" do
5
+ data = TeambitionApi::Helpers::Organization.get_organizations
6
+ p data
7
+ expect(data).to eq("00")
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler/setup'
2
+ require 'teambition_api'
3
+
4
+ Bundler.setup
5
+
6
+ TeambitionApi.setup do |config|
7
+ config.oauth_server = "https://account.teambition.com"
8
+ config.server = "https://api.teambition.com"
9
+ config.client_key = "your_key"
10
+ config.client_secret = "your_secrect"
11
+ end
12
+
13
+
14
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'teambition_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "teambition_api"
8
+ spec.version = TeambitionApi::VERSION
9
+ spec.authors = ["402399938"]
10
+ spec.email = ["402399938@qq.com"]
11
+ spec.summary = "TeambitionAPI"
12
+ spec.description = "封装TeambitionAPI"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", '~> 3.3'
24
+ spec.add_development_dependency 'guard', '~> 2.13'
25
+ spec.add_development_dependency 'guard-rspec', '~> 4.6'
26
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teambition_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - '402399938'
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.6'
83
+ description: "封装TeambitionAPI"
84
+ email:
85
+ - 402399938@qq.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Guardfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/teambition_api.rb
97
+ - lib/teambition_api/configuration.rb
98
+ - lib/teambition_api/helpers/base.rb
99
+ - lib/teambition_api/helpers/oauth.rb
100
+ - lib/teambition_api/helpers/organization.rb
101
+ - lib/teambition_api/version.rb
102
+ - spec/helpers/oauth_spec.rb
103
+ - spec/helpers/organization_spec.rb
104
+ - spec/spec_helper.rb
105
+ - teambition_api.gemspec
106
+ homepage: ''
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: TeambitionAPI
130
+ test_files:
131
+ - spec/helpers/oauth_spec.rb
132
+ - spec/helpers/organization_spec.rb
133
+ - spec/spec_helper.rb
134
+ has_rdoc: