ecircle 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ecircle (0.0.7)
4
+ ecircle (0.0.8)
5
5
  activesupport
6
6
  i18n
7
7
  rake
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ Travis Build Status
2
+ -------------
3
+
1
4
  [![Build Status](https://secure.travis-ci.org/troessner/ecircle.png)](http://travis-ci.org/troessner/ecircle)
2
5
 
3
6
  Synopsis
@@ -5,30 +8,40 @@ Synopsis
5
8
 
6
9
  This gem aims to be a full-fledged solution for the ecircle API, the [synchronous one](http://webservices.ecircle-ag.com/soap/javadoc/com/ecircleag/webservices/EcMApi.html) and the [asynchronous one](http://developer.ecircle-ag.com/apiwiki/wiki/AsynchronousAPI).
7
10
 
8
- The API coverage is far from complete.
11
+ The API coverage is far from complete, however as far as I can see the most useful / frequent methods are covered.
9
12
 
10
- However, the existing API coverage can be considered stable and is used in production.
13
+ The existing API methods can be considered stable and are used in production.
11
14
 
12
15
  Features
13
16
  -------------
14
17
 
15
- So far just a couple of methods:
18
+ ###Synchronous API
19
+
20
+ The following methods are implemented:
21
+
22
+ * createMember
23
+ * createOrUpdateUserByEmail
24
+ * deleteGroup
25
+ * deleteMember
26
+ * logon (only for debugging purposes)
27
+ * logout
28
+ * sendParametrizedSingleMessageToUser
29
+
30
+ See the [online API documentation](http://rubydoc.info/github/troessner/ecircle/master/frames) for details on arguments and return values
16
31
 
17
- * create_member
18
- * create_or_update_user_by_email
19
- * delete_member
20
- * send_parametrized_single_message_to_user
32
+ ###Asnchronous API
21
33
 
22
- See the rdoc for details on arguments and return values: [TODO Add link]
34
+ Since the asynchronous API is neither documented by ecircle nor intuitive at all, you're on your own. Jump to the examples section and good luck.
23
35
 
24
36
  To do
25
37
  -------------
26
38
 
27
- * Rethink current structure
28
- * Implement missing API methods
29
- * Specs
30
- * RDoc
31
- * Remove JobPackage from gem since this is highly specific
39
+ * Implement missing API methods:
40
+ * createOrUpdateGroup
41
+ * deleteUser
42
+ * deleteUserByEmail
43
+ * lookupGroups
44
+ * Write specs
32
45
 
33
46
  Configuration
34
47
  -------------
@@ -53,6 +66,8 @@ Session tokens will be re-used to keep the number of session related traffic to
53
66
  Examples
54
67
  -------------
55
68
 
69
+ ### Synchronous API
70
+
56
71
  ```Ruby
57
72
  # Given you have called Ecircle.configure appropriatly...
58
73
 
@@ -73,4 +88,39 @@ Ecircle.send_parametrized_single_message_to_user uid,
73
88
  [ :name, :message ],
74
89
  [ 'Tom', 'welcome!' ]
75
90
 
76
- ```
91
+ # 5.) Delete the group
92
+ Ecircle.delete_group your_group_id
93
+
94
+ # 6.) Log out
95
+ Ecircle.logout
96
+
97
+ ```
98
+ ### Asynchronous API
99
+
100
+ ```Ruby
101
+ Ecircle.configure do |config|
102
+ config.user = 'your@user.com'
103
+ config.async_realm = 'http://your.async.realm.com' # IMPORTANT - different realm.
104
+ config.password = 'your_password'
105
+ end
106
+
107
+ @options = {
108
+ :endpoint => 'http://your.domain/eC-MessageService',
109
+ :request_id => '1234',
110
+ :group_id => '5678',
111
+ :send_out_date => 70.minutes.from_now, # Must be at least one hour in the future!
112
+ :send_date_for_report => 140.minutes.from_now, # Must be at least one hour in the future *after* dispatching!
113
+ :report_email => 'your@report.de',
114
+ :report_email_name => 'Your name',
115
+ :subject => 'Newsletter',
116
+ :text => 'Newsletter text content',
117
+ :html => 'Newsletter html content'
118
+ }
119
+
120
+ Ecircle::JobPackage.send_async_message_to_group @options
121
+ ```
122
+
123
+ Documentation
124
+ -------------
125
+
126
+ * [Online API Documentation](http://rubydoc.info/github/troessner/ecircle/master/frames)
data/lib/ecircle.rb CHANGED
@@ -10,7 +10,7 @@ require 'savon'
10
10
 
11
11
  dir = File.dirname(__FILE__)
12
12
 
13
- %w!version configuration client helper job_package!.each do |file|
13
+ %w!api version configuration helper job_package wrapped_response!.each do |file|
14
14
  require File.join(dir, 'ecircle', file)
15
15
  end
16
16
 
@@ -23,8 +23,8 @@ module Ecircle
23
23
  end
24
24
 
25
25
  #@private
26
- def client
27
- @client ||= Client.new
26
+ def api
27
+ @api ||= Api.new
28
28
  end
29
29
 
30
30
  #@private
@@ -33,9 +33,9 @@ module Ecircle
33
33
  end
34
34
  end
35
35
 
36
- (Ecircle::Client.instance_methods(false) - [:client]).each do |meth|
36
+ (Ecircle::Api.instance_methods(false) - [:client]).each do |meth|
37
37
  define_singleton_method meth do |*args|
38
- client.send meth, *args
38
+ api.send meth, *args
39
39
  end
40
40
  end
41
41
  end
@@ -0,0 +1,209 @@
1
+ module Ecircle
2
+ class Api
3
+ #@private
4
+ attr_accessor :auth_token
5
+ @@help = <<-doc
6
+ !!!
7
+ Got an authentication exception, chances are good that you're credentials are wrong, so better double check that.
8
+ You can explicitly check for it by calling something like:
9
+ Ecircle.configure do..
10
+ Ecircle.logon
11
+ !!!
12
+ doc
13
+
14
+
15
+ #@private
16
+ def ensuring_logon &block
17
+ begin
18
+ @auth_token ||= logon
19
+ rescue Savon::SOAP::Fault => e
20
+ # If we are here this probably means that our login credentials are wrong.
21
+ wrapped_response = WrappedResponse.new(e)
22
+ if wrapped_response.permission_problem?
23
+ puts @@help
24
+ raise
25
+ end
26
+ end
27
+
28
+ first_try = true
29
+ begin
30
+ block.call
31
+ rescue Savon::SOAP::Fault => e
32
+ # If we are here that probably means that our session token has expired.
33
+ wrapped_response = WrappedResponse.new(e)
34
+ if wrapped_response.permission_problem?
35
+ if first_try
36
+ first_try = false
37
+ @auth_token = logon
38
+ retry
39
+ else
40
+ puts "!!! Could not re-authenticate after session expired: #{wrapped_response.inspect} !!!"
41
+ raise
42
+ end
43
+ else
44
+ raise # Re-raise cause something else went wrong.
45
+ end
46
+ end
47
+ end
48
+
49
+ # @private
50
+ def client
51
+ @client ||= Savon::Client.new do
52
+ wsdl.document = Ecircle.configuration.wsdl
53
+ wsdl.endpoint = Ecircle.configuration.endpoint
54
+ wsdl.namespace = Ecircle.configuration.namespace
55
+ end
56
+ end
57
+
58
+ # Creates a member, which basically is just an association between a user and a group.
59
+ #
60
+ # @param [Integer] user_id ecircle user_id
61
+ # @param [Integer] group_id ecircle group_id
62
+ # @param [Boolean] invite send an invite by ecircle
63
+ # @param [Boolean] send_message send a message by ecircle
64
+ # @return [WrappedResponse]
65
+ def create_member user_id, group_id, invite = false, send_message = false
66
+ ensuring_logon do
67
+ begin
68
+ @response = client.request :createMember do
69
+ soap.body = {
70
+ :session => auth_token,
71
+ :userId => user_id,
72
+ :groupId => group_id,
73
+ :invite => invite.to_s,
74
+ :sendMessage => send_message.to_s
75
+ }
76
+ end
77
+ rescue Savon::SOAP::Fault => e
78
+ wrapped_response = WrappedResponse.new(e)
79
+ if wrapped_response.no_such_user? || wrapped_response.no_such_group_when_a_user_was_given
80
+ return wrapped_response
81
+ else
82
+ raise # Re-raise cause something else went wrong.
83
+ end
84
+ end
85
+ WrappedResponse.new(:success => true, :ecircle_id => @response.body[:create_member_response][:create_member_return].to_s)
86
+ end
87
+ end
88
+
89
+ # Create or update user by email
90
+ # see http://developer.ecircle-ag.com/apiwiki/wiki/SynchronousSoapAPI#section-SynchronousSoapAPI-UserObjectExample
91
+ # for an example of the user xml
92
+ # @param [Hash] user_xml, in it's most simple form a { :email => 'test@test.com' } is sufficient
93
+ # @return [Integer] the user id
94
+ # TODO Error handling is missing.
95
+ def create_or_update_user_by_email user_attributes
96
+ ensuring_logon do
97
+ @response = client.request :createOrUpdateUserByEmail do
98
+ soap.body = {
99
+ :session => auth_token, # TODO We can't use @auth_token here cause then the session_id is nil. Why?
100
+ :userXml => Helper.build_user_xml(user_attributes),
101
+ :sendMessage => 0
102
+ }
103
+ end
104
+ @response.body[:create_or_update_user_by_email_response][:create_or_update_user_by_email_return].to_i
105
+ end
106
+ end
107
+
108
+ # Delete a member.
109
+ #
110
+ # @param [Integer] group_id ecircle group id
111
+ # @return [WrappedResponse]
112
+ def delete_group group_id
113
+ ensuring_logon do
114
+ begin
115
+ @response = client.request :deleteGroup do
116
+ soap.body = {
117
+ :session => auth_token,
118
+ :memberId => group_id
119
+ }
120
+ end
121
+ rescue Savon::SOAP::Fault => e
122
+ wrapped_response = WrappedResponse.new(e)
123
+ if wrapped_response.group_does_not_exist?
124
+ return wrapped_response
125
+ else
126
+ raise # Re-raise cause something else went wrong.
127
+ end
128
+ end
129
+ end
130
+ WrappedResponse.new(:success => true)
131
+ end
132
+
133
+ # Delete a member.
134
+ #
135
+ # @param [Integer] member_id ecircle member id
136
+ # @return [WrappedResponse]
137
+ def delete_member member_id
138
+ ensuring_logon do
139
+ begin
140
+ @response = client.request :deleteMember do
141
+ soap.body = {
142
+ :session => auth_token,
143
+ :memberId => member_id
144
+ }
145
+ end
146
+ rescue Savon::SOAP::Fault => e
147
+ wrapped_response = WrappedResponse.new(e)
148
+ if wrapped_response.member_does_not_exist?
149
+ return wrapped_response
150
+ else
151
+ raise # Re-raise cause something else went wrong.
152
+ end
153
+ end
154
+ end
155
+ WrappedResponse.new(:success => true)
156
+ end
157
+
158
+ # Logon. You don't need to call this explicitly but it's useful for debugging.
159
+ #
160
+ # @return [String] the session id
161
+ def logon
162
+ @response = client.request :logon do
163
+ soap.body = {
164
+ :user => Ecircle.configuration.user,
165
+ :realm => Ecircle.configuration.sync_realm,
166
+ :passwd => Ecircle.configuration.password
167
+ }
168
+ end
169
+ @response.body[:logon_response][:logon_return].to_s
170
+ end
171
+
172
+ # Log out. Uses the last session token.
173
+ #
174
+ # @return nil
175
+ def logout
176
+ client.request :logout do
177
+ soap.body = {
178
+ :session => auth_token,
179
+ }
180
+ end
181
+ end
182
+
183
+ # Send a parametrized single message to user - you need an existing ecircle template ID for this.
184
+ #
185
+ # @param [Integer] user_id ecircle user_id
186
+ # @param [Integer] message_id the ecircle template ID
187
+ # @param [Array] the names of the variables you want to interpolate in the template
188
+ # @param [Array] the values of the variables you want to interpolate in the template
189
+ # @return [WrappedResponse]
190
+ def send_parametrized_single_message_to_user user_id, message_id, names = [], values = []
191
+ ensuring_logon do
192
+ begin
193
+ @response = client.request :sendParametrizedSingleMessageToUser do
194
+ soap.body = {
195
+ :session => auth_token,
196
+ :singleMessageId => message_id,
197
+ :userId => user_id,
198
+ :names => names,
199
+ :values => values
200
+ }
201
+ end
202
+ rescue Savon::SOAP::Fault => e
203
+ return WrappedResponse.new(e)
204
+ end
205
+ end
206
+ WrappedResponse.new(:success => true)
207
+ end
208
+ end
209
+ end
@@ -8,5 +8,12 @@ module Ecircle
8
8
  matcher = /(.*)(00)/.match(tz) # We need to do that because ecircle won't accept +0200, just +02:00.
9
9
  "#{date.strftime('%Y-%m-%dT%H:%M:%S')}#{matcher[1]}:#{matcher[2]}"
10
10
  end
11
+
12
+ def build_user_xml attributes
13
+ '<user>' + attributes.each_with_object('') do |slice, xml|
14
+ name, value = slice.first, slice.last;
15
+ xml << "<#{name}>#{value}</#{name}>"
16
+ end+'</user>'
17
+ end
11
18
  end
12
19
  end
@@ -9,7 +9,7 @@ module Ecircle
9
9
  wsdl.namespace = "http://webservices.ecircleag.com/ws"
10
10
  end
11
11
 
12
- response = client.request :postGroupRequest, 'xmlns' => 'http://webservices.ecircle-ag.com/ws' do
12
+ client.request :postGroupRequest, 'xmlns' => 'http://webservices.ecircle-ag.com/ws' do
13
13
  soap.header = { :authenticate => { :realm => Ecircle.configuration.async_realm,
14
14
  :email => Ecircle.configuration.user,
15
15
  :password => Ecircle.configuration.password },
@@ -33,14 +33,14 @@ module Ecircle
33
33
  xml.tag! 'send-report-address' do
34
34
  xml.tag! 'email-address' do
35
35
  xml.email options[:report_email]
36
- xml.name "Send report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
36
+ xml.name options[:report_email_name]
37
37
  end
38
38
  end
39
39
  xml.tag! 'status-report', 'report-id' => 'new', 'delete' => 'false', 'user-tracking-details' => 'false', 'link-tracking-details' => 'false', 'bouncing-details' => 'false' do
40
40
  xml.tag! 'report-address' do
41
41
  xml.tag! 'email-address' do
42
42
  xml.email options[:report_email]
43
- xml.name "Status report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
43
+ xml.name options[:report_email_name]
44
44
  end
45
45
  end
46
46
  xml.tag! 'send-date' do
@@ -56,13 +56,13 @@ module Ecircle
56
56
  xml.tag! 'success-report-address' do
57
57
  xml.tag! 'email-address' do
58
58
  xml.email options[:report_email]
59
- xml.name "Success report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
59
+ xml.name options[:report_email_name]
60
60
  end
61
61
  end
62
62
  xml.tag! 'failure-report-address' do
63
63
  xml.tag! 'email-address' do
64
64
  xml.email options[:report_email]
65
- xml.name "Failure report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
65
+ xml.name options[:report_email_name]
66
66
  end
67
67
  end
68
68
  end
@@ -1,3 +1,3 @@
1
1
  module Ecircle
2
- VERSION = "0.0.7"
2
+ VERSION = '0.0.8'
3
3
  end
@@ -0,0 +1,50 @@
1
+ module Ecircle
2
+ class WrappedResponse
3
+ #@private
4
+ attr_accessor :success, :error_message, :fault_code, :ecircle_id
5
+
6
+ # We create a wrapped response in 2 cases:
7
+ # 1.) We get a Savon::SOAP::Fault exception, so something went wrong. In this we get passed an exception.
8
+ # 2.) We get back a "regular" response. In this we get passed an hash.
9
+ def initialize options_or_exception
10
+ if options_or_exception.kind_of? Exception
11
+ attributes = options_or_exception.to_hash
12
+ @success = false
13
+ @error_message = attributes[:fault][:detail][:fault][:error_message]
14
+ @fault_code = attributes[:fault][:detail][:fault][:code].to_i
15
+ elsif options_or_exception.kind_of? Hash
16
+ @success = options_or_exception[:success]
17
+ @error_message = options_or_exception[:error_message]
18
+ @fault_code = options_or_exception[:fault_code] ? options_or_exception[:fault_code].to_i : nil
19
+ @ecircle_id = options_or_exception[:ecircle_id]
20
+ else
21
+ raise ArgumentError, "!!! Was either expecting a hash or an exception but got: #{options_or_exception.class} !!!"
22
+ end
23
+ end
24
+
25
+ def member_does_not_exist?
26
+ @fault_code == 100
27
+ end
28
+
29
+ def group_does_not_exist?
30
+ @fault_code == 500
31
+ end
32
+
33
+ def no_such_user?
34
+ @fault_code == 500
35
+ end
36
+
37
+ def permission_problem?
38
+ @fault_code == 502 && @error_message = 'Permission Problem'
39
+ end
40
+
41
+ def no_such_group_when_a_user_was_given?
42
+ # YES, this IS horrible. Thanks ecircle. "Group does not exist" error codes vary depending on context.
43
+ @fault_code == 502 && @error_message = 'Permission Problem'
44
+ end
45
+
46
+ def success?
47
+ @success
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -1,100 +1,105 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ecircle
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.7
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.0.8
6
6
  platform: ruby
7
- authors:
8
- - Timo Rößner
7
+ authors:
8
+ - "Timo R\xC3\xB6\xC3\x9Fner"
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-02 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2011-11-09 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
15
17
  name: activesupport
16
- requirement: &69598750 !ruby/object:Gem::Requirement
18
+ requirement: &id001 !ruby/object:Gem::Requirement
17
19
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
22
24
  type: :runtime
23
25
  prerelease: false
24
- version_requirements: *69598750
25
- - !ruby/object:Gem::Dependency
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
26
28
  name: i18n
27
- requirement: &69598090 !ruby/object:Gem::Requirement
29
+ requirement: &id002 !ruby/object:Gem::Requirement
28
30
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
33
35
  type: :runtime
34
36
  prerelease: false
35
- version_requirements: *69598090
36
- - !ruby/object:Gem::Dependency
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
37
39
  name: rake
38
- requirement: &69597470 !ruby/object:Gem::Requirement
40
+ requirement: &id003 !ruby/object:Gem::Requirement
39
41
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
44
46
  type: :runtime
45
47
  prerelease: false
46
- version_requirements: *69597470
47
- - !ruby/object:Gem::Dependency
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
48
50
  name: savon
49
- requirement: &69596650 !ruby/object:Gem::Requirement
51
+ requirement: &id004 !ruby/object:Gem::Requirement
50
52
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
54
56
  version: 0.9.7
55
57
  type: :runtime
56
58
  prerelease: false
57
- version_requirements: *69596650
58
- - !ruby/object:Gem::Dependency
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
59
61
  name: rspec
60
- requirement: &69595940 !ruby/object:Gem::Requirement
62
+ requirement: &id005 !ruby/object:Gem::Requirement
61
63
  none: false
62
- requirements:
63
- - - =
64
- - !ruby/object:Gem::Version
64
+ requirements:
65
+ - - "="
66
+ - !ruby/object:Gem::Version
65
67
  version: 2.6.0
66
68
  type: :development
67
69
  prerelease: false
68
- version_requirements: *69595940
69
- - !ruby/object:Gem::Dependency
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
70
72
  name: yard
71
- requirement: &69595540 !ruby/object:Gem::Requirement
73
+ requirement: &id006 !ruby/object:Gem::Requirement
72
74
  none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
77
79
  type: :development
78
80
  prerelease: false
79
- version_requirements: *69595540
80
- - !ruby/object:Gem::Dependency
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
81
83
  name: ruby-debug19
82
- requirement: &69594720 !ruby/object:Gem::Requirement
84
+ requirement: &id007 !ruby/object:Gem::Requirement
83
85
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
88
90
  type: :development
89
91
  prerelease: false
90
- version_requirements: *69594720
92
+ version_requirements: *id007
91
93
  description: The ecircle gem aims to be a full-fledged client for all ecircle services.
92
- email:
94
+ email:
93
95
  - timo.roessner@googlemail.com
94
96
  executables: []
97
+
95
98
  extensions: []
99
+
96
100
  extra_rdoc_files: []
97
- files:
101
+
102
+ files:
98
103
  - .gitignore
99
104
  - .rvmrc
100
105
  - .travis.yml
@@ -104,42 +109,47 @@ files:
104
109
  - Rakefile
105
110
  - ecircle.gemspec
106
111
  - lib/ecircle.rb
107
- - lib/ecircle/client.rb
112
+ - lib/ecircle/api.rb
108
113
  - lib/ecircle/configuration.rb
109
114
  - lib/ecircle/helper.rb
110
115
  - lib/ecircle/job_package.rb
111
116
  - lib/ecircle/version.rb
117
+ - lib/ecircle/wrapped_response.rb
112
118
  - spec/client_spec.rb
113
119
  - spec/spec_helper.rb
114
- homepage: ''
120
+ has_rdoc: true
121
+ homepage: ""
115
122
  licenses: []
123
+
116
124
  post_install_message:
117
125
  rdoc_options: []
118
- require_paths:
126
+
127
+ require_paths:
119
128
  - lib
120
- required_ruby_version: !ruby/object:Gem::Requirement
129
+ required_ruby_version: !ruby/object:Gem::Requirement
121
130
  none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- segments:
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: -743074899
135
+ segments:
127
136
  - 0
128
- hash: -98517107
129
- required_rubygems_version: !ruby/object:Gem::Requirement
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
139
  none: false
131
- requirements:
132
- - - ! '>='
133
- - !ruby/object:Gem::Version
134
- version: '0'
135
- segments:
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: -743074899
144
+ segments:
136
145
  - 0
137
- hash: -98517107
146
+ version: "0"
138
147
  requirements: []
148
+
139
149
  rubyforge_project: ecircle
140
- rubygems_version: 1.8.10
150
+ rubygems_version: 1.6.2
141
151
  signing_key:
142
152
  specification_version: 3
143
153
  summary: Ecircle gem
144
154
  test_files: []
145
- has_rdoc:
155
+
@@ -1,164 +0,0 @@
1
- module Ecircle
2
- class Client
3
- #@private
4
- attr_accessor :auth_token
5
-
6
- #@private
7
- def ensuring_logon &block
8
- begin
9
- @auth_token ||= logon
10
- rescue Savon::SOAP::Fault => e
11
- # If we are here this probably means that our login credentials are wrong.
12
- response = e.to_hash
13
- if response[:fault][:detail][:fault][:code] == '502'
14
- help = <<-doc
15
- !!!
16
- Got an authentication exception, chances are good that you're credentials are wrong, so better double check that.
17
- You can explicitly check for it by calling something like:
18
- Ecircle.configure do..
19
- Ecircle.logon
20
- !!!
21
- doc
22
- puts help
23
- else
24
- puts "!!! Got an unexpected fault code from Savon: #{response.inspect} !!!"
25
- end
26
- raise
27
- rescue => e
28
- puts "!!! Got unexpected non-Savon exception: #{e.class} !!!"
29
- raise
30
- end
31
-
32
- first_try = true
33
- begin
34
- block.call
35
- rescue Savon::SOAP::Fault => e
36
- # If we are here that probably means that our session token has expired.
37
- if first_try
38
- first_try = false
39
- @auth_token = logon
40
- retry
41
- else
42
- puts "!!! Could not re-authenticate after session expired: #{e.to_hash.inspect} !!!"
43
- raise
44
- end
45
- end
46
- end
47
-
48
- # @private
49
- def client
50
- @client ||= Savon::Client.new do
51
- wsdl.document = Ecircle.configuration.wsdl
52
- wsdl.endpoint = Ecircle.configuration.endpoint
53
- wsdl.namespace = Ecircle.configuration.namespace
54
- end
55
- end
56
-
57
- # Creates a member, which basically is just an association between a user and a group.
58
- #
59
- # @param [Integer] user_id ecircle user_id
60
- # @param [Integer] group_id ecircle group_id
61
- # @param [Boolean] invite send an invite by ecircle
62
- # @param [Boolean] send_message send a message by ecircle
63
- # @return [String] the member id
64
- def create_member user_id, group_id, invite = false, send_message = false
65
- ensuring_logon do
66
- @response = client.request :createMember do
67
- soap.body = {
68
- :session => auth_token,
69
- :userId => user_id,
70
- :groupId => group_id,
71
- :invite => invite.to_s,
72
- :sendMessage => send_message.to_s
73
- }
74
- end
75
- @response.body[:create_member_response][:create_member_return].to_s
76
- end
77
- end
78
-
79
- # Create or update user by email
80
- # see http://developer.ecircle-ag.com/apiwiki/wiki/SynchronousSoapAPI#section-SynchronousSoapAPI-UserObjectExample
81
- # for an example of the user xml
82
- # @param [Hash] user_xml, in it's most simple form a { :email => 'test@test.com' } is sufficient
83
- # @return [Integer] the user id
84
- def create_or_update_user_by_email attributes
85
- user_xml = '<user>' + attributes.each_with_object('') do |slice, xml|
86
- name, value = slice.first, slice.last;
87
- xml << "<#{name}>#{value}</#{name}>"
88
- end+'</user>'
89
-
90
- ensuring_logon do
91
- @response = client.request :createOrUpdateUserByEmail do
92
- soap.body = {
93
- :session => auth_token, # TODO We can't use @auth_token here cause then the session_id is nil. Why?
94
- :userXml => user_xml,
95
- :sendMessage => 0
96
- }
97
- end
98
- @response.body[:create_or_update_user_by_email_response][:create_or_update_user_by_email_return].to_i
99
- end
100
- end
101
-
102
- # Delete a member.
103
- #
104
- # @param [Integer] member_id ecircle member id
105
- # @return [Boolean]
106
- def delete_member member_id
107
- ensuring_logon do
108
- # In case we pass in a non existing member id we'll get a corresponding exception, so we need to catch this here as well.
109
- begin
110
- @response = client.request :deleteMember do
111
- soap.body = {
112
- :session => auth_token,
113
- :memberId => member_id
114
- }
115
- end
116
- rescue Savon::SOAP::Fault => e
117
- if e.to_hash[:fault][:detail][:fault][:code] == '100'
118
- # "100" means member ID didn't exist so just return false.
119
- return false
120
- else
121
- # Re-raise cause something else went wrong.
122
- raise
123
- end
124
- end
125
- end
126
- true
127
- end
128
-
129
- # Logon. You don't need to call this explicitly but it's useful for debugging.
130
- #
131
- # @return [String] the session id
132
- def logon
133
- @response = client.request :logon do
134
- soap.body = {
135
- :user => Ecircle.configuration.user,
136
- :realm => Ecircle.configuration.sync_realm,
137
- :passwd => Ecircle.configuration.password
138
- }
139
- end
140
- @response.body[:logon_response][:logon_return].to_s
141
- end
142
-
143
- # Send a parametrized single message to user - you need an existing ecircle template ID for this.
144
- #
145
- # @param [Integer] user_id ecircle user_id
146
- # @param [Integer] message_id the ecircle template ID
147
- # @param [Array] the names of the variables you want to interpolate in the template
148
- # @param [Array] the values of the variables you want to interpolate in the template
149
- # @return nil
150
- def send_parametrized_single_message_to_user user_id, message_id, names = [], values = []
151
- ensuring_logon do
152
- @response = client.request :sendParametrizedSingleMessageToUser do
153
- soap.body = {
154
- :session => auth_token,
155
- :singleMessageId => message_id,
156
- :userId => user_id,
157
- :names => names,
158
- :values => values
159
- }
160
- end
161
- end
162
- end
163
- end
164
- end