ki_youtrack 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ki_youtrack.gemspec +1 -0
- data/lib/ki_youtrack.rb +1 -1
- data/lib/ki_youtrack/api.rb +4 -1
- data/lib/ki_youtrack/session.rb +44 -12
- data/lib/ki_youtrack/version.rb +1 -1
- data/spec/unit/session_spec.rb +21 -0
- metadata +116 -30
- data/lib/ki_youtrack/creds.rb +0 -10
data/ki_youtrack.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_dependency('multi_xml', '~> 0.4.1')
|
22
22
|
gem.add_dependency('multi_json', '~> 1.3.6')
|
23
23
|
gem.add_dependency('highline', '~> 1.6.8')
|
24
|
+
gem.add_dependency('patron', '~> 0.4.18')
|
24
25
|
|
25
26
|
gem.add_development_dependency('debugger', '~> 1.2.0')
|
26
27
|
gem.add_development_dependency('rake', '~> 0.9.2')
|
data/lib/ki_youtrack.rb
CHANGED
@@ -5,6 +5,7 @@ require 'multi_xml'
|
|
5
5
|
require 'multi_json'
|
6
6
|
require 'yaml/store'
|
7
7
|
require 'highline'
|
8
|
+
require 'patron'
|
8
9
|
|
9
10
|
autoload :Kiseru, 'ki_youtrack/kiseru'
|
10
11
|
|
@@ -12,7 +13,6 @@ module KiYoutrack
|
|
12
13
|
|
13
14
|
autoload :Initializer, 'ki_youtrack/initializer'
|
14
15
|
autoload :Api, 'ki_youtrack/api'
|
15
|
-
autoload :Creds, 'ki_youtrack/creds'
|
16
16
|
autoload :Session, 'ki_youtrack/session'
|
17
17
|
autoload :IssueFilter, 'ki_youtrack/issue_filter'
|
18
18
|
|
data/lib/ki_youtrack/api.rb
CHANGED
@@ -15,12 +15,15 @@ module KiYoutrack
|
|
15
15
|
password = @config.read('password')
|
16
16
|
subdomain = @config.read('subdomain')
|
17
17
|
ssl = @config.read('ssl')
|
18
|
+
cookies = @config.read('cached_auth_cookies')
|
18
19
|
|
19
|
-
session = Session.new(login, password, subdomain, :ssl => ssl)
|
20
|
+
session = Session.new(login, password, subdomain, :ssl => ssl, :cookies => cookies)
|
20
21
|
response = session.init
|
21
22
|
|
22
23
|
issue = session.issue(id)
|
23
24
|
|
25
|
+
@config.write('cached_auth_cookies', session.session_cookies.encode("UTF-8"))
|
26
|
+
|
24
27
|
filtered_data = IssueFilter.filter(issue)
|
25
28
|
MultiJson.dump(filtered_data, :pretty => opts[:pretty])
|
26
29
|
end
|
data/lib/ki_youtrack/session.rb
CHANGED
@@ -19,9 +19,11 @@ module KiYoutrack
|
|
19
19
|
@login = login
|
20
20
|
@password = password
|
21
21
|
@api_url = Session.url(subdomain, ssl)
|
22
|
+
@session_cookies = opts[:cookies]
|
22
23
|
end
|
23
24
|
|
24
25
|
def init
|
26
|
+
return if @session_cookies
|
25
27
|
response = connection.post("/youtrack/rest/user/login",
|
26
28
|
:login => @login,
|
27
29
|
:password => @password)
|
@@ -44,24 +46,53 @@ module KiYoutrack
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def user
|
50
|
+
try_with_provided_session do
|
51
|
+
response = connection.get do |req|
|
52
|
+
req.url "/youtrack/rest/admin/user/root"
|
53
|
+
req.headers['Cookie'] = session_cookies
|
54
|
+
req.options[:timeout] = 5
|
55
|
+
req.options[:open_timeout] = 2
|
56
|
+
end
|
57
|
+
case response.status
|
58
|
+
when 200
|
59
|
+
response.body
|
60
|
+
else
|
61
|
+
raise SessionError, "Unhandled status code #{response.status}"
|
62
|
+
end
|
51
63
|
end
|
64
|
+
end
|
52
65
|
|
53
|
-
|
54
|
-
|
55
|
-
response.
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
66
|
+
def issue(id)
|
67
|
+
try_with_provided_session do
|
68
|
+
response = connection.get do |req|
|
69
|
+
req.url "/youtrack/rest/issue/#{id}"
|
70
|
+
req.headers['Cookie'] = session_cookies
|
71
|
+
req.options[:timeout] = 5
|
72
|
+
req.options[:open_timeout] = 2
|
73
|
+
end
|
74
|
+
|
75
|
+
case response.status
|
76
|
+
when 200
|
77
|
+
response.body['issue']
|
78
|
+
when 404
|
79
|
+
raise SessionError, "Can't find issue #{id}"
|
80
|
+
else
|
81
|
+
raise SessionError, "Unhandled status code #{response.status}"
|
82
|
+
end
|
60
83
|
end
|
61
84
|
end
|
62
85
|
|
63
86
|
private
|
64
87
|
|
88
|
+
def try_with_provided_session
|
89
|
+
yield
|
90
|
+
rescue SessionError
|
91
|
+
@session_cookies = nil
|
92
|
+
init
|
93
|
+
yield
|
94
|
+
end
|
95
|
+
|
65
96
|
def connection
|
66
97
|
@connection ||= Faraday.new(:url => @api_url) do |faraday|
|
67
98
|
faraday.request :url_encoded # form-encode POST params
|
@@ -69,7 +100,8 @@ module KiYoutrack
|
|
69
100
|
faraday.response :logger # log requests to STDOUT
|
70
101
|
end
|
71
102
|
faraday.response :xml, :content_type => /\bxml$/
|
72
|
-
faraday.adapter
|
103
|
+
faraday.adapter :patron
|
104
|
+
#faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
73
105
|
end
|
74
106
|
end
|
75
107
|
|
data/lib/ki_youtrack/version.rb
CHANGED
data/spec/unit/session_spec.rb
CHANGED
@@ -37,4 +37,25 @@ describe KiYoutrack::Session do
|
|
37
37
|
issue['id'].should == "KI-1"
|
38
38
|
end
|
39
39
|
|
40
|
+
it "uses provided authentication cookies" do
|
41
|
+
session = Session.new(@login, @password, @subdomain, :ssl => false)
|
42
|
+
session.init
|
43
|
+
cookies = session.session_cookies
|
44
|
+
|
45
|
+
new_session = Session.new(@login, @password, @subdomain,
|
46
|
+
:ssl => false, :cookies => cookies)
|
47
|
+
session.init
|
48
|
+
permissions = session.user
|
49
|
+
session.session_cookies.should == cookies
|
50
|
+
end
|
51
|
+
|
52
|
+
it "gets new authentication cookies if provided ones don't work" do
|
53
|
+
expired_cookies = "JSESSIONID=zzzzzzzzzzzz;Path=/youtrack, jetbrains.charisma.main.security.PRINCIPAL=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;Path=/youtrack;Expires=Tue, 20-Aug-2013 20:28:31 GMT"
|
54
|
+
session = Session.new(@login, @password, @subdomain,
|
55
|
+
:ssl => false, :cookies => expired_cookies)
|
56
|
+
session.init
|
57
|
+
permissions = session.user
|
58
|
+
session.session_cookies.should_not == expired_cookies
|
59
|
+
end
|
60
|
+
|
40
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ki_youtrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-08-
|
13
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gli
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,15 @@ dependencies:
|
|
22
22
|
version: 1.6.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.6.0
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
32
|
name: faraday
|
28
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
36
|
- - ~>
|
@@ -33,10 +38,15 @@ dependencies:
|
|
33
38
|
version: 0.8.2
|
34
39
|
type: :runtime
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.2
|
37
47
|
- !ruby/object:Gem::Dependency
|
38
48
|
name: faraday_middleware
|
39
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
40
50
|
none: false
|
41
51
|
requirements:
|
42
52
|
- - ~>
|
@@ -44,10 +54,15 @@ dependencies:
|
|
44
54
|
version: 0.8.8
|
45
55
|
type: :runtime
|
46
56
|
prerelease: false
|
47
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.8.8
|
48
63
|
- !ruby/object:Gem::Dependency
|
49
64
|
name: multi_xml
|
50
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
51
66
|
none: false
|
52
67
|
requirements:
|
53
68
|
- - ~>
|
@@ -55,10 +70,15 @@ dependencies:
|
|
55
70
|
version: 0.4.1
|
56
71
|
type: :runtime
|
57
72
|
prerelease: false
|
58
|
-
version_requirements:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.4.1
|
59
79
|
- !ruby/object:Gem::Dependency
|
60
80
|
name: multi_json
|
61
|
-
requirement:
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
62
82
|
none: false
|
63
83
|
requirements:
|
64
84
|
- - ~>
|
@@ -66,10 +86,15 @@ dependencies:
|
|
66
86
|
version: 1.3.6
|
67
87
|
type: :runtime
|
68
88
|
prerelease: false
|
69
|
-
version_requirements:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.3.6
|
70
95
|
- !ruby/object:Gem::Dependency
|
71
96
|
name: highline
|
72
|
-
requirement:
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
73
98
|
none: false
|
74
99
|
requirements:
|
75
100
|
- - ~>
|
@@ -77,10 +102,31 @@ dependencies:
|
|
77
102
|
version: 1.6.8
|
78
103
|
type: :runtime
|
79
104
|
prerelease: false
|
80
|
-
version_requirements:
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.6.8
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: patron
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 0.4.18
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 0.4.18
|
81
127
|
- !ruby/object:Gem::Dependency
|
82
128
|
name: debugger
|
83
|
-
requirement:
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
84
130
|
none: false
|
85
131
|
requirements:
|
86
132
|
- - ~>
|
@@ -88,10 +134,15 @@ dependencies:
|
|
88
134
|
version: 1.2.0
|
89
135
|
type: :development
|
90
136
|
prerelease: false
|
91
|
-
version_requirements:
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ~>
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 1.2.0
|
92
143
|
- !ruby/object:Gem::Dependency
|
93
144
|
name: rake
|
94
|
-
requirement:
|
145
|
+
requirement: !ruby/object:Gem::Requirement
|
95
146
|
none: false
|
96
147
|
requirements:
|
97
148
|
- - ~>
|
@@ -99,10 +150,15 @@ dependencies:
|
|
99
150
|
version: 0.9.2
|
100
151
|
type: :development
|
101
152
|
prerelease: false
|
102
|
-
version_requirements:
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ~>
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 0.9.2
|
103
159
|
- !ruby/object:Gem::Dependency
|
104
160
|
name: rspec
|
105
|
-
requirement:
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
106
162
|
none: false
|
107
163
|
requirements:
|
108
164
|
- - ~>
|
@@ -110,10 +166,15 @@ dependencies:
|
|
110
166
|
version: 2.11.0
|
111
167
|
type: :development
|
112
168
|
prerelease: false
|
113
|
-
version_requirements:
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ~>
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: 2.11.0
|
114
175
|
- !ruby/object:Gem::Dependency
|
115
176
|
name: simplecov
|
116
|
-
requirement:
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
117
178
|
none: false
|
118
179
|
requirements:
|
119
180
|
- - ~>
|
@@ -121,10 +182,15 @@ dependencies:
|
|
121
182
|
version: 0.6.4
|
122
183
|
type: :development
|
123
184
|
prerelease: false
|
124
|
-
version_requirements:
|
185
|
+
version_requirements: !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - ~>
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: 0.6.4
|
125
191
|
- !ruby/object:Gem::Dependency
|
126
192
|
name: test-construct
|
127
|
-
requirement:
|
193
|
+
requirement: !ruby/object:Gem::Requirement
|
128
194
|
none: false
|
129
195
|
requirements:
|
130
196
|
- - ~>
|
@@ -132,10 +198,15 @@ dependencies:
|
|
132
198
|
version: 1.2.0
|
133
199
|
type: :development
|
134
200
|
prerelease: false
|
135
|
-
version_requirements:
|
201
|
+
version_requirements: !ruby/object:Gem::Requirement
|
202
|
+
none: false
|
203
|
+
requirements:
|
204
|
+
- - ~>
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: 1.2.0
|
136
207
|
- !ruby/object:Gem::Dependency
|
137
208
|
name: vcr
|
138
|
-
requirement:
|
209
|
+
requirement: !ruby/object:Gem::Requirement
|
139
210
|
none: false
|
140
211
|
requirements:
|
141
212
|
- - ~>
|
@@ -143,10 +214,15 @@ dependencies:
|
|
143
214
|
version: 2.2.4
|
144
215
|
type: :development
|
145
216
|
prerelease: false
|
146
|
-
version_requirements:
|
217
|
+
version_requirements: !ruby/object:Gem::Requirement
|
218
|
+
none: false
|
219
|
+
requirements:
|
220
|
+
- - ~>
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 2.2.4
|
147
223
|
- !ruby/object:Gem::Dependency
|
148
224
|
name: webmock
|
149
|
-
requirement:
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
150
226
|
none: false
|
151
227
|
requirements:
|
152
228
|
- - ~>
|
@@ -154,7 +230,12 @@ dependencies:
|
|
154
230
|
version: 1.8.8
|
155
231
|
type: :development
|
156
232
|
prerelease: false
|
157
|
-
version_requirements:
|
233
|
+
version_requirements: !ruby/object:Gem::Requirement
|
234
|
+
none: false
|
235
|
+
requirements:
|
236
|
+
- - ~>
|
237
|
+
- !ruby/object:Gem::Version
|
238
|
+
version: 1.8.8
|
158
239
|
description: Kiseru YouTrack client
|
159
240
|
email:
|
160
241
|
- ben@freeagent.com
|
@@ -174,7 +255,6 @@ files:
|
|
174
255
|
- ki_youtrack.gemspec
|
175
256
|
- lib/ki_youtrack.rb
|
176
257
|
- lib/ki_youtrack/api.rb
|
177
|
-
- lib/ki_youtrack/creds.rb
|
178
258
|
- lib/ki_youtrack/initializer.rb
|
179
259
|
- lib/ki_youtrack/issue_filter.rb
|
180
260
|
- lib/ki_youtrack/kiseru.rb
|
@@ -197,15 +277,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
277
|
- - ! '>='
|
198
278
|
- !ruby/object:Gem::Version
|
199
279
|
version: '0'
|
280
|
+
segments:
|
281
|
+
- 0
|
282
|
+
hash: 571299714120245625
|
200
283
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
284
|
none: false
|
202
285
|
requirements:
|
203
286
|
- - ! '>='
|
204
287
|
- !ruby/object:Gem::Version
|
205
288
|
version: '0'
|
289
|
+
segments:
|
290
|
+
- 0
|
291
|
+
hash: 571299714120245625
|
206
292
|
requirements: []
|
207
293
|
rubyforge_project:
|
208
|
-
rubygems_version: 1.8.
|
294
|
+
rubygems_version: 1.8.24
|
209
295
|
signing_key:
|
210
296
|
specification_version: 3
|
211
297
|
summary: Kiseru YouTrack client
|