confluence-soap 0.0.8 → 0.0.9

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: 5dd3ae54fb12362a0f0e89e5d5d01451edd1519f
4
- data.tar.gz: 30d78f9164051adceb7759a9b307de247be9ea57
3
+ metadata.gz: 833da3e2d59c0f3a7244562cb72b2711613ccf60
4
+ data.tar.gz: dc911c4d3142cba6e141c827b297ae98a8a699ff
5
5
  SHA512:
6
- metadata.gz: 1d4a364b0a3962ae83c3034544155c2532632f6e0bc0f47d6896a6d8cf9897c16d0c3d78e5d27bcd4744987b9fa9b1463542715120d65d8d98622df7ef65995e
7
- data.tar.gz: 8791722d3061ebbe9015cf6594b3302d7715b6e8d789b0f991d363f214f9e035b3fe9ebcd2e25973ddf8cf7366fd58195946a921ac8216445b6bea9ed8cb8094
6
+ metadata.gz: 574e10ad50fe1de0896b3db19f540415754c91fbc94c3849f1fe4c217d70f80baa7b2baf967aad957539346125d316059a798fda575b340f7f6f53828bc157ab
7
+ data.tar.gz: 16b3a22ee6b0274f3b161fee88b39b7e605596202dd2657b028495d1704688f33ef629d8c419182c4e1fb5ce5b496b3fe287eb2b0dc339453b3fbc364294cacd
data/Gemfile CHANGED
@@ -1,13 +1,20 @@
1
1
  source "https://rubygems.org"
2
- gem 'savon'
2
+ gem 'savon', '~> 2.3.3'
3
3
 
4
4
  group :development do
5
5
  gem "bundler", "~> 1.0"
6
6
  gem "jeweler", "~> 2.0.0"
7
7
  gem "rdoc", "~> 3.12"
8
+ gem "pry-debugger"
9
+ gem "pry-stack_explorer"
10
+ gem "yard"
11
+ gem "redcarpet"
8
12
  end
9
13
 
10
14
  group :test do
11
15
  gem "rspec", "~> 2.8.0"
12
16
  gem "simplecov"
17
+
18
+ gem 'vcr', '~> 2.8.0'
19
+ gem 'webmock', '~> 1.15.0'
13
20
  end
data/Gemfile.lock CHANGED
@@ -2,17 +2,30 @@ GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
4
  addressable (2.3.5)
5
- akami (1.2.0)
5
+ akami (1.2.1)
6
6
  gyoku (>= 0.4.0)
7
- nokogiri (>= 1.4.0)
7
+ nokogiri
8
+ binding_of_caller (0.7.2)
9
+ debug_inspector (>= 0.0.1)
8
10
  builder (3.2.2)
11
+ coderay (1.1.0)
12
+ columnize (0.3.6)
13
+ crack (0.4.2)
14
+ safe_yaml (~> 1.0.0)
15
+ debug_inspector (0.0.2)
16
+ debugger (1.6.5)
17
+ columnize (>= 0.3.1)
18
+ debugger-linecache (~> 1.2.0)
19
+ debugger-ruby_core_source (~> 1.3.1)
20
+ debugger-linecache (1.2.0)
21
+ debugger-ruby_core_source (1.3.1)
9
22
  descendants_tracker (0.0.3)
10
23
  diff-lcs (1.1.3)
11
- docile (1.1.1)
24
+ docile (1.1.3)
12
25
  faraday (0.9.0)
13
26
  multipart-post (>= 1.2, < 3)
14
27
  git (1.2.6)
15
- github_api (0.11.1)
28
+ github_api (0.11.2)
16
29
  addressable (~> 2.3)
17
30
  descendants_tracker (~> 0.0.1)
18
31
  faraday (~> 0.8, < 0.10)
@@ -27,7 +40,7 @@ GEM
27
40
  httpi (2.1.0)
28
41
  rack
29
42
  rubyntlm (~> 0.3.2)
30
- jeweler (2.0.0)
43
+ jeweler (2.0.1)
31
44
  builder
