ecircle 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +18 -1
- data/README.md +39 -10
- data/ecircle.gemspec +2 -0
- data/lib/ecircle.rb +4 -0
- data/lib/ecircle/client.rb +55 -10
- data/lib/ecircle/configuration.rb +2 -0
- data/lib/ecircle/helper.rb +1 -0
- data/lib/ecircle/job_package.rb +2 -0
- data/lib/ecircle/version.rb +1 -1
- metadata +36 -13
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ecircle (0.0.
|
4
|
+
ecircle (0.0.7)
|
5
5
|
activesupport
|
6
6
|
i18n
|
7
7
|
rake
|
@@ -14,13 +14,17 @@ GEM
|
|
14
14
|
multi_json (~> 1.0)
|
15
15
|
akami (1.0.0)
|
16
16
|
gyoku (>= 0.4.0)
|
17
|
+
archive-tar-minitar (0.5.2)
|
17
18
|
builder (3.0.0)
|
19
|
+
columnize (0.3.4)
|
18
20
|
diff-lcs (1.1.3)
|
19
21
|
gyoku (0.4.4)
|
20
22
|
builder (>= 2.1.2)
|
21
23
|
httpi (0.9.5)
|
22
24
|
rack
|
23
25
|
i18n (0.6.0)
|
26
|
+
linecache19 (0.5.12)
|
27
|
+
ruby_core_source (>= 0.1.4)
|
24
28
|
multi_json (1.0.3)
|
25
29
|
nokogiri (1.5.0)
|
26
30
|
nori (1.0.2)
|
@@ -34,6 +38,16 @@ GEM
|
|
34
38
|
rspec-expectations (2.6.0)
|
35
39
|
diff-lcs (~> 1.1.2)
|
36
40
|
rspec-mocks (2.6.0)
|
41
|
+
ruby-debug-base19 (0.11.25)
|
42
|
+
columnize (>= 0.3.1)
|
43
|
+
linecache19 (>= 0.5.11)
|
44
|
+
ruby_core_source (>= 0.1.4)
|
45
|
+
ruby-debug19 (0.11.6)
|
46
|
+
columnize (>= 0.3.1)
|
47
|
+
linecache19 (>= 0.5.11)
|
48
|
+
ruby-debug-base19 (>= 0.11.19)
|
49
|
+
ruby_core_source (0.1.5)
|
50
|
+
archive-tar-minitar (>= 0.5.2)
|
37
51
|
savon (0.9.7)
|
38
52
|
akami (~> 1.0)
|
39
53
|
builder (>= 2.1.2)
|
@@ -44,6 +58,7 @@ GEM
|
|
44
58
|
wasabi (~> 2.0)
|
45
59
|
wasabi (2.0.0)
|
46
60
|
nokogiri (>= 1.4.0)
|
61
|
+
yard (0.7.3)
|
47
62
|
|
48
63
|
PLATFORMS
|
49
64
|
ruby
|
@@ -51,3 +66,5 @@ PLATFORMS
|
|
51
66
|
DEPENDENCIES
|
52
67
|
ecircle!
|
53
68
|
rspec (= 2.6.0)
|
69
|
+
ruby-debug19
|
70
|
+
yard
|
data/README.md
CHANGED
@@ -5,7 +5,9 @@ Synopsis
|
|
5
5
|
|
6
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).
|
7
7
|
|
8
|
-
|
8
|
+
The API coverage is far from complete.
|
9
|
+
|
10
|
+
However, the existing API coverage can be considered stable and is used in production.
|
9
11
|
|
10
12
|
Features
|
11
13
|
-------------
|
@@ -15,33 +17,60 @@ So far just a couple of methods:
|
|
15
17
|
* create_member
|
16
18
|
* create_or_update_user_by_email
|
17
19
|
* delete_member
|
18
|
-
* logon
|
19
20
|
* send_parametrized_single_message_to_user
|
20
21
|
|
22
|
+
See the rdoc for details on arguments and return values: [TODO Add link]
|
23
|
+
|
21
24
|
To do
|
22
25
|
-------------
|
23
26
|
|
24
|
-
* Rethink current structure
|
25
|
-
* doing an explicit logon in every method is ugly at best
|
26
|
-
* inefficient handling of session token (we could and should reuse it instead of requesting a new one every time)
|
27
|
+
* Rethink current structure
|
27
28
|
* Implement missing API methods
|
28
29
|
* Specs
|
29
30
|
* RDoc
|
31
|
+
* Remove JobPackage from gem since this is highly specific
|
30
32
|
|
31
33
|
Configuration
|
32
34
|
-------------
|
33
35
|
|
34
36
|
```Ruby
|
35
37
|
Ecircle.configure do |config|
|
36
|
-
config.user
|
37
|
-
config.
|
38
|
-
config.password
|
38
|
+
config.user = 'your@user.com'
|
39
|
+
config.sync_realm = 'http://your.realm.com'
|
40
|
+
config.password = 'your_password'
|
39
41
|
end
|
40
42
|
```
|
41
43
|
|
42
|
-
|
44
|
+
The reason for the unusual configuration setting "sync_realm" is that there is also an asynchronous ecircle API with a different realm.
|
45
|
+
|
46
|
+
Logon
|
47
|
+
-------------
|
48
|
+
|
49
|
+
The ecircle gem does the session handling for you, there is no need to logon explicitly.
|
50
|
+
Session tokens will be re-used to keep the number of session related traffic to a minimum.
|
51
|
+
|
52
|
+
|
53
|
+
Examples
|
43
54
|
-------------
|
44
55
|
|
45
56
|
```Ruby
|
46
|
-
Ecircle.
|
57
|
+
# Given you have called Ecircle.configure appropriatly...
|
58
|
+
|
59
|
+
# 1.) Create a user
|
60
|
+
uid = Ecircle.create_or_update_user_by_email 'your@email.com'
|
61
|
+
puts "Ecircle user ID: #{uid}"
|
62
|
+
|
63
|
+
# 2.) Add this user as a member to a group - e.g. for newsletters
|
64
|
+
mid = Ecircle.create_member uid, 'your_group_id'
|
65
|
+
puts "Ecircle member Id: #{mid}"
|
66
|
+
|
67
|
+
# 3.) Delete member from group - e.g. when he unsubscribes
|
68
|
+
Ecircle.delete_member mid
|
69
|
+
|
70
|
+
# 4.) Send the user a transactional email:
|
71
|
+
Ecircle.send_parametrized_single_message_to_user uid,
|
72
|
+
your_template_id_at_ecircle,
|
73
|
+
[ :name, :message ],
|
74
|
+
[ 'Tom', 'welcome!' ]
|
75
|
+
|
47
76
|
```
|
data/ecircle.gemspec
CHANGED
data/lib/ecircle.rb
CHANGED
@@ -16,14 +16,18 @@ end
|
|
16
16
|
|
17
17
|
module Ecircle
|
18
18
|
class << self
|
19
|
+
|
20
|
+
#@private
|
19
21
|
def configuration
|
20
22
|
@configuration ||= Configuration.new
|
21
23
|
end
|
22
24
|
|
25
|
+
#@private
|
23
26
|
def client
|
24
27
|
@client ||= Client.new
|
25
28
|
end
|
26
29
|
|
30
|
+
#@private
|
27
31
|
def configure &block
|
28
32
|
block.call configuration
|
29
33
|
end
|
data/lib/ecircle/client.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
module Ecircle
|
2
2
|
class Client
|
3
|
+
#@private
|
3
4
|
attr_accessor :auth_token
|
4
5
|
|
6
|
+
#@private
|
5
7
|
def ensuring_logon &block
|
6
8
|
begin
|
7
9
|
@auth_token ||= logon
|
8
10
|
rescue Savon::SOAP::Fault => e
|
9
11
|
# If we are here this probably means that our login credentials are wrong.
|
10
12
|
response = e.to_hash
|
11
|
-
if response[:fault][:
|
13
|
+
if response[:fault][:detail][:fault][:code] == '502'
|
12
14
|
help = <<-doc
|
13
15
|
!!!
|
14
16
|
Got an authentication exception, chances are good that you're credentials are wrong, so better double check that.
|
@@ -43,6 +45,7 @@ module Ecircle
|
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
48
|
+
# @private
|
46
49
|
def client
|
47
50
|
@client ||= Savon::Client.new do
|
48
51
|
wsdl.document = Ecircle.configuration.wsdl
|
@@ -51,6 +54,13 @@ module Ecircle
|
|
51
54
|
end
|
52
55
|
end
|
53
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
|
54
64
|
def create_member user_id, group_id, invite = false, send_message = false
|
55
65
|
ensuring_logon do
|
56
66
|
@response = client.request :createMember do
|
@@ -66,31 +76,59 @@ module Ecircle
|
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
|
-
|
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
|
+
|
70
90
|
ensuring_logon do
|
71
91
|
@response = client.request :createOrUpdateUserByEmail do
|
72
92
|
soap.body = {
|
73
93
|
:session => auth_token, # TODO We can't use @auth_token here cause then the session_id is nil. Why?
|
74
|
-
:userXml =>
|
94
|
+
:userXml => user_xml,
|
75
95
|
:sendMessage => 0
|
76
96
|
}
|
77
97
|
end
|
78
|
-
@response.body[:create_or_update_user_by_email_response][:create_or_update_user_by_email_return].
|
98
|
+
@response.body[:create_or_update_user_by_email_response][:create_or_update_user_by_email_return].to_i
|
79
99
|
end
|
80
100
|
end
|
81
101
|
|
102
|
+
# Delete a member.
|
103
|
+
#
|
104
|
+
# @param [Integer] member_id ecircle member id
|
105
|
+
# @return [Boolean]
|
82
106
|
def delete_member member_id
|
83
107
|
ensuring_logon do
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
89
124
|
end
|
90
|
-
@response.body[:delete_member_response][:delete_member_return].to_s
|
91
125
|
end
|
126
|
+
true
|
92
127
|
end
|
93
128
|
|
129
|
+
# Logon. You don't need to call this explicitly but it's useful for debugging.
|
130
|
+
#
|
131
|
+
# @return [String] the session id
|
94
132
|
def logon
|
95
133
|
@response = client.request :logon do
|
96
134
|
soap.body = {
|
@@ -102,6 +140,13 @@ module Ecircle
|
|
102
140
|
@response.body[:logon_response][:logon_return].to_s
|
103
141
|
end
|
104
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
|
105
150
|
def send_parametrized_single_message_to_user user_id, message_id, names = [], values = []
|
106
151
|
ensuring_logon do
|
107
152
|
@response = client.request :sendParametrizedSingleMessageToUser do
|
@@ -4,8 +4,10 @@ module Ecircle
|
|
4
4
|
ENDPOINT = 'http://webservices.ecircle-ag.com/rpc'
|
5
5
|
NAMESPACE = "http://webservices.ecircleag.com/rpcns"
|
6
6
|
|
7
|
+
# @private
|
7
8
|
attr_accessor :user, :password, :sync_realm, :async_realm, :wsdl, :endpoint, :namespace
|
8
9
|
|
10
|
+
# @private
|
9
11
|
def initialize
|
10
12
|
@wsdl = WSDL
|
11
13
|
@endpoint = ENDPOINT
|
data/lib/ecircle/helper.rb
CHANGED
data/lib/ecircle/job_package.rb
CHANGED
@@ -2,6 +2,7 @@ module Ecircle
|
|
2
2
|
module JobPackage
|
3
3
|
TARGET_CONTENT_ENCODING = 'ISO-8859-1'
|
4
4
|
|
5
|
+
# @private
|
5
6
|
def self.send_async_message_to_group(options)
|
6
7
|
client = Savon::Client.new do
|
7
8
|
wsdl.endpoint = options[:endpoint]
|
@@ -17,6 +18,7 @@ module Ecircle
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
# @private
|
20
22
|
def self.soap_body(options)
|
21
23
|
xml = Builder::XmlMarkup.new(:indent => 2)
|
22
24
|
xml.control 'xmlns' => "http://webservices.ecircle-ag.com/ecm", 'request-id' => options[:request_id], 'group-id' => options[:group_id] do
|
data/lib/ecircle/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-02 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &69598750 !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: *69598750
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: i18n
|
27
|
-
requirement: &
|
27
|
+
requirement: &69598090 !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: *69598090
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &69597470 !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: *69597470
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: savon
|
49
|
-
requirement: &
|
49
|
+
requirement: &69596650 !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: *
|
57
|
+
version_requirements: *69596650
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &69595940 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - =
|
@@ -65,7 +65,29 @@ dependencies:
|
|
65
65
|
version: 2.6.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *69595940
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: &69595540 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *69595540
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: ruby-debug19
|
82
|
+
requirement: &69594720 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *69594720
|
69
91
|
description: The ecircle gem aims to be a full-fledged client for all ecircle services.
|
70
92
|
email:
|
71
93
|
- timo.roessner@googlemail.com
|
@@ -103,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
125
|
version: '0'
|
104
126
|
segments:
|
105
127
|
- 0
|
106
|
-
hash:
|
128
|
+
hash: -98517107
|
107
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
130
|
none: false
|
109
131
|
requirements:
|
@@ -112,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
134
|
version: '0'
|
113
135
|
segments:
|
114
136
|
- 0
|
115
|
-
hash:
|
137
|
+
hash: -98517107
|
116
138
|
requirements: []
|
117
139
|
rubyforge_project: ecircle
|
118
140
|
rubygems_version: 1.8.10
|
@@ -120,3 +142,4 @@ signing_key:
|
|
120
142
|
specification_version: 3
|
121
143
|
summary: Ecircle gem
|
122
144
|
test_files: []
|
145
|
+
has_rdoc:
|