ecircle 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ rvm: 1.9.2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ecircle (0.0.5)
4
+ ecircle (0.0.6)
5
5
  activesupport
6
6
  i18n
7
7
  rake
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
+ [![Build Status](https://secure.travis-ci.org/troessner/ecircle.png)](http://travis-ci.org/troessner/ecircle)
1
2
 
3
+ Synopsis
4
+ -------------
2
5
 
3
6
  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).
4
7
 
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -1,5 +1,48 @@
1
1
  module Ecircle
2
2
  class Client
3
+ attr_accessor :auth_token
4
+
5
+ def ensuring_logon &block
6
+ begin
7
+ @auth_token ||= logon
8
+ rescue Savon::SOAP::Fault => e
9
+ # If we are here this probably means that our login credentials are wrong.
10
+ response = e.to_hash
11
+ if response[:fault][:faultcode] == 'soapenv:Server.userException' && response[:fault][:detail][:fault][:code] == '502'
12
+ help = <<-doc
13
+ !!!
14
+ Got an authentication exception, chances are good that you're credentials are wrong, so better double check that.
15
+ You can explicitly check for it by calling something like:
16
+ Ecircle.configure do..
17
+ Ecircle.logon
18
+ !!!
19
+ doc
20
+ puts help
21
+ else
22
+ puts "!!! Got an unexpected fault code from Savon: #{response.inspect} !!!"
23
+ end
24
+ raise
25
+ rescue => e
26
+ puts "!!! Got unexpected non-Savon exception: #{e.class} !!!"
27
+ raise
28
+ end
29
+
30
+ first_try = true
31
+ begin
32
+ block.call
33
+ rescue Savon::SOAP::Fault => e
34
+ # If we are here that probably means that our session token has expired.
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: #{e.to_hash.inspect} !!!"
41
+ raise
42
+ end
43
+ end
44
+ end
45
+
3
46
  def client
4
47
  @client ||= Savon::Client.new do
5
48
  wsdl.document = Ecircle.configuration.wsdl
@@ -9,40 +52,43 @@ module Ecircle
9
52
  end
10
53
 
11
54
  def create_member user_id, group_id, invite = false, send_message = false
12
- session_id = logon
13
- @response = client.request :createMember do
14
- soap.body = {
15
- :session => session_id,
16
- :userId => user_id,
17
- :groupId => group_id,
18
- :invite => invite.to_s,
19
- :sendMessage => send_message.to_s
20
- }
55
+ ensuring_logon do
56
+ @response = client.request :createMember do
57
+ soap.body = {
58
+ :session => auth_token,
59
+ :userId => user_id,
60
+ :groupId => group_id,
61
+ :invite => invite.to_s,
62
+ :sendMessage => send_message.to_s
63
+ }
64
+ end
65
+ @response.body[:create_member_response][:create_member_return].to_s
21
66
  end
22
- @response.body[:create_member_response][:create_member_return].to_s
23
67
  end
24
68
 
25
69
  def create_or_update_user_by_email email
26
- session_id = logon
27
- @response = client.request :createOrUpdateUserByEmail do
28
- soap.body = {
29
- :session => session_id,
30
- :userXml => "<user><email>#{email}</email></user>",
31
- :sendMessage => 0
32
- }
70
+ ensuring_logon do
71
+ @response = client.request :createOrUpdateUserByEmail do
72
+ soap.body = {
73
+ :session => auth_token, # TODO We can't use @auth_token here cause then the session_id is nil. Why?
74
+ :userXml => "<user><email>#{email}</email></user>",
75
+ :sendMessage => 0
76
+ }
77
+ end
78
+ @response.body[:create_or_update_user_by_email_response][:create_or_update_user_by_email_return].to_s
33
79
  end
34
- @response.body[:create_or_update_user_by_email_response][:create_or_update_user_by_email_return].to_s
35
80
  end
36
81
 
37
82
  def delete_member member_id
38
- session_id = logon
39
- @response = client.request :deleteMember do
40
- soap.body = {
41
- :session => session_id,
42
- :memberId => member_id
43
- }
83
+ ensuring_logon do
84
+ @response = client.request :deleteMember do
85
+ soap.body = {
86
+ :session => auth_token,
87
+ :memberId => member_id
88
+ }
89
+ end
90
+ @response.body[:delete_member_response][:delete_member_return].to_s
44
91
  end
45
- @response.body[:delete_member_response][:delete_member_return].to_s
46
92
  end
47
93
 
48
94
  def logon
@@ -57,15 +103,16 @@ module Ecircle
57
103
  end
58
104
 
59
105
  def send_parametrized_single_message_to_user user_id, message_id, names = [], values = []
60
- session_id = logon
61
- @response = client.request :sendParametrizedSingleMessageToUser do
62
- soap.body = {
63
- :session => session_id,
64
- :singleMessageId => message_id,
65
- :userId => user_id,
66
- :names => names,
67
- :values => values
68
- }
106
+ ensuring_logon do
107
+ @response = client.request :sendParametrizedSingleMessageToUser do
108
+ soap.body = {
109
+ :session => auth_token,
110
+ :singleMessageId => message_id,
111
+ :userId => user_id,
112
+ :names => names,
113
+ :values => values
114
+ }
115
+ end
69
116
  end
70
117
  end
71
118
  end
@@ -3,7 +3,9 @@ module Ecircle
3
3
  extend self
4
4
 
5
5
  def date_format date
6
- date.strftime("%Y-%m-%dT%H:%M:%S")
6
+ tz = date.strftime('%z')
7
+ matcher = /(.*)(00)/.match(tz) # We need to do that because ecircle won't accept +0200, just +02:00.
8
+ "#{date.strftime('%Y-%m-%dT%H:%M:%S')}#{matcher[1]}:#{matcher[2]}"
7
9
  end
8
10
  end
9
11
  end
@@ -4,11 +4,11 @@ module Ecircle
4
4
 
5
5
  def self.send_async_message_to_group(options)
6
6
  client = Savon::Client.new do
7
- wsdl.endpoint = 'http://webservices.ecircle-ag.com/ws'
7
+ wsdl.endpoint = options[:endpoint]
8
8
  wsdl.namespace = "http://webservices.ecircleag.com/ws"
9
9
  end
10
10
 
11
- response = client.request :control, 'xmlns' => "http://webservices.ecircle-ag.com/ecm", 'request-id' => options[:request_id], 'group-id' => options[:group_id] do
11
+ response = client.request :postGroupRequest, 'xmlns' => 'http://webservices.ecircle-ag.com/ws' do
12
12
  soap.header = { :authenticate => { :realm => Ecircle.configuration.async_realm,
13
13
  :email => Ecircle.configuration.user,
14
14
  :password => Ecircle.configuration.password },
@@ -19,47 +19,49 @@ module Ecircle
19
19
 
20
20
  def self.soap_body(options)
21
21
  xml = Builder::XmlMarkup.new(:indent => 2)
22
- xml.message 'message-id' => 'new', 'delete' => 'false' do
23
- xml.tag! 'sendout-preferences' do
24
- xml.tag! 'object-handling', 'html-images' => 'untouched'
25
- xml.tag! 'email-channel', 'preferred-format' => 'email-html-multipart'
26
- end
27
- xml.tag! 'send-date' do
28
- xml.date Helper.date_format(options[:send_out_date])
29
- end
30
- xml.tag! 'send-report-address' do
31
- xml.tag! 'email-address' do
32
- xml.email options[:report_email]
33
- xml.name "Send report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
22
+ xml.control 'xmlns' => "http://webservices.ecircle-ag.com/ecm", 'request-id' => options[:request_id], 'group-id' => options[:group_id] do
23
+ xml.message 'message-id' => 'new', 'delete' => 'false' do
24
+ xml.tag! 'sendout-preferences' do
25
+ xml.tag! 'object-handling', 'html-images' => 'untouched'
26
+ xml.tag! 'email-channel', 'preferred-format' => 'email-html-multipart'
34
27
  end
35
- end
36
- xml.tag! 'status-report', 'report-id' => 'new', 'delete' => 'false', 'user-tracking-details' => 'false', 'link-tracking-details' => 'false', 'bouncing-details' => 'false' do
37
- xml.tag! 'report-address' do
28
+ xml.tag! 'send-date' do
29
+ xml.date Helper.date_format(options[:send_out_date])
30
+ end
31
+ xml.tag! 'send-report-address' do
38
32
  xml.tag! 'email-address' do
39
33
  xml.email options[:report_email]
40
- xml.name "Status report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
34
+ xml.name "Send report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
41
35
  end
42
36
  end
43
- xml.tag! 'send-date' do
44
- xml.date Helper.date_format(options[:send_date_for_report])
37
+ xml.tag! 'status-report', 'report-id' => 'new', 'delete' => 'false', 'user-tracking-details' => 'false', 'link-tracking-details' => 'false', 'bouncing-details' => 'false' do
38
+ xml.tag! 'report-address' do
39
+ xml.tag! 'email-address' do
40
+ xml.email options[:report_email]
41
+ xml.name "Status report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
42
+ end
43
+ end
44
+ xml.tag! 'send-date' do
45
+ xml.date Helper.date_format(options[:send_date_for_report])
46
+ end
47
+ end
48
+ xml.content 'target-content-encoding' => TARGET_CONTENT_ENCODING do
49
+ xml.subject options[:subject], 'target-encoding' => TARGET_CONTENT_ENCODING
50
+ xml.text options[:text], 'target-content-encoding' => TARGET_CONTENT_ENCODING
51
+ xml.html options[:html], 'target-content-encoding' => TARGET_CONTENT_ENCODING
45
52
  end
46
53
  end
47
- xml.content 'target-content-encoding' => TARGET_CONTENT_ENCODING do
48
- xml.subject options[:subject], 'target-encoding' => TARGET_CONTENT_ENCODING
49
- xml.text options[:text], 'target-content-encoding' => TARGET_CONTENT_ENCODING
50
- xml.html options[:html], 'target-content-encoding' => TARGET_CONTENT_ENCODING
51
- end
52
- end
53
- xml.tag! 'success-report-address' do
54
- xml.tag! 'email-address' do
55
- xml.email options[:report_email]
56
- xml.name "Success report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
54
+ xml.tag! 'success-report-address' do
55
+ xml.tag! 'email-address' do
56
+ xml.email options[:report_email]
57
+ xml.name "Success report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
58
+ end
57
59
  end
58
- end
59
- xml.tag! 'failure-report-address' do
60
- xml.tag! 'email-address' do
61
- xml.email options[:report_email]
62
- xml.name "Failure report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
60
+ xml.tag! 'failure-report-address' do
61
+ xml.tag! 'email-address' do
62
+ xml.email options[:report_email]
63
+ xml.name "Failure report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
64
+ end
63
65
  end
64
66
  end
65
67
  xml.target!
@@ -1,3 +1,3 @@
1
1
  module Ecircle
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -16,8 +16,7 @@ describe Ecircle::JobPackage do
16
16
  }
17
17
 
18
18
  @doc = <<xml
19
- <?xml version="1.0" encoding="UTF-8"?>
20
- <control xmlns="http://webservices.ecircle-ag.com/ecm" request-id="#{@options[:request_id]}" group-id="#{@options[:group_id]}">
19
+ <control xmlns="http://webservices.ecircle-ag.com/ecm" request-id="1234" group-id="5678">
21
20
  <message message-id="new" delete="false">
22
21
  <sendout-preferences>
23
22
  <object-handling html-images="untouched"/>
@@ -67,7 +66,7 @@ xml
67
66
 
68
67
  describe 'xml_for_asynch_calls' do
69
68
  it 'should generate valid xml' do
70
- Ecircle::JobPackage.xml_for_asynch_calls(@options).should == @doc
69
+ Ecircle::JobPackage.soap_body(@options).should == @doc
71
70
  end
72
71
  end
73
72
  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.0.5
4
+ version: 0.0.6
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-10-25 00:00:00.000000000Z
12
+ date: 2011-11-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &81915150 !ruby/object:Gem::Requirement
16
+ requirement: &78327690 !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: *81915150
24
+ version_requirements: *78327690
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
27
- requirement: &81914550 !ruby/object:Gem::Requirement
27
+ requirement: &78326710 !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: *81914550
35
+ version_requirements: *78326710
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &81914140 !ruby/object:Gem::Requirement
38
+ requirement: &78325790 !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: *81914140
46
+ version_requirements: *78325790
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: savon
49
- requirement: &81913720 !ruby/object:Gem::Requirement
49
+ requirement: &78324890 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.9.7
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *81913720
57
+ version_requirements: *78324890
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &81879230 !ruby/object:Gem::Requirement
60
+ requirement: &78323840 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - =
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 2.6.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *81879230
68
+ version_requirements: *78323840
69
69
  description: The ecircle gem aims to be a full-fledged client for all ecircle services.
70
70
  email:
71
71
  - timo.roessner@googlemail.com
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
77
  - .rvmrc
78
+ - .travis.yml
78
79
  - Gemfile
79
80
  - Gemfile.lock
80
81
  - README.md
@@ -102,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
103
  version: '0'
103
104
  segments:
104
105
  - 0
105
- hash: -975259857
106
+ hash: 645926193
106
107
  required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  none: false
108
109
  requirements:
@@ -111,10 +112,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  segments:
113
114
  - 0
114
- hash: -975259857
115
+ hash: 645926193
115
116
  requirements: []
116
117
  rubyforge_project: ecircle
117
- rubygems_version: 1.8.6
118
+ rubygems_version: 1.8.10
118
119
  signing_key:
119
120
  specification_version: 3
120
121
  summary: Ecircle gem