32
45
  bundler (>= 1.0)
33
46
  git (>= 1.2.5)
@@ -39,6 +52,7 @@ GEM
39
52
  json (1.8.1)
40
53
  jwt (0.1.11)
41
54
  multi_json (>= 1.5)
55
+ method_source (0.8.2)
42
56
  mime-types (1.25.1)
43
57
  mini_portile (0.5.2)
44
58
  multi_json (1.8.4)
@@ -53,10 +67,21 @@ GEM
53
67
  multi_json (~> 1.3)
54
68
  multi_xml (~> 0.5)
55
69
  rack (~> 1.2)
70
+ pry (0.9.12.6)
71
+ coderay (~> 1.0)
72
+ method_source (~> 0.8)
73
+ slop (~> 3.4)
74
+ pry-debugger (0.2.2)
75
+ debugger (~> 1.3)
76
+ pry (~> 0.9.10)
77
+ pry-stack_explorer (0.4.9.1)
78
+ binding_of_caller (>= 0.7)
79
+ pry (>= 0.9.11)
56
80
  rack (1.5.2)
57
81
  rake (10.1.1)
58
82
  rdoc (3.12.2)
59
83
  json (~> 1.4)
84
+ redcarpet (3.0.0)
60
85
  rspec (2.8.0)
61
86
  rspec-core (~> 2.8.0)
62
87
  rspec-expectations (~> 2.8.0)
@@ -66,6 +91,7 @@ GEM
66
91
  diff-lcs (~> 1.1.2)
67
92
  rspec-mocks (2.8.0)
68
93
  rubyntlm (0.3.4)
94
+ safe_yaml (1.0.1)
69
95
  savon (2.3.3)
70
96
  akami (~> 1.2.0)
71
97
  builder (>= 2.1.2)
@@ -79,10 +105,16 @@ GEM
79
105
  multi_json
80
106
  simplecov-html (~> 0.8.0)
81
107
  simplecov-html (0.8.0)
108
+ slop (3.4.7)
109
+ vcr (2.8.0)
82
110
  wasabi (3.2.3)
83
111
  httpi (~> 2.0)
84
112
  mime-types (< 2.0.0)
85
113
  nokogiri (>= 1.4.0)
114
+ webmock (1.15.2)
115
+ addressable (>= 2.2.7)
116
+ crack (>= 0.3.2)
117
+ yard (0.8.7.3)
86
118
 
87
119
  PLATFORMS
88
120
  ruby
@@ -90,7 +122,13 @@ PLATFORMS
90
122
  DEPENDENCIES
91
123
  bundler (~> 1.0)
92
124
  jeweler (~> 2.0.0)
125
+ pry-debugger
126
+ pry-stack_explorer
93
127
  rdoc (~> 3.12)
128
+ redcarpet
94
129
  rspec (~> 2.8.0)
95
- savon
130
+ savon (~> 2.3.3)
96
131
  simplecov
132
+ vcr (~> 2.8.0)
133
+ webmock (~> 1.15.0)
134
+ yard
data/README.md CHANGED
@@ -3,7 +3,26 @@ confluence-soap
3
3
 
4
4
  Ruby client for Confluence's SOAP API
5
5
 
6
- http://<confluence-install>/rpc/soap-axis/confluenceservice-v2?wsdl
6
+ http://<confluence-install>/wiki/rpc/soap-axis/confluenceservice-v2?wsdl
7
+
8
+ ## Example Usage
9
+
10
+ ```ruby
11
+ require 'confluence-soap'
12
+
13
+ cs = ConfluenceSoap.new("http://<confluence-install>/wiki/rpc/soap-axis/confluenceservice-v2?wsdl",
14
+ "user", "password")
15
+
16
+ cs.get_pages("name_of_your_space")
17
+ ```
18
+ ## Running the specs
19
+
20
+ First:
21
+ `cp config/confluence.yml.example config/confluence.yml`
22
+
23
+ Then edit `config/confluence.yml` to match your instance's settings.
24
+ You should create a separate confluence space for the specs to run
25
+ against, as running the specs will delete all pages in that space.
7
26
 
