ecircle 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -1
- data/README.md +13 -1
- data/ecircle.gemspec +1 -0
- data/lib/ecircle.rb +2 -0
- data/lib/ecircle/api.rb +44 -18
- data/lib/ecircle/version.rb +1 -1
- data/lib/ecircle/wrapped_response.rb +5 -1
- data/spec/api_spec.rb +98 -0
- data/spec/spec_helper.rb +17 -0
- metadata +30 -18
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ecircle (0.1.
|
4
|
+
ecircle (0.1.2)
|
5
5
|
activesupport
|
6
6
|
i18n
|
7
7
|
rake
|
@@ -30,6 +30,7 @@ GEM
|
|
30
30
|
nori (1.0.2)
|
31
31
|
rack (1.3.5)
|
32
32
|
rake (0.9.2.2)
|
33
|
+
random_data (1.5.2)
|
33
34
|
rspec (2.6.0)
|
34
35
|
rspec-core (~> 2.6.0)
|
35
36
|
rspec-expectations (~> 2.6.0)
|
@@ -65,6 +66,7 @@ PLATFORMS
|
|
65
66
|
|
66
67
|
DEPENDENCIES
|
67
68
|
ecircle!
|
69
|
+
random_data (= 1.5.2)
|
68
70
|
rspec (= 2.6.0)
|
69
71
|
ruby-debug19
|
70
72
|
yard
|
data/README.md
CHANGED
@@ -146,7 +146,7 @@ To do
|
|
146
146
|
* deleteUser
|
147
147
|
* deleteUserByEmail
|
148
148
|
* lookupGroups
|
149
|
-
*
|
149
|
+
* Add more functional specs
|
150
150
|
|
151
151
|
Logon
|
152
152
|
-------------
|
@@ -154,6 +154,18 @@ Logon
|
|
154
154
|
The ecircle gem does the session handling for you, there is no need to logon explicitly.
|
155
155
|
Session tokens will be re-used to keep the number of session related traffic to a minimum.
|
156
156
|
|
157
|
+
Running the specs
|
158
|
+
-------------
|
159
|
+
In order to run the functional specs you need to fill in the configuration values at the top of spec/api_spec.rb.disabled
|
160
|
+
with your ecircle account data and then rename spec/api_spec.rb.disabled to spec/api_spec.rb.
|
161
|
+
|
162
|
+
Currently you need to clean up created groups and members manually afterwards (yes, I know that sucks) since
|
163
|
+
ecircle doesn't offer a test api so all tests are going against the live API.
|
164
|
+
Without a test API I figured it's too dangerous to execute destructive actions like delete_group so the only actions
|
165
|
+
which are actually tested are non-destructive like create_or_update_user.... and so on, but never methods like delete_group.
|
166
|
+
Finding data that has been created by the tests is pretty easy, right now there is only one user with email
|
167
|
+
'apitest@apitest.com' and one or more groups whose names are 'API TEST' so you can easily find test remnants via the web interface.
|
168
|
+
|
157
169
|
Documentation
|
158
170
|
-------------
|
159
171
|
|
data/ecircle.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_dependency 'i18n'
|
23
23
|
s.add_dependency 'rake'
|
24
24
|
s.add_dependency 'savon', '>=0.9.7'
|
25
|
+
s.add_development_dependency 'random_data', '1.5.2'
|
25
26
|
s.add_development_dependency 'rspec', '2.6.0'
|
26
27
|
s.add_development_dependency 'yard'
|
27
28
|
s.add_development_dependency 'ruby-debug19'
|
data/lib/ecircle.rb
CHANGED
data/lib/ecircle/api.rb
CHANGED
@@ -15,15 +15,33 @@ module Ecircle
|
|
15
15
|
#@private
|
16
16
|
def ensuring_logon &block
|
17
17
|
begin
|
18
|
-
@auth_token
|
19
|
-
block.call
|
18
|
+
@auth_token ||= logon
|
20
19
|
rescue Savon::SOAP::Fault => e
|
21
|
-
# If we are here this
|
20
|
+
# If we are here this means that our login credentials are wrong.
|
22
21
|
wrapped_response = WrappedResponse.new(e)
|
23
|
-
if wrapped_response.permission_problem?
|
22
|
+
if wrapped_response.not_authenticated? || wrapped_response.permission_problem?
|
24
23
|
puts @@help
|
24
|
+
raise InvalidLoginCredentials
|
25
|
+
else
|
26
|
+
raise
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
first_try = true
|
31
|
+
# -> In case the session token has expired (which means 'not_authenticated') retry once.
|
32
|
+
# -> In case we can't get a token on second there's nothing we can do, so give up.
|
33
|
+
# -> In all other cases (regardless if success? is true or false) return the response.
|
34
|
+
loop do
|
35
|
+
wrapped_response = block.call
|
36
|
+
if first_try && wrapped_response.not_authenticated?
|
37
|
+
first_try = false
|
38
|
+
@auth_token = logon
|
39
|
+
elsif wrapped_response.not_authenticated?
|
40
|
+
puts "!!! Could not re-authenticate after session expired: #{wrapped_response.inspect} !!!"
|
41
|
+
raise
|
42
|
+
else
|
43
|
+
return wrapped_response
|
25
44
|
end
|
26
|
-
raise
|
27
45
|
end
|
28
46
|
end
|
29
47
|
|
@@ -56,9 +74,11 @@ module Ecircle
|
|
56
74
|
}
|
57
75
|
end
|
58
76
|
rescue Savon::SOAP::Fault => e
|
59
|
-
|
77
|
+
WrappedResponse.new(e)
|
78
|
+
else
|
79
|
+
WrappedResponse.new :success => true,
|
80
|
+
:ecircle_id => @response.body[:create_member_response][:create_member_return].to_s
|
60
81
|
end
|
61
|
-
WrappedResponse.new :success => true, :ecircle_id => @response.body[:create_member_response][:create_member_return].to_s
|
62
82
|
end
|
63
83
|
end
|
64
84
|
|
@@ -78,9 +98,11 @@ module Ecircle
|
|
78
98
|
}
|
79
99
|
end
|
80
100
|
rescue Savon::SOAP::Fault => e
|
81
|
-
|
101
|
+
WrappedResponse.new(e)
|
102
|
+
else
|
103
|
+
WrappedResponse.new :success => true,
|
104
|
+
:ecircle_id => @response[:create_or_update_group_response][:create_or_update_group_return].to_i
|
82
105
|
end
|
83
|
-
WrappedResponse.new :success => true, :ecircle_id => @response[:create_or_update_group_response][:create_or_update_group_return].to_i
|
84
106
|
end
|
85
107
|
end
|
86
108
|
|
@@ -100,10 +122,11 @@ module Ecircle
|
|
100
122
|
}
|
101
123
|
end
|
102
124
|
rescue Savon::SOAP::Fault => e
|
103
|
-
|
125
|
+
WrappedResponse.new(e)
|
126
|
+
else
|
127
|
+
WrappedResponse.new :success => true,
|
128
|
+
:ecircle_id => @response.body[:create_or_update_user_by_email_response][:create_or_update_user_by_email_return].to_i
|
104
129
|
end
|
105
|
-
WrappedResponse.new :success => true,
|
106
|
-
:ecircle_id => @response.body[:create_or_update_user_by_email_response][:create_or_update_user_by_email_return].to_i
|
107
130
|
end
|
108
131
|
end
|
109
132
|
|
@@ -121,10 +144,11 @@ module Ecircle
|
|
121
144
|
}
|
122
145
|
end
|
123
146
|
rescue Savon::SOAP::Fault => e
|
124
|
-
|
147
|
+
WrappedResponse.new(e)
|
148
|
+
else
|
149
|
+
WrappedResponse.new(:success => true)
|
125
150
|
end
|
126
151
|
end
|
127
|
-
WrappedResponse.new(:success => true)
|
128
152
|
end
|
129
153
|
|
130
154
|
# Delete a member.
|
@@ -141,10 +165,11 @@ module Ecircle
|
|
141
165
|
}
|
142
166
|
end
|
143
167
|
rescue Savon::SOAP::Fault => e
|
144
|
-
|
168
|
+
WrappedResponse.new(e)
|
169
|
+
else
|
170
|
+
WrappedResponse.new(:success => true)
|
145
171
|
end
|
146
172
|
end
|
147
|
-
WrappedResponse.new(:success => true)
|
148
173
|
end
|
149
174
|
|
150
175
|
# Logon. You don't need to call this explicitly but it's useful for debugging.
|
@@ -193,10 +218,11 @@ module Ecircle
|
|
193
218
|
}
|
194
219
|
end
|
195
220
|
rescue Savon::SOAP::Fault => e
|
196
|
-
|
221
|
+
WrappedResponse.new(e)
|
222
|
+
else
|
223
|
+
WrappedResponse.new(:success => true)
|
197
224
|
end
|
198
225
|
end
|
199
|
-
WrappedResponse.new(:success => true)
|
200
226
|
end
|
201
227
|
end
|
202
228
|
end
|
data/lib/ecircle/version.rb
CHANGED
@@ -42,11 +42,15 @@ module Ecircle
|
|
42
42
|
end
|
43
43
|
alias :no_such_group? :permission_problem?
|
44
44
|
|
45
|
+
def not_authenticated?
|
46
|
+
@fault_code == 501 && @error_message == 'Not authenticated'
|
47
|
+
end
|
48
|
+
|
45
49
|
# This method will tell you if you referred to a message id that ecircle doesn't know about.
|
46
50
|
# Usefull for send_parametrized_message_to_user requests.
|
47
51
|
# @return[Boolean]
|
48
52
|
def message_id_does_not_exist?
|
49
|
-
@error_message =~ /MessageInfo '(\d+)' not found/
|
53
|
+
!!(@error_message =~ /MessageInfo '(\d+)' not found/)
|
50
54
|
end
|
51
55
|
|
52
56
|
def success?
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ecircle::Api do
|
4
|
+
#IMPORTANT:
|
5
|
+
#In order to run the functional specs you need to fill in the configuration values at the top of spec/api_spec.rb.disabled
|
6
|
+
#with your ecircle account data and then rename spec/api_spec.rb.disabled to spec/api_spec.rb.
|
7
|
+
#
|
8
|
+
#Currently you need to clean up created groups and members manually afterwards (yes, I know that sucks) since
|
9
|
+
#ecircle doesn't offer a test api so all tests are going against the live API.
|
10
|
+
#Without a test API I figured it's too dangerous to execute destructive actions like delete_group so the only actions
|
11
|
+
#which are actually tested are non-destructive like create_or_update_user.... and so on, but never methods like delete_group.
|
12
|
+
#Finding data that has been created by the tests is pretty easy, right now there is only one user with email
|
13
|
+
#'apitest@apitest.com' and one or more groups whose names are 'API TEST' so you can easily find test remnants via the web interface.
|
14
|
+
# TODO Add more edge cases where things can go wrong, e.g. create_or_update_user with an invalid email etc.
|
15
|
+
before :each do
|
16
|
+
Ecircle.configure do |config|
|
17
|
+
config.user = ''
|
18
|
+
config.sync_realm = ''
|
19
|
+
config.password = ''
|
20
|
+
end
|
21
|
+
@email_suffix = '' # This MUST be your ecircle domain e.g. 'newsletter.your.company.com'
|
22
|
+
# You need to create this message before in the webinterface, there's no way of doing this automatically.
|
23
|
+
@test_message_id = '1200095137'
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'ensuring_logon' do
|
27
|
+
context 'wrong credentials' do
|
28
|
+
it 'should immediately raise an exception' do
|
29
|
+
Ecircle.configuration.password = 'invalid'
|
30
|
+
expect do
|
31
|
+
dummy_proc = Proc.new {}
|
32
|
+
Ecircle.api.ensuring_logon &dummy_proc
|
33
|
+
end.to raise_error(Ecircle::InvalidLoginCredentials)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'stale session token' do
|
37
|
+
it 'should retry exactly once to obtain a new token' do
|
38
|
+
response = Ecircle::WrappedResponse.new :success => false
|
39
|
+
response.stub(:not_authenticated?).and_return(true)
|
40
|
+
dummy_proc = Proc.new { response }
|
41
|
+
expect do
|
42
|
+
Ecircle.api.ensuring_logon &dummy_proc
|
43
|
+
end.to raise_error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'create_or_update_group' do
|
50
|
+
it 'should return the ecircle id' do
|
51
|
+
group_attributes = { :name => 'API TEST',
|
52
|
+
:description => 'API TEST',
|
53
|
+
:email => random_group_email(@email_suffix) }
|
54
|
+
res = Ecircle.create_or_update_group group_attributes
|
55
|
+
res.success?.should be_true
|
56
|
+
res.ecircle_id.to_s.should =~ /\d+/
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'create_member' do
|
61
|
+
it 'should create a member' do
|
62
|
+
group_id = create_random_group @email_suffix
|
63
|
+
user_id = test_user_id
|
64
|
+
res = Ecircle.create_member user_id, group_id
|
65
|
+
res.success?.should be_true
|
66
|
+
res.ecircle_id.to_s.should =~ /\d+/
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'create_or_update_user_by_email' do
|
71
|
+
it 'should return the ecircle id' do
|
72
|
+
res = Ecircle.create_or_update_user_by_email :email => 'apitest@apitest.com'
|
73
|
+
res.success?.should be_true
|
74
|
+
res.ecircle_id.to_s.should =~ /\d+/
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe 'delete_group' do
|
79
|
+
# TODO Implement but ONLY once ecircle provides a test API.
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'delete_member' do
|
83
|
+
# TODO Implement but ONLY once ecircle provides a test API.
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'send_parametrized_single_message_to_user' do
|
87
|
+
it 'should return success' do
|
88
|
+
res = Ecircle.send_parametrized_single_message_to_user test_user_id, @test_message_id
|
89
|
+
res.success?.should be_true
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should return a corresponding error message if the template does not exist' do
|
93
|
+
res = Ecircle.send_parametrized_single_message_to_user test_user_id, Random.number(10000)
|
94
|
+
res.success?.should be_false
|
95
|
+
res.message_id_does_not_exist?.should be_true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,19 @@
|
|
1
1
|
dir = File.dirname(__FILE__)
|
2
2
|
require File.join(dir, '..', 'lib', 'ecircle')
|
3
|
+
|
4
|
+
require 'random_data'
|
5
|
+
|
6
|
+
def random_group_email suffix
|
7
|
+
"apitest#{Random.number(100000)}@#{suffix}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_random_group suffix
|
11
|
+
group_attributes = { :name => 'API TEST',
|
12
|
+
:description => 'API TEST',
|
13
|
+
:email => random_group_email(suffix) }
|
14
|
+
@ecircle_group_id ||= Ecircle.create_or_update_group(group_attributes).ecircle_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_user_id
|
18
|
+
@ecircle_user_id ||= Ecircle.create_or_update_user_by_email(:email => 'apitest@apitest.com').ecircle_id
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecircle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &85674020 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *85674020
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: i18n
|
27
|
-
requirement: &
|
27
|
+
requirement: &85673810 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *85673810
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &85673600 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *85673600
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: savon
|
49
|
-
requirement: &
|
49
|
+
requirement: &85673350 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,21 @@ dependencies:
|
|
54
54
|
version: 0.9.7
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *85673350
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: random_data
|
60
|
+
requirement: &85673080 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - =
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.5.2
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *85673080
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rspec
|
60
|
-
requirement: &
|
71
|
+
requirement: &85672810 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - =
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 2.6.0
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *85672810
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: yard
|
71
|
-
requirement: &
|
82
|
+
requirement: &85672580 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *85672580
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: ruby-debug19
|
82
|
-
requirement: &
|
93
|
+
requirement: &85636880 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,7 +98,7 @@ dependencies:
|
|
87
98
|
version: '0'
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *85636880
|
91
102
|
description: The ecircle gem aims to be a full-fledged client for all ecircle services.
|
92
103
|
email:
|
93
104
|
- timo.roessner@googlemail.com
|
@@ -111,6 +122,7 @@ files:
|
|
111
122
|
- lib/ecircle/job_package.rb
|
112
123
|
- lib/ecircle/version.rb
|
113
124
|
- lib/ecircle/wrapped_response.rb
|
125
|
+
- spec/api_spec.rb
|
114
126
|
- spec/job_package_spec.rb
|
115
127
|
- spec/spec_helper.rb
|
116
128
|
homepage: ''
|
@@ -127,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
139
|
version: '0'
|
128
140
|
segments:
|
129
141
|
- 0
|
130
|
-
hash:
|
142
|
+
hash: 207876449
|
131
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
144
|
none: false
|
133
145
|
requirements:
|
@@ -136,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
148
|
version: '0'
|
137
149
|
segments:
|
138
150
|
- 0
|
139
|
-
hash:
|
151
|
+
hash: 207876449
|
140
152
|
requirements: []
|
141
153
|
rubyforge_project: ecircle
|
142
154
|
rubygems_version: 1.8.10
|