rally-wsapi 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +15 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/wsapi/session.rb +67 -15
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8fcd6dfc98a371448591ac323e980f16b38220b
|
4
|
+
data.tar.gz: 16fde94fe2cd3776b90ca3150f92cbc147634e65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df67aba1e91f9e1e650ca5d5304d6d9c16da733471df6e0f4bebc26d4637502a84da570f1cb754c7c67befdeb52ff277a690cf9c2034b336df8c5439fcc27d0a
|
7
|
+
data.tar.gz: 51a297733c01698f72bb1aacd44f7385f7577683b304f0b7fca522e19870e364e039dbe3397ebacb237aee610fbc50e356e7a0a51526ad574670a51a42f09ffd
|
data/Gemfile.lock
CHANGED
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
rdoc
|
36
36
|
json (1.8.1)
|
37
37
|
jwt (1.2.0)
|
38
|
-
mini_portile (0.6.
|
38
|
+
mini_portile (0.6.1)
|
39
39
|
multi_json (1.10.1)
|
40
40
|
multi_xml (0.5.5)
|
41
41
|
multipart-post (2.0.0)
|
@@ -47,7 +47,7 @@ GEM
|
|
47
47
|
multi_json (~> 1.3)
|
48
48
|
multi_xml (~> 0.5)
|
49
49
|
rack (~> 1.2)
|
50
|
-
rack (1.
|
50
|
+
rack (1.5.2)
|
51
51
|
rake (10.4.2)
|
52
52
|
rdoc (4.2.0)
|
53
53
|
json (~> 1.4)
|
data/README.md
CHANGED
@@ -14,7 +14,15 @@ s = Wsapi::Session.new("deadbeefdeadbeef")
|
|
14
14
|
The constructor also accepts the following options:
|
15
15
|
* `:workspace_id`, if not given, user's default workspace is used for queries
|
16
16
|
* `:version`, WSAPI version, default is `3.0`
|
17
|
+
* `oauth2`, see: (using WSAPI with OAuth2)[https://github.com/flowdock/rally-wsapi#using-wsapi-with-oauth2]
|
17
18
|
|
19
|
+
### Using WSAPI with OAuth2
|
20
|
+
|
21
|
+
Authenticating to WSAPI is also possible with OAuth2. Access token used in
|
22
|
+
requests is given in place of the API token. Refresh token can be supplied with
|
23
|
+
`Wsapi::Session#.setup_refresh_token(client_id, client_secret, refresh_token)`
|
24
|
+
method. It takes optional block parameter, which is called every time the
|
25
|
+
access token is refreshed.
|
18
26
|
|
19
27
|
## Method reference for Session
|
20
28
|
|
@@ -81,6 +89,13 @@ get_editors(project_id, opts = {})
|
|
81
89
|
update_artifact(artifact_type, artifact_id, parameters)
|
82
90
|
```
|
83
91
|
|
92
|
+
### Setup refresh token to be used with OAuth2
|
93
|
+
```
|
94
|
+
setup_refresh_token(client_id, client_secret, refresh_token, &block)
|
95
|
+
```
|
96
|
+
|
97
|
+
See (Using WSAPI with OAuth2)[https://github.com/flowdock/rally-wsapi#using-wsapi-with-oauth2] for more info.
|
98
|
+
|
84
99
|
## Result objects
|
85
100
|
|
86
101
|
There's a couple of convenience classes for the following object types:
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ Jeweler::Tasks.new do |s|
|
|
6
6
|
s.email = "antti@flowdock.com"
|
7
7
|
s.homepage = "http://github.com/flowdock/rally-wsapi"
|
8
8
|
s.description = "Simple client for Rally WSAPI"
|
9
|
-
s.authors = ["Antti Pitkänen"]
|
9
|
+
s.authors = ["Antti Pitkänen", "Oskari Virtanen"]
|
10
10
|
s.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"]
|
11
11
|
s.licenses = ["MIT"]
|
12
12
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/wsapi/session.rb
CHANGED
@@ -4,7 +4,6 @@ require 'faraday_middleware'
|
|
4
4
|
require 'excon'
|
5
5
|
|
6
6
|
require_relative './mapper'
|
7
|
-
|
8
7
|
module Wsapi
|
9
8
|
class StandardErrorWithResponse < StandardError
|
10
9
|
attr_reader :response
|
@@ -19,6 +18,7 @@ module Wsapi
|
|
19
18
|
class IpAddressLimited < StandardErrorWithResponse; end
|
20
19
|
|
21
20
|
WSAPI_URL = ENV['WSAPI_URL'] || 'https://rally1.rallydev.com/slm/webservice/'
|
21
|
+
AUTH_URL = ENV['RALLY_AUTHENTICATION_URL'] || "https://rally1.rallydev.com/login/oauth2/token"
|
22
22
|
|
23
23
|
class WsapiAuthentication < Faraday::Middleware
|
24
24
|
def initialize(logger, session_id)
|
@@ -37,13 +37,17 @@ module Wsapi
|
|
37
37
|
|
38
38
|
def initialize(session_id, opts = {})
|
39
39
|
@api_version = opts[:version] || "3.0"
|
40
|
-
@session_id = session_id
|
41
40
|
@workspace_id = opts[:workspace_id]
|
42
|
-
@conn =
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
@conn = connection(session_id)
|
42
|
+
end
|
43
|
+
|
44
|
+
def setup_refresh_token(client_id, client_secret, refresh_token, &block)
|
45
|
+
@oauth2 = {
|
46
|
+
client_id: client_id,
|
47
|
+
client_secret: client_secret,
|
48
|
+
refresh_token: refresh_token,
|
49
|
+
refresh_token_updated: block
|
50
|
+
}
|
47
51
|
end
|
48
52
|
|
49
53
|
def get_user_subscription
|
@@ -106,6 +110,14 @@ module Wsapi
|
|
106
110
|
|
107
111
|
private
|
108
112
|
|
113
|
+
def connection(session_id)
|
114
|
+
Faraday.new(ssl: {version: :TLSv1}) do |faraday|
|
115
|
+
faraday.request :json
|
116
|
+
faraday.use WsapiAuthentication, session_id
|
117
|
+
faraday.adapter :excon
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
109
121
|
def workspace_url
|
110
122
|
wsapi_resource_url("Workspace/#{@workspace_id}")
|
111
123
|
end
|
@@ -115,22 +127,62 @@ module Wsapi
|
|
115
127
|
end
|
116
128
|
|
117
129
|
def wsapi_post(url, opts = {})
|
118
|
-
response =
|
130
|
+
response = wsapi_request_with_refresh_token(:post, url, opts)
|
119
131
|
check_response_for_errors!(response)
|
120
132
|
|
121
133
|
response
|
122
134
|
end
|
123
135
|
|
124
136
|
def wsapi_get(url, opts = {})
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
137
|
+
request_options = {}
|
138
|
+
request_options['workspace'] = workspace_url if @workspace_id
|
139
|
+
request_options['query'] = opts[:query] if opts[:query]
|
140
|
+
request_options['start'] = opts[:start] || 1
|
141
|
+
request_options['pagesize'] = opts[:pagesize] || 200
|
142
|
+
request_options['fetch'] = opts[:fetch] || true # by default, fetch full objects
|
143
|
+
|
144
|
+
response = wsapi_request_with_refresh_token(:get, url, request_options)
|
145
|
+
check_response_for_errors!(response)
|
146
|
+
|
147
|
+
response
|
148
|
+
end
|
149
|
+
|
150
|
+
def wsapi_request_with_refresh_token(method, url, opts = {})
|
151
|
+
response = @conn.send(method, url, opts)
|
152
|
+
if defined?(@oauth2) && response.status == 401
|
153
|
+
refresh_token_response = refresh_token!
|
154
|
+
|
155
|
+
access_token = MultiJson.load(refresh_token_response.body)["access_token"]
|
156
|
+
@conn = connection(access_token)
|
157
|
+
response = @conn.send(method, url, opts) # Try again with fresh token
|
158
|
+
end
|
159
|
+
|
160
|
+
response
|
161
|
+
end
|
162
|
+
|
163
|
+
def refresh_token!
|
164
|
+
client = Faraday.new(ssl: {version: :TLSv1}) do |faraday|
|
165
|
+
faraday.request :url_encoded
|
166
|
+
faraday.adapter :excon
|
132
167
|
end
|
168
|
+
|
169
|
+
refresh_params = {
|
170
|
+
grant_type: "refresh_token",
|
171
|
+
refresh_token: @oauth2[:refresh_token],
|
172
|
+
client_id: @oauth2[:client_id],
|
173
|
+
client_secret: @oauth2[:client_secret]
|
174
|
+
}
|
175
|
+
|
176
|
+
response = client.post AUTH_URL, refresh_params
|
177
|
+
|
133
178
|
check_response_for_errors!(response)
|
179
|
+
|
180
|
+
response_body = MultiJson.load(response.body)
|
181
|
+
|
182
|
+
@oauth2[:refresh_token] = response_body["refresh_token"]
|
183
|
+
if @oauth2[:refresh_token_updated]
|
184
|
+
@oauth2[:refresh_token_updated].call(MultiJson.load(response.body))
|
185
|
+
end
|
134
186
|
response
|
135
187
|
end
|
136
188
|
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rally-wsapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antti Pitkänen
|
8
|
+
- Oskari Virtanen
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
12
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake
|
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
122
|
version: '0'
|
122
123
|
requirements: []
|
123
124
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.4.
|
125
|
+
rubygems_version: 2.4.3
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Simple client for Rally WSAPI
|