8
27
  ## Contributing to confluence-soap
9
28
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.0.9
@@ -0,0 +1,4 @@
1
+ :space: test_environment_space
2
+ :url: https://<your-instance-host>/wiki/rpc/soap-axis/confluenceservice-v2?wsdl
3
+ :user: api_user
4
+ :password: password
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "confluence-soap"
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ping Yu", "Eric Himmelreich"]
12
- s.date = "2014-01-29"
12
+ s.date = "2014-02-10"
13
13
  s.description = ""
14
14
  s.email = ["ping@intridea.com", "eric@intridea.com"]
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "README.md",
27
27
  "Rakefile",
28
28
  "VERSION",
29
+ "config/confluence.yml.example",
29
30
  "confluence-soap.gemspec",
30
31
  "lib/confluence-soap.rb",
31
32
  "spec/confluence-soap_spec.rb",
@@ -41,21 +42,33 @@ Gem::Specification.new do |s|
41
42
  s.specification_version = 4
42
43
 
43
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_runtime_dependency(%q<savon>, [">= 0"])
45
+ s.add_runtime_dependency(%q<savon>, ["~> 2.3.3"])
45
46
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
46
47
  s.add_development_dependency(%q<jeweler>, ["~> 2.0.0"])
47
48
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_development_dependency(%q<pry-debugger>, [">= 0"])
50
+ s.add_development_dependency(%q<pry-stack_explorer>, [">= 0"])
51
+ s.add_development_dependency(%q<yard>, [">= 0"])
52
+ s.add_development_dependency(%q<redcarpet>, [">= 0"])
48
53
  else
49
- s.add_dependency(%q<savon>, [">= 0"])
54
+ s.add_dependency(%q<savon>, ["~> 2.3.3"])
50
55
  s.add_dependency(%q<bundler>, ["~> 1.0"])
51
56
  s.add_dependency(%q<jeweler>, ["~> 2.0.0"])
52
57
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
59
+ s.add_dependency(%q<pry-stack_explorer>, [">= 0"])
60
+ s.add_dependency(%q<yard>, [">= 0"])
61
+ s.add_dependency(%q<redcarpet>, [">= 0"])
53
62
  end
54
63
  else
55
- s.add_dependency(%q<savon>, [">= 0"])
64
+ s.add_dependency(%q<savon>, ["~> 2.3.3"])
56
65
  s.add_dependency(%q<bundler>, ["~> 1.0"])
57
66
  s.add_dependency(%q<jeweler>, ["~> 2.0.0"])
58
67
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
68
+ s.add_dependency(%q<pry-debugger>, [">= 0"])
69
+ s.add_dependency(%q<pry-stack_explorer>, [">= 0"])
70
+ s.add_dependency(%q<yard>, [">= 0"])
71
+ s.add_dependency(%q<redcarpet>, [">= 0"])
59
72
  end
60
73
  end
61
74
 
@@ -1,6 +1,8 @@
1
1
  require 'savon'
2
2
 
3
3
  class ConfluenceSoap
4
+ module Error; end
5
+
4
6
  attr_reader :client, :token, :user
5
7
 
