ecircle 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ .idea
2
+ pkg
3
+ runner.rb
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ruby-1.9.2-p180@ecircle
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ecircle (0.0.2)
5
+ active_support
6
+ i18n
7
+ rake
8
+ savon (>= 0.9.7)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ active_support (3.0.0)
14
+ activesupport (= 3.0.0)
15
+ activesupport (3.0.0)
16
+ akami (1.0.0)
17
+ gyoku (>= 0.4.0)
18
+ builder (3.0.0)
19
+ diff-lcs (1.1.3)
20
+ gyoku (0.4.4)
21
+ builder (>= 2.1.2)
22
+ httpi (0.9.5)
23
+ rack
24
+ i18n (0.6.0)
25
+ nokogiri (1.5.0)
26
+ nori (1.0.2)
27
+ rack (1.3.4)
28
+ rake (0.9.2)
29
+ rspec (2.6.0)
30
+ rspec-core (~> 2.6.0)
31
+ rspec-expectations (~> 2.6.0)
32
+ rspec-mocks (~> 2.6.0)
33
+ rspec-core (2.6.4)
34
+ rspec-expectations (2.6.0)
35
+ diff-lcs (~> 1.1.2)
36
+ rspec-mocks (2.6.0)
37
+ savon (0.9.7)
38
+ akami (~> 1.0)
39
+ builder (>= 2.1.2)
40
+ gyoku (>= 0.4.0)
41
+ httpi (~> 0.9)
42
+ nokogiri (>= 1.4.0)
43
+ nori (~> 1.0)
44
+ wasabi (~> 2.0)
45
+ wasabi (2.0.0)
46
+ nokogiri (>= 1.4.0)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ ecircle!
53
+ rspec (= 2.6.0)
@@ -0,0 +1,44 @@
1
+
2
+
3
+ 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
+
5
+ This is WIP and far from complete.
6
+
7
+ Features
8
+ -------------
9
+
10
+ So far just a couple of methods:
11
+
12
+ * create_member
13
+ * create_or_update_user_by_email
14
+ * delete_member
15
+ * logon
16
+ * send_parametrized_single_message_to_user
17
+
18
+ To do
19
+ -------------
20
+
21
+ * Rethink current structure e.g.
22
+ * doing an explicit logon in every method is ugly at best
23
+ * inefficient handling of session token (we could and should reuse it instead of requesting a new one every time)
24
+ * Implement missing API methods
25
+ * Specs
26
+ * RDoc
27
+
28
+ Configuration
29
+ -------------
30
+
31
+ ```Ruby
32
+ Ecircle.configure do |config|
33
+ config.user = 'your@user.com'
34
+ config.realm = 'http://your.realm.com'
35
+ config.password = 'your_password'
36
+ end
37
+ ```
38
+
39
+ Usage
40
+ -------------
41
+
42
+ ```Ruby
43
+ Ecircle.create_or_update_user_by_email 'user@email.com'
44
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ecircle/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ecircle"
7
+ s.version = Ecircle::VERSION
8
+ s.authors = ["Timo Rößner"]
9
+ s.email = ["timo.roessner@googlemail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Ecircle gem}
12
+ s.description = %q{The ecircle gem aims to be a full-fledged client for all ecircle services.}
13
+
14
+ s.rubyforge_project = "ecircle"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'active_support'
22
+ s.add_dependency 'i18n'
23
+ s.add_dependency 'rake'
24
+ s.add_dependency 'savon', '>=0.9.7'
25
+ s.add_development_dependency 'rspec', '2.6.0'
26
+ end
@@ -0,0 +1,37 @@
1
+ require 'bundler'
2
+ require 'active_support/all'
3
+ require 'savon'
4
+
5
+ # TODO Improve requiring of gems.
6
+ # `Bundler.require :default` works for an irb session with `require lib/ecircle` (e.g. Savon exists)
7
+ # but this won't work from within the rails project since `Bundler.require :default` uses the current rails
8
+ # projects Gemfile, not ecircle's one. Not sure if there is a solution for this problem, but I'd
9
+ # rather do requires via bundler instead of explicit requires.
10
+
11
+ dir = File.dirname(__FILE__)
12
+
13
+ %w!version configuration client helper job_package!.each do |file|
14
+ require File.join(dir, 'ecircle', file)
15
+ end
16
+
17
+ module Ecircle
18
+ class << self
19
+ def configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+
23
+ def client
24
+ @client ||= Client.new
25
+ end
26
+
27
+ def configure &block
28
+ block.call configuration
29
+ end
30
+ end
31
+
32
+ (Ecircle::Client.instance_methods(false) - [:client]).each do |meth|
33
+ define_singleton_method meth do |*args|
34
+ client.send meth, *args
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,71 @@
1
+ module Ecircle
2
+ class Client
3
+ def client
4
+ @client ||= Savon::Client.new do
5
+ wsdl.document = Ecircle.configuration.wsdl
6
+ wsdl.endpoint = Ecircle.configuration.endpoint
7
+ wsdl.namespace = Ecircle.configuration.namespace
8
+ end
9
+ end
10
+
11
+ def create_member user_id, group_id, invite = false, sendMessage = 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 => 0,
19
+ :sendMessage => 0
20
+ }
21
+ end
22
+ @response.body[:create_member_response][:create_member_return].to_s
23
+ end
24
+
25
+ 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
+ }
33
+ end
34
+ @response.body[:create_or_update_user_by_email_response][:create_or_update_user_by_email_return].to_s
35
+ end
36
+
37
+ 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
+ }
44
+ end
45
+ @response.body[:delete_member_response][:delete_member_return].to_s
46
+ end
47
+
48
+ def logon
49
+ @response = client.request :logon do
50
+ soap.body = {
51
+ :user => Ecircle.configuration.user,
52
+ :realm => Ecircle.configuration.realm,
53
+ :passwd => Ecircle.configuration.password
54
+ }
55
+ end
56
+ @response.body[:logon_response][:logon_return].to_s
57
+ end
58
+
59
+ def send_parametrized_single_message_to_user user_id, message_id, names = [], values = []
60
+ @response = client.request :sendParametrizedSingleMessageToUser do
61
+ soap.body = {
62
+ :session => logon,
63
+ :singleMessageId => message_id,
64
+ :userId => user_id,
65
+ :names => names,
66
+ :values => values
67
+ }
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,15 @@
1
+ module Ecircle
2
+ class Configuration
3
+ WSDL = 'http://webservices.ecircle-ag.com/soap/ecm.wsdl'
4
+ ENDPOINT = 'http://webservices.ecircle-ag.com/rpc'
5
+ NAMESPACE = "http://webservices.ecircleag.com/rpcns"
6
+
7
+ attr_accessor :user, :password, :realm, :wsdl, :endpoint, :namespace
8
+
9
+ def initialize
10
+ @wsdl = WSDL
11
+ @endpoint = ENDPOINT
12
+ @namespace = NAMESPACE
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module Ecircle
2
+ module Helper
3
+ extend self
4
+
5
+ def date_format date
6
+ date.strftime("%Y-%m-%dT%H:%M:%S")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,60 @@
1
+ module Ecircle
2
+ module JobPackage
3
+ TARGET_CONTENT_ENCODING = 'ISO-8859-1'
4
+
5
+ def self.send_asynch_message_to_group(options)
6
+ xml = xml_for_asynch_calls(options)
7
+ end
8
+
9
+ def self.xml_for_asynch_calls(options)
10
+ xml = Builder::XmlMarkup.new(:indent => 2)
11
+ xml.instruct!
12
+ xml.control :xmlns => 'http://webservices.ecircle-ag.com/ecm', 'request-id' => options[:request_id], 'group-id' => options[:group_id] do
13
+ xml.message 'message-id' => 'new', 'delete' => 'false' do
14
+ xml.tag! 'sendout-preferences' do
15
+ xml.tag! 'object-handling', 'html-images' => 'untouched'
16
+ xml.tag! 'email-channel', 'preferred-format' => 'email-html-multipart'
17
+ end
18
+ xml.tag! 'send-date' do
19
+ xml.date Helper.date_format(options[:send_out_date])
20
+ end
21
+ xml.tag! 'send-report-address' do
22
+ xml.tag! 'email-address' do
23
+ xml.email options[:report_email]
24
+ xml.name "Send report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
25
+ end
26
+ end
27
+ xml.tag! 'status-report', 'report-id' => 'new', 'delete' => 'false', 'user-tracking-details' => 'false', 'link-tracking-details' => 'false', 'bouncing-details' => 'false' do
28
+ xml.tag! 'report-address' do
29
+ xml.tag! 'email-address' do
30
+ xml.email options[:report_email]
31
+ xml.name "Status report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
32
+ end
33
+ end
34
+ xml.tag! 'send-date' do
35
+ xml.date Helper.date_format(options[:send_date_for_report])
36
+ end
37
+ end
38
+ xml.content 'target-content-encoding' => TARGET_CONTENT_ENCODING do
39
+ xml.subject options[:subject], 'target-encoding' => TARGET_CONTENT_ENCODING
40
+ xml.text options[:text], 'target-content-encoding' => TARGET_CONTENT_ENCODING
41
+ xml.html options[:html], 'target-content-encoding' => TARGET_CONTENT_ENCODING
42
+ end
43
+ end
44
+ xml.tag! 'success-report-address' do
45
+ xml.tag! 'email-address' do
46
+ xml.email options[:report_email]
47
+ xml.name "Success report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
48
+ end
49
+ end
50
+ xml.tag! 'failure-report-address' do
51
+ xml.tag! 'email-address' do
52
+ xml.email options[:report_email]
53
+ xml.name "Failure report for newsletter for location #{options[:location_name]} sent out on #{options[:send_out_date]}"
54
+ end
55
+ end
56
+ end
57
+ xml.target!
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Ecircle
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ecircle::JobPackage do
4
+ before :all do
5
+ date = 1.hour.from_now
6
+ @options = {
7
+ :request_id => '1234',
8
+ :group_id => '5678',
9
+ :send_out_date => date,
10
+ :send_date_for_report => date,
11
+ :report_email => 'report@dealvertise.de',
12
+ :location_name => 'Berlin',
13
+ :subject => 'Berlin newsletter',
14
+ :text => 'Newsletter text content',
15
+ :html => 'Newsletter html content'
16
+ }
17
+
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]}">
21
+ <message message-id="new" delete="false">
22
+ <sendout-preferences>
23
+ <object-handling html-images="untouched"/>
24
+ <email-channel preferred-format="email-html-multipart"/>
25
+ </sendout-preferences>
26
+ <send-date>
27
+ <date>#{Ecircle::Helper.date_format(@options[:send_out_date])}</date>
28
+ </send-date>
29
+ <send-report-address>
30
+ <email-address>
31
+ <email>#{@options[:report_email]}</email>
32
+ <name>Send report for newsletter for location #{@options[:location_name]} sent out on #{@options[:send_out_date]}</name>
33
+ </email-address>
34
+ </send-report-address>
35
+ <status-report report-id="new" delete="false" user-tracking-details="false" link-tracking-details="false" bouncing-details="false">
36
+ <report-address>
37
+ <email-address>
38
+ <email>#{@options[:report_email]}</email>
39
+ <name>Status report for newsletter for location #{@options[:location_name]} sent out on #{@options[:send_out_date]}</name>
40
+ </email-address>
41
+ </report-address>
42
+ <send-date>
43
+ <date>#{Ecircle::Helper.date_format(@options[:send_date_for_report])}</date>
44
+ </send-date>
45
+ </status-report>
46
+ <content target-content-encoding="ISO-8859-1">
47
+ <subject target-encoding="ISO-8859-1">#{@options[:subject]}</subject>
48
+ <text target-content-encoding="ISO-8859-1">#{@options[:text]}</text>
49
+ <html target-content-encoding="ISO-8859-1">#{@options[:html]}</html>
50
+ </content>
51
+ </message>
52
+ <success-report-address>
53
+ <email-address>
54
+ <email>#{@options[:report_email]}</email>
55
+ <name>Success report for newsletter for location #{@options[:location_name]} sent out on #{@options[:send_out_date]}</name>
56
+ </email-address>
57
+ </success-report-address>
58
+ <failure-report-address>
59
+ <email-address>
60
+ <email>#{@options[:report_email]}</email>
61
+ <name>Failure report for newsletter for location #{@options[:location_name]} sent out on #{@options[:send_out_date]}</name>
62
+ </email-address>
63
+ </failure-report-address>
64
+ </control>
65
+ xml
66
+ end
67
+
68
+ describe 'xml_for_asynch_calls' do
69
+ it 'should generate valid xml' do
70
+ Ecircle::JobPackage.xml_for_asynch_calls(@options).should == @doc
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,2 @@
1
+ dir = File.dirname(__FILE__)
2
+ require File.join(dir, '..', 'lib', 'ecircle')
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ecircle
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - "Timo R\xC3\xB6\xC3\x9Fner"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-23 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: active_support
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: savon
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.9.7
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rspec
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - "="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.6.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ description: The ecircle gem aims to be a full-fledged client for all ecircle services.
72
+ email:
73
+ - timo.roessner@googlemail.com
74
+ executables: []
75
+
76
+ extensions: []
77
+
78
+ extra_rdoc_files: []
79
+
80
+ files:
81
+ - .gitignore
82
+ - .rvmrc
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - README.md
86
+ - Rakefile
87
+ - ecircle.gemspec
88
+ - lib/ecircle.rb
89
+ - lib/ecircle/client.rb
90
+ - lib/ecircle/configuration.rb
91
+ - lib/ecircle/helper.rb
92
+ - lib/ecircle/job_package.rb
93
+ - lib/ecircle/version.rb
94
+ - spec/client_spec.rb
95
+ - spec/spec_helper.rb
96
+ has_rdoc: true
97
+ homepage: ""
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: -289051661
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: -289051661
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements: []
124
+
125
+ rubyforge_project: ecircle
126
+ rubygems_version: 1.6.2
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Ecircle gem
130
+ test_files: []
131
+