backlog_kit 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e134e8fc91f309ca6a70a8ad4280b03b4b06973
4
- data.tar.gz: f6e4204aaf0ff0226f8acc95b41f437d04adf6b7
3
+ metadata.gz: 752006db289cf9dfc2aa04609fed2c79a74bbe61
4
+ data.tar.gz: b3efd3ad0b22dfc8918e8424212bf93ad7304757
5
5
  SHA512:
6
- metadata.gz: 7811c7270d413a3afc7c056be6fbcba44b1a81fa9e11377c913bafc7ef88a914b3bc0e82e2df3d7ffe58b496f0554b35f6ef3d9718cf2eb7a5418aedbbd96e08
7
- data.tar.gz: 26478ad2a3c3fef466033aac4dec28cd74cb58e9e1086b89e46c1c11d57d93d18f860e8e3974b888840c25f4b22c35e8351ff15bdb1a7152c184bd63c6082982
6
+ metadata.gz: 4ef392ccd33e88bc673d77ccebbaa04f03aebc81c6aea71b44d2dd0adae9447defb1981b3908f5a5c2b7705a4efc1c25d462faa68c5305f5c3042b77f0857a55
7
+ data.tar.gz: 70d3ea2aa209d494d34f2fa1b976d4e1df68a02e6ec246c2a83264795de09a8380da6e533459e7d286e59542655e1876d5e8522ff7811735280d2cf6ab64711f
data/README.md CHANGED
@@ -31,20 +31,51 @@ Or install it yourself as:
31
31
  ```ruby
32
32
  require 'backlog_kit'
33
33
 
34
- client = BacklogKit::Client.new(space_id: 'emsk', api_key: '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234')
34
+ client = BacklogKit::Client.new(
35
+ space_id: 'emsk',
36
+ api_key: '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234'
37
+ )
35
38
 
36
- client.get('space').body # get body
37
- client.get('space').headers # get headers
38
- client.get('space').status # get status
39
+ client.get_space.body # get body
40
+ client.get_space.headers # get headers
41
+ client.get_space.status # get status
39
42
 
40
- client.get('space/activities') # no params
41
- client.get('space/activities', activity_type_id: [1, 4], min_id: 100) # underscored key
42
- client.get('space/activities', activityTypeId: [1, 4], minId: 100) # camelized key
43
+ client.get_space_activities # no params
44
+ client.get_space_activities(activity_type_id: [1, 4], min_id: 100) # underscored key
45
+ client.get_space_activities(activityTypeId: [1, 4], minId: 100) # camelized key
43
46
 
44
- client.post('groups', name: 'beer') # POST method
45
- client.put('space/notification', content: 'Cheers!') # PUT method
46
- client.patch('groups/3712', name: 'whiskey') # PATCH method
47
- client.delete('groups/3712') # DELETE method
47
+ client.get_groups.body[0].members[0].mail_address # method chaining
48
+ ```
49
+
50
+ You can also use low-level methods.
51
+
52
+ ```ruby
53
+ client.get('projects/1234/customFields') # GET
54
+ client.post('groups', name: 'beer') # POST
55
+ client.put('space/notification', content: 'Cheers!') # PUT
56
+ client.patch('groups/3712', name: 'whiskey') # PATCH
57
+ client.delete('groups/3712') # DELETE
58
+ ```
59
+
60
+ ## Authentication
61
+
62
+ ### API Key
63
+
64
+ ```ruby
65
+ client = BacklogKit::Client.new(
66
+ space_id: 'emsk',
67
+ api_key: '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234'
68
+ )
69
+ ```
70
+
71
+ ### OAuth access token
72
+
73
+ ```ruby
74
+ client = BacklogKit::Client.new(
75
+ space_id: 'emsk',
76
+ api_key: nil, # api_key should be nil
77
+ access_token: 'abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcd'
78
+ )
48
79
  ```
49
80
 
50
81
  ## ENV
@@ -53,6 +84,9 @@ client.delete('groups/3712') # DELETE method
53
84
  | :----------- | :---------- |
54
85
  | `BACKLOG_SPACE_ID` | Your Backlog SPACE ID. |
55
86
  | `BACKLOG_API_KEY` | Your Backlog API KEY. |
87
+ | `BACKLOG_OAUTH_CLIENT_ID` | CLIENT ID of your Backlog application. |
88
+ | `BACKLOG_OAUTH_CLIENT_SECRET` | CLIENT SECRET of your Backlog application. |
89
+ | `BACKLOG_OAUTH_REFRESH_TOKEN` | REFRESH TOKEN obtained from the Backlog token endpoint. |
56
90
 
57
91
  You can create instance more easily.
58
92
 
@@ -60,6 +94,23 @@ You can create instance more easily.
60
94
  client = BacklogKit::Client.new
61
95
  ```
62
96
 
97
+ ## Supported API
98
+
99
+ * Git
100
+ * Group
101
+ * Issue
102
+ * Notification
103
+ * Priority
104
+ * Project
105
+ * Resolution
106
+ * Space
107
+ * Star
108
+ * Status
109
+ * User
110
+ * Wiki
111
+
112
+ See [RDoc](http://www.rubydoc.info/gems/backlog_kit) for more details.
113
+
63
114
  ## Development
64
115
 
65
116
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,6 +1,7 @@
1
1
  require 'backlog_kit/error'
2
2
  require 'backlog_kit/response'
3
3
  require 'backlog_kit/version'
4
+ require 'backlog_kit/client/authorization'
4
5
  require 'backlog_kit/client/git'
5
6
  require 'backlog_kit/client/group'
6
7
  require 'backlog_kit/client/issue'
@@ -19,6 +20,7 @@ require 'backlog_kit/hash_extensions'
19
20
 
20
21
  module BacklogKit
21
22
  class Client
23
+ include BacklogKit::Client::Authorization
22
24
  include BacklogKit::Client::Git
23
25
  include BacklogKit::Client::Group
24
26
  include BacklogKit::Client::Issue
@@ -34,17 +36,36 @@ module BacklogKit
34
36
 
35
37
  USER_AGENT = "BacklogKit Ruby Gem #{BacklogKit::VERSION}".freeze
36
38
 
37
- attr_accessor(:space_id, :api_key)
39
+ attr_accessor(
40
+ :space_id,
41
+ :api_key,
42
+ :client_id,
43
+ :client_secret,
44
+ :refresh_token,
45
+ :redirect_uri,
46
+ :state,
47
+ :access_token
48
+ )
38
49
 
39
50
  def initialize(options = {})
40
- @space_id = ENV['BACKLOG_SPACE_ID']
41
- @api_key = ENV['BACKLOG_API_KEY']
51
+ @space_id = ENV['BACKLOG_SPACE_ID']
52
+ @api_key = ENV['BACKLOG_API_KEY']
53
+ @client_id = ENV['BACKLOG_OAUTH_CLIENT_ID']
54
+ @client_secret = ENV['BACKLOG_OAUTH_CLIENT_SECRET']
55
+ @refresh_token = ENV['BACKLOG_OAUTH_REFRESH_TOKEN']
42
56
 
43
57
  options.each do |key, value|
44
58
  instance_variable_set(:"@#{key}", value)
45
59
  end
46
60
  end
47
61
 
62
+ def authorization_url
63
+ url = "#{host}/OAuth2AccessRequest.action?response_type=code&client_id=#{@client_id}"
64
+ url += "&redirect_uri=#{URI.escape(@redirect_uri)}" if @redirect_uri
65
+ url += "&state=#{@state}" if @state
66
+ url
67
+ end
68
+
48
69
  def get(path, params = {})
49
70
  request(:get, path, params)
50
71
  end
@@ -67,8 +88,8 @@ module BacklogKit
67
88
 
68
89
  private
69
90
 
70
- def request(method, path, params = {})
71
- params.camelize_keys!
91
+ def request(method, path, params = {}, raw_params = false)
92
+ params.camelize_keys! unless raw_params
72
93
  faraday_response = connection.send(method, request_path(path), params)
73
94
  BacklogKit::Response.new(faraday_response)
74
95
  rescue Faraday::ConnectionFailed => e
@@ -91,11 +112,19 @@ module BacklogKit
91
112
  end
92
113
 
93
114
  def request_headers
94
- { 'User-Agent' => USER_AGENT }
115
+ headers = { 'User-Agent' => USER_AGENT }
116
+ headers.merge!('Authorization' => "Bearer #{@access_token}") if oauth_request?
117
+ headers
118
+ end
119
+
120
+ def oauth_request?
121
+ !@api_key && @access_token
95
122
  end
96
123
 
97
124
  def request_path(path)
98
- "/api/v2/#{URI.escape(path)}?apiKey=#{URI.escape(@api_key.to_s)}"
125
+ path = "/api/v2/#{URI.escape(path)}"
126
+ path += "?apiKey=#{URI.escape(@api_key.to_s)}" if @api_key
127
+ path
99
128
  end
100
129
  end
101
130
  end
@@ -0,0 +1,26 @@
1
+ module BacklogKit
2
+ class Client
3
+ module Authorization
4
+ def create_token(oauth_code)
5
+ params = {
6
+ client_id: client_id,
7
+ client_secret: client_secret,
8
+ grant_type: 'authorization_code',
9
+ code: oauth_code
10
+ }
11
+ params.merge!(redirect_uri: redirect_uri) if redirect_uri
12
+ request(:post, 'oauth2/token', params, true)
13
+ end
14
+
15
+ def update_token
16
+ params = {
17
+ client_id: client_id,
18
+ client_secret: client_secret,
19
+ grant_type: 'refresh_token',
20
+ refresh_token: refresh_token
21
+ }
22
+ request(:post, 'oauth2/token', params, true)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module BacklogKit
2
- VERSION = '0.11.0'.freeze
2
+ VERSION = '0.12.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backlog_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - emsk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2015-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -184,6 +184,7 @@ files:
184
184
  - bin/setup
185
185
  - lib/backlog_kit.rb
186
186
  - lib/backlog_kit/client.rb
187
+ - lib/backlog_kit/client/authorization.rb
187
188
  - lib/backlog_kit/client/git.rb
188
189
  - lib/backlog_kit/client/group.rb
189
190
  - lib/backlog_kit/client/issue.rb