jira-ruby 0.1.9 → 0.1.10

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: a91329011e2ccf157d07936d501a70beb8ce35e2
4
- data.tar.gz: d1dbd212719b220640475549e59e78a5d861d048
3
+ metadata.gz: cc4f6eb059f491b8aeaf07b2ee453aa9eee6687b
4
+ data.tar.gz: 29f02ed0e3c66b1a06d71342cf7e04574d282c94
5
5
  SHA512:
6
- metadata.gz: c1eb6f1379630c0899d7ea4cc60ed8c2ddf1addef20ee8efc0d2a9d0d9881d5a746634e4e4774cab7fdbe9d13a8426b4530a2111dde82dedc8d1e308474b5437
7
- data.tar.gz: 5a3f281268b3203d4cb7480b78523b65d2aa381d9b21c9f3882eb7f255d8dff59936bd752e50c5084463cdc76497049ed6e52bd163394a289f1c2efef95a6d14
6
+ metadata.gz: 0f176491a5f2ff1558d883f0ac6e5d5b92b2f9aac29a2b6183720e09bfd3ec8a7ae96a12e257f4c92e9f293ddbfc2828287c019dc38a45fb194ac0bcd01d2937
7
+ data.tar.gz: e3b7707569609d99b6431bc20c9f8def378f15286b161e40d51941b9199343ef930a0ad10bee27c80f24dc7b3596f9da5d3ff752c143d1e13f4fdbc02a628406
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'net/https'
3
+ require 'cgi/cookie'
3
4
 
4
5
  module JIRA
5
6
  class HttpClient < RequestClient
@@ -13,13 +14,16 @@ module JIRA
13
14
 
14
15
  def initialize(options)
15
16
  @options = DEFAULT_OPTIONS.merge(options)
17
+ @cookies = {}
16
18
  end
17
19
 
18
20
  def make_request(http_method, path, body='', headers={})
19
21
  request = Net::HTTP.const_get(http_method.to_s.capitalize).new(path, headers)
20
22
  request.body = body unless body.nil?
23
+ add_cookies(request) if options[:use_cookies]
21
24
  request.basic_auth(@options[:username], @options[:password])
22
25
  response = basic_auth_http_conn.request(request)
26
+ store_cookies(response) if options[:use_cookies]
23
27
  response
24
28
  end
25
29
 
@@ -42,5 +46,24 @@ module JIRA
42
46
  def uri
43
47
  uri = URI.parse(@options[:site])
44
48
  end
49
+
50
+ private
51
+
52
+ def store_cookies(response)
53
+ cookies = response.get_fields('set-cookie')
54
+ if cookies
55
+ cookies.each do |cookie|
56
+ data = CGI::Cookie.parse(cookie)
57
+ data.delete('Path')
58
+ @cookies.merge!(data)
59
+ end
60
+ end
61
+ end
62
+
63
+ def add_cookies(request)
64
+ cookie_array = @cookies.values.map { |cookie| cookie.to_s }
65
+ request.add_field('Cookie', cookie_array.join('; ')) if cookie_array.any?
66
+ request
67
+ end
45
68
  end
46
69
  end
data/lib/jira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JIRA
2
- VERSION = "0.1.9"
3
- end
2
+ VERSION = "0.1.10"
3
+ end
@@ -7,12 +7,23 @@ describe JIRA::HttpClient do
7
7
  JIRA::HttpClient.new(options)
8
8
  end
9
9
 
10
+ let(:basic_cookie_client) do
11
+ options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(:use_cookies => true)
12
+ JIRA::HttpClient.new(options)
13
+ end
14
+
10
15
  let(:response) do
11
16
  response = double("response")
12
17
  response.stub(:kind_of?).with(Net::HTTPSuccess).and_return(true)
13
18
  response
14
19
  end
15
20
 
21
+ let(:cookie_response) do
22
+ response = double("response")
23
+ response.stub(:kind_of?).with(Net::HTTPSuccess).and_return(true)
24
+ response
25
+ end
26
+
16
27
  it "creates an instance of Net:HTTP for a basic auth client" do
17
28
  basic_client.basic_auth_http_conn.class.should == Net::HTTP
18
29
  end
@@ -36,6 +47,27 @@ describe JIRA::HttpClient do
36
47
  end
37
48
  end
38
49
 
50
+ it "gets and sets cookies" do
51
+ body = ''
52
+ headers = double()
53
+ basic_auth_http_conn = double()
54
+ request = double()
55
+ basic_cookie_client.stub(:basic_auth_http_conn => basic_auth_http_conn)
56
+ request.should_receive(:basic_auth).with(basic_cookie_client.options[:username], basic_cookie_client.options[:password]).exactly(5).times.and_return(request)
57
+ cookie_response.should_receive(:get_fields).with('set-cookie').exactly(5).times
58
+ basic_auth_http_conn.should_receive(:request).exactly(5).times.with(request).and_return(cookie_response)
59
+ [:delete, :get, :head].each do |method|
60
+ Net::HTTP.const_get(method.to_s.capitalize).should_receive(:new).with('/path', headers).and_return(request)
61
+ basic_cookie_client.make_request(method, '/path', nil, headers).should == cookie_response
62
+ end
63
+ [:post, :put].each do |method|
64
+ Net::HTTP.const_get(method.to_s.capitalize).should_receive(:new).with('/path', headers).and_return(request)
65
+ request.should_receive(:body=).with(body).and_return(request)
66
+ basic_cookie_client.make_request(method, '/path', body, headers).should == cookie_response
67
+ end
68
+ end
69
+
70
+
39
71
  it "performs a basic http client request" do
40
72
  body = nil
41
73
  headers = double()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUMO Heavy Industries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-25 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
225
  version: '0'
226
226
  requirements: []
227
227
  rubyforge_project: jira-ruby
228
- rubygems_version: 2.2.2
228
+ rubygems_version: 2.0.5
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: Ruby Gem for use with the Atlassian JIRA REST API