6
8
  Page = Struct.new(:content, :content_status, :created, :creator, :current,
@@ -22,103 +24,149 @@ class ConfluenceSoap
22
24
  end
23
25
  end
24
26
 
25
- def initialize(url, user, password)
27
+ def initialize(url, user, password, opts = {})
28
+ opts = opts.merge(wsdl: url)
26
29
  @user = user
27
30
  @password = password
28
- @client = Savon.client(wsdl: url) do
31
+ @client = Savon.client(opts) do
29
32
  convert_request_keys_to :lower_camelcase
30
33
  end
31
- @token = login(user, password)
34
+ @token = login
32
35
  end
33
36
 
34
- def login(user, password)
35
- response = @client.call :login, message: {in0: user, in1: password}
36
- @token = response.body[:login_response][:login_return]
37
+ def login
38
+ response = client.call(:login, message: {in0: @user, in1: @password})
39
+ @token = parse_response(:login, response)
37
40
  end
38
41
 
39
42
  def logout
40
- @client.call :logout, message: {in0: @token} if @token
43
+ client.call(:logout, message: {in0: @token}) if @token
41
44
  end
42
45
 
43
46
  def get_pages(space)
44
- response = @client.call :get_pages, auth_message({in1: space})
45
- pages = parse_array_response :get_pages, response
47
+ response = execute do
48
+ client.call(:get_pages, auth_message({in1: space}))
49
+ end
50
+
51
+ pages = parse_array_response(:get_pages, response)
46
52
  pages.map { |page| Page.from_hash(page) }
47
53
  end
48
54
 
49
55
  def get_page(page_id)
50
- response = @client.call :get_page, auth_message({in1: page_id})
51
- Page.from_hash parse_response :get_page, response
56
+ response = execute do
57
+ client.call(:get_page, auth_message({in1: page_id}))
58
+ end
59
+
60
+ Page.from_hash(parse_response(:get_page, response))
52
61
  end
53
62
 
54
63
  def get_children(page_id)
55
- response = @client.call :get_children, auth_message({in1: page_id})
56
- pages = parse_array_response :get_children, response
64
+ response = execute do
65
+ client.call(:get_children, auth_message({in1: page_id}))
66
+ end
67
+
68
+ pages = parse_array_response(:get_children, response)
57
69
  pages.map { |page| Page.from_hash(page) }
58
70
  end
59
71
 
60
72
  def store_page(page)
61
- response = @client.call :store_page, auth_message({in1: page.to_soap})
62
- Page.from_hash parse_response :store_page, response
73
+ response = execute do
74
+ client.call(:store_page, auth_message({in1: page.to_soap}))
75
+ end
76
+
77
+ Page.from_hash(parse_response(:store_page, response))
63
78
  end
64
79
 
65
80
  def update_page(page)
66
- response =
67
- @client.call(:update_page,
68
- auth_message({in1: page.to_soap, in2: {minorEdit: true} }))
69
- Page.from_hash parse_response :update_page, response
81
+ response = execute do
82
+ client.call(:update_page,
83
+ auth_message({in1: page.to_soap, in2: {minorEdit: true} }))
84
+ end
85
+
86
+ Page.from_hash(parse_response(:update_page, response))
70
87
  end
71
88
 
72
89
  def remove_page(page_id)
73
- response = @client.call :remove_page, auth_message({in1: page_id})
74
- Page.from_hash parse_response :remove_page, response
90
+ response = execute do
91
+ client.call(:remove_page, auth_message({in1: page_id}))
92
+ end
93
+
94
+ parse_response(:remove_page, response)
75
95
  end
76
96
 
77
97
  def search(term, criteria = {})
78
98
  limit = criteria.delete(:limit) || 20
79
99
  criteria = criteria.map { |k, v| {key: k, value: v} }
80
- response =
81
- @client.call(:search,
82
- auth_message({in1: term, in2: {item: criteria}, in3: limit}))
83
- pages = parse_array_response :search, response
100
+ response = execute do
101
+ client.call(:search,
102
+ auth_message({in1: term, in2: {item: criteria}, in3: limit}))
103
+ end
104
+
105
+ pages = parse_array_response(:search, response)
84
106
  pages.map { |page| Page.from_hash(page) }
85
107
  end
86
108
 
87
109
  def add_label_by_name(label, page_id)
88
- response =
89
- @client.call(:add_label_by_name, auth_message({in1: label, in2: page_id}))
110
+ response = execute do
111
+ client.call(:add_label_by_name, auth_message({in1: label, in2: page_id}))
112
+ end
90
113
 
91
114
  parse_response(:add_label_by_name, response)
92
115
  end
93
116
 
94
117
  def remove_label_by_name(label, page_id)
95
- response =
96
- @client.call(:remove_label_by_name,
97
- auth_message({in1: label, in2: page_id}))
118
+ response = execute do
119
+ client.call(:remove_label_by_name,
120
+ auth_message({in1: label, in2: page_id}))
121
+ end
98
122
 
99
123
  parse_response(:remove_label_by_name, response)
100
124
  end
101
125
 
102
- def has_user(user)
103
- response = @client.call(:has_user, auth_message({in1: user}))
126
+ def has_user?(user)
127
+ response = execute do
128
+ client.call(:has_user, auth_message({in1: user}))
129
+ end
130
+
104
131
  parse_response(:has_user, response)
105
132
  end
106
133
 
107
- def execute(&block)
108
- yield self
109
- rescue Savon::SOAPFault => e
110
- if e.to_hash[:fault][:faultstring] =~ /InvalidSessionException/
111
- reconnect
112
- yield e
113
- else
114
- raise e
115
- end
134
+ private
135
+
136
+ def execute
137
+ if block_given?
138
+ yield
139
+ else
140
+ tag_errors { raise StandardError.new('requires a block') }
141
+ end
142
+ rescue Exception => e
143
+ if invalid_session?(e)
144
+ reconnect
145
+ # @note necessary for catching an invalid session, and then a
146
+ # Savon::SOAPFault on the same request
147
+ tag_errors { yield e }
148
+ else
149
+ tag_errors { raise e }
150
+ end
151
+ end
152
+
153
+ def invalid_session?(exception)
154
+ if exception.respond_to?(:to_hash)
155
+ fault = exception.to_hash.fetch(:fault) { {} }
156
+
157
+ fault[:faultstring] =~ /InvalidSessionException/
158
+ end
116
159
  end
117
160
 
118
- private
161
+ def tag_errors
162
+ yield
163
+ rescue Exception => e
164
+ e.extend(ConfluenceSoap::Error)
165
+ raise
166
+ end
119
167
 
120
168
  def reconnect
121
- login(@user, @password)
169
+ @token = login
122
170
  end
123
171
 
124
172
  def parse_array_response(method, response)
@@ -1,183 +1,166 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ConfluenceSoap do
4
- let (:url) {'http://example.com?wsdl'}
5
- subject {ConfluenceSoap.new(url, 'user', 'password')}
4
+ let (:url) { ConfluenceConfig[:url] }
5
+ let(:space) { ConfluenceConfig[:space] }
6
+ let(:page) do
7
+ ConfluenceSoap::Page.from_hash({content: 'test', title: 'Testing API ',
8
+ space: ConfluenceConfig[:space],
9
+ permissions: 0})
10
+ end
11
+
12
+ subject do
13
+ ConfluenceSoap.new(url, ConfluenceConfig[:user],
14
+ ConfluenceConfig[:password],
15
+ log: false)
6
16
 
7
- describe 'Page' do
8
- ConfluenceSoap::Page.new.to_h
9
17
  end
10
18
 
19
+ shared_context 'invalidate session to force a reconnect' do
20
+ before(:each) do
21
+ ignore_request do
22
+ @token = subject.token
23
+
24
+ subject.client.stub(:call)
25
+ .and_return(double(body:
26
+ {login_response:
27
+ {login_return: 'invalid_token'}}))
28
+ subject.login
29
+ subject.client.unstub(:call)
30
+ subject.stub(:login).and_return(@token)
31
+ end
32
+ end
33
+ end
34
+
35
+
11
36
  describe '#initialize' do
12
- it 'should create a savon soap client with url provided' do
13
- Savon.should_receive(:client).with(wsdl: url)
37
+ it 'creates a savon soap client with url provided' do
14
38
  ConfluenceSoap.any_instance.should_receive(:login)
39
+ Savon.should_receive(:client)
15
40
 
16
41
  subject
17
42
  end
18
43
  end
19
44
 
20
- describe '#login' do
21
- before (:each) do
22
- Savon::Client.any_instance.should_receive(:call).twice
23
- .with(:login, message: {in0: 'user', in1: 'password'})
24
- .and_return(double(:response, body: {login_response: {login_return: 'token'}}))
25
- end
45
+ context 'when #login repeatedly fails' do
46
+ it 'should raise the library error' do
47
+ ConfluenceSoap.any_instance.stub(:login).and_return('invalid-token')
26
48
 
27
- it 'should login with savon client' do
28
-
29
- subject.login('user', 'password')
49
+ VCR.use_cassette(:repeated_login_failures) do
50
+ lambda {
51
+ subject.get_pages(space)
52
+ }.should raise_error(ConfluenceSoap::Error)
53
+ end
30
54
  end
55
+ end
31
56
 
32
- it 'should store the login token' do
33
- subject.login('user', 'password')
57
+ describe '#login' do
58
+ it 'stores the session token' do
59
+ VCR.use_cassette(:login) do
60
+ subject.login
61
+ end
34
62
 
35
- subject.token.should == 'token'
63
+ subject.token.should_not be_nil
36
64
  end
37
65
  end
38
66
 
39
67
  describe 'with an authenticated user' do
40
- before(:each) do
41
- ConfluenceSoap.any_instance.stub(:login).and_return('token')
42
- end
43
-
44
- describe '#get_pages' do
45
- let(:space) { 'SpaceName' }
46
- before (:each) do
68
+ include_context 'invalidate session to force a reconnect'
47
69
 
48
- subject.client.should_receive(:call)
49
- .with(:get_pages, message: {in0: 'token', in1: space})
50
- .and_return(double(:response, body: {get_pages_response: {get_pages_return: {get_pages_return: []}}}))
70
+ describe '#store_page' do
71
+ it 'stores the page and returns it' do
72
+ ignore_request do
73
+ subject.store_page(page).should be_instance_of(ConfluenceSoap::Page)
74
+ end
51
75
  end
52
76
 
53
- it 'should return the pages in the space' do
54
- subject.get_pages(space).should == []
77
+ context 'when the page already exists' do
78
+ it 'should raise the library error' do
79
+ ignore_request do
80
+ lambda { subject.store_page(page) }
81
+ .should raise_error(ConfluenceSoap::Error)
82
+ end
83
+ end
55
84
  end
56
85
  end
57
86
 
58
- describe '#get_page' do
59
- let(:page_id) { '123456' }
60
- before (:each) do
61
- subject.client.should_receive(:call)
62
- .with(:get_page, message: {in0: 'token', in1: page_id})
63
- .and_return(double(:response, body: {get_page_response: {get_page_return: {}}}))
64
- end
65
-
66
- it 'should return the page' do
67
- subject.get_page page_id
87
+ describe '#get_pages' do
88
+ it 'should return the pages in the space' do
89
+ VCR.use_cassette(:get_pages) do
90
+ subject.get_pages(space).size.should == 1
91
+ end
68
92
  end
69
93
  end
70
94
 
71
95
  describe '#get_page' do
72
- let(:page_id) { '123456' }
73
- before (:each) do
74
- subject.client.should_receive(:call)
75
- .with(:remove_page, message: {in0: 'token', in1: page_id})
76
- .and_return(double(:response, body: {remove_page_response: {remove_page_return: {}}}))
77
- end
78
-
79
96
  it 'should return the page' do
80
- subject.remove_page page_id
97
+ VCR.use_cassette(:get_first_page) do
98
+ subject.get_pages(space).first.id.should_not be_nil
99
+ end
81
100
  end
82
101
  end
83
- describe '#get_children' do
84
- before (:each) do
85
- subject.client.should_receive(:call)
86
- .with(:get_children, message: {in0: 'token', in1: 'page_id'})
87
- .and_return(double(:response, body: {get_children_response: {get_children_return: {get_children_return: []}}}))
88
- end
89
102
 
103
+ describe '#get_children' do
90
104
  it 'should return array of child pages' do
91
- subject.get_children('page_id').should == []
92
- end
93
- end
94
-
95
- describe '#store_page' do
96
- let(:page) do
97
- ConfluenceSoap::Page.from_hash({content: 'test', title: 'Testing API ', space: 'Space Name',
98
- parent_id: 'parent_id', permissions: 0})
99
- end
100
-
101
- before (:each) do
102
- subject.client.should_receive(:call)
103
- .with(:store_page, message: {in0: 'token', in1: {content: 'test', title: 'Testing API ',
104
- space: 'Space Name', parent_id: 'parent_id', permissions: 0}})
105
- .and_return(double(:response, body: {store_page_response: {store_page_return: {}}}))
106
- end
105
+ VCR.use_cassette(:get_first_page_id) do
106
+ @page_id = subject.get_pages(space).first.id
107
+ end
107
108
 
108
- it 'should store page with savon' do
109
- subject.store_page(page)
109
+ VCR.use_cassette(:get_children) do
110
+ subject.get_children(@page_id).should == []
111
+ end
110
112
  end
111
113
  end
112
114
 
113
115
  describe '#update_page' do
114
- let(:page) do
115
- ConfluenceSoap::Page.from_hash({content: 'test', title: 'Testing API ', space: 'Space Name',
116
- parent_id: 'parent_id', permissions: 0})
117
- end
118
-
119
- before (:each) do
120
- subject.client.should_receive(:call)
121
- .with(:update_page, message: {in0: 'token', in1: {content: 'test', title: 'Testing API ',
122
- space: 'Space Name', parent_id: 'parent_id', permissions: 0},
123
- in2: {minorEdit: true}})
124
- .and_return(double(:response, body: {update_page_response: {update_page_return: {}}}))
125
- end
126
-
127
116
  it 'should store page with savon' do
128
- subject.update_page(page)
117
+ ignore_request do
118
+ @page = subject.get_pages(space).first
119
+ end
120
+
121
+ VCR.use_cassette(:update_page) do
122
+ @page.content = 'my edits'
123
+ subject.update_page(@page).should be_instance_of(ConfluenceSoap::Page)
124
+ end
129
125
  end
130
126
  end
131
127
 
132
128
  describe '#search' do
133
- let(:term) { 'search term' }
134
- let(:criteria) { {item: [{key: :space_key, value: 'SpaceName'}]} }
135
- before (:each) do
136
- subject.client.should_receive(:call)
137
- .with(:search,
138
- message: {in0: 'token', in1: term, in2: criteria, in3: 20})
139
- .and_return(double(:response, body: {search_response: {search_return: {search_return: []}}}))
140
- end
141
-
142
129
  it 'should search with savon' do
143
- subject.search(term, space_key: 'SpaceName').should == []
130
+ VCR.use_cassette(:search_without_results) do
131
+ subject.search('Intridea',
132
+ {type: 'page', spaceKey: ConfluenceConfig[:space]})
133
+ .should == []
134
+ end
144
135
  end
145
136
  end
146
137
 
147
138
  describe '#add_label_by_name' do
148
- before(:each) do
149
- subject.client.should_receive(:call)
150
- .with(:add_label_by_name, message: {in0: 'token', in1: 'faq', in2: 1})
151
- .and_return(double(:response, body: {add_label_by_name_response: {add_label_by_name_return: true}}))
152
- end
153
-
154
139
  it 'should add a label to the page' do
155
- subject.add_label_by_name('faq', 1).should == true
140
+ ignore_request do
141
+ page_id = subject.get_pages(space).first.id
142
+
143
+ subject.add_label_by_name('faq', page_id).should == true
144
+ end
156
145
  end
157
146
  end
158
147
 
159
148
  describe '#remove_label_by_name' do
160
- before(:each) do
161
- subject.client.should_receive(:call)
162
- .with(:remove_label_by_name, message: {in0: 'token', in1: 'faq', in2: 1})
163
- .and_return(double(:response, body: {remove_label_by_name_response: {remove_label_by_name_return: true}}))
164
- end
165
-
166
149
  it 'should remove a label from the page' do
167
- subject.remove_label_by_name('faq', 1).should == true
150
+ ignore_request do
151
+ page_id = subject.get_pages(space).first.id
152
+
153
+ subject.remove_label_by_name('faq', page_id).should == true
154
+ end
168
155
  end
169
156
  end
170
157
 
171
- describe '#execute' do
172
- before (:each) do
173
- subject.should_receive(:login)
174
- end
158
+ describe '#remove_page' do
159
+ it 'should remove the page' do
160
+ ignore_request do
161
+ page_id = subject.get_pages(space).first.id
175
162
 
176
- it 'should reconnect when session is invalid' do
177
- Savon::SOAPFault.any_instance.stub(:to_hash).and_return({fault: {faultstring: 'InvalidSessionException'}})
178
- ex = Savon::SOAPFault.new nil, nil
179
- subject.execute do |x|
180
- raise ex if x.is_a? ConfluenceSoap
163
+ subject.remove_page(page_id).should == true
181
164
  end
182
165
  end
183
166
  end
data/spec/spec_helper.rb CHANGED
@@ -2,11 +2,53 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'confluence-soap'
5
+ require 'vcr'
5
6
 
6
7
  # Requires supporting files with custom matchers and macros, etc,
7
8
  # in ./support/ and its subdirectories.
8
9
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
10
 
11
+ ConfluenceConfig = YAML.load(File.read("config/confluence.yml"))
12
+
10
13
  RSpec.configure do |config|
11
-
14
+ config.before(:suite) do
15
+ ignore_request { delete_all_pages_in_test_space }
16
+ end
17
+ end
18
+
19
+ VCR.configure do |c|
20
+ c.cassette_library_dir = 'spec/support/vcr_cassettes'
21
+ c.hook_into :webmock # or :fakeweb
22
+ end
23
+
24
+ def delete_all_pages_in_test_space
25
+ client = Savon.client(wsdl: ConfluenceConfig[:url], log: false) do
26
+ convert_request_keys_to :lower_camelcase
27
+ end
28
+ token = client.call(:login, message: {
29
+ in0: ConfluenceConfig[:user],
30
+ in1: ConfluenceConfig[:password]
31
+ }).body[:login_response][:login_return]
32
+ pages = client.call(:get_pages, message: {
33
+ in0: token,
34
+ in1: ConfluenceConfig[:space]
35
+ })
36
+ pages =
37
+ pages.body[:get_pages_response][:get_pages_return][:get_pages_return] || []
38
+ pages = pages.respond_to?(:to_hash) ? [pages] : pages
39
+
40
+ pages.each do |page|
41
+ client.call(:remove_page, message: {in0: token, in1: page[:id]})
42
+ end
43
+ end
44
+
45
+ # @note https://github.com/vcr/vcr/issues/181#issuecomment-7016463
46
+ def ignore_request
47
+ VCR.turned_off do
48
+ WebMock.allow_net_connect!
49
+
50
+ yield
51
+
52
+ WebMock.disable_net_connect!
53
+ end
12
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confluence-soap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ping Yu
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-29 00:00:00.000000000 Z
12
+ date: 2014-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: 2.3.3
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: 2.3.3
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -67,6 +67,62 @@ dependencies:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  version: '3.12'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry-debugger
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry-stack_explorer
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: yard
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: redcarpet
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
70
126
  description: ''
71
127
  email:
72
128
  - ping@intridea.com
@@ -86,6 +142,7 @@ files:
86
142
  - README.md
87
143
  - Rakefile
88
144
  - VERSION
145
+ - config/confluence.yml.example
89
146
  - confluence-soap.gemspec
90
147
  - lib/confluence-soap.rb
91
148
  - spec/confluence-soap_spec.rb
@@ -115,3 +172,4 @@ signing_key:
115
172
  specification_version: 4
116
173
  summary: ruby client for confluence soap API
117
174
  test_files: []
175
+ has_rdoc: