Silverpops 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +10 -0
  3. data/lib/silverpops.rb +190 -0
  4. metadata +87 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44989ca2865f3090862e652f0ce8b01e42391ca1
4
+ data.tar.gz: b2d427cc08c34ea33b7e0cfe134947848835f25d
5
+ SHA512:
6
+ metadata.gz: ccc0beef8d2167374f885e145011de6d41c3239ef7a99b30f95710ce79dc2c0d1ce55b8bdf0989147496df013fb882c5fa3f5e66d52a2e0a15bd6d1af8476010
7
+ data.tar.gz: 308a99e110f1526c834fd017ca2908bc1df6f7abab1a21203528b91830c5178e03bac7851444bb87e5aa0fd8f729f97939f2272b5f71841c11b0117b7e5af64e
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in silverpops.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'guard-rspec', '~> 4.3.1', require: false
8
+ gem 'rspec', require: false
9
+ gem 'dotenv', require: false
10
+ end
@@ -0,0 +1,190 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'redis'
4
+ require 'nokogiri'
5
+
6
+ module Silverpops
7
+
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.get_api_base_uri
13
+ return 'http://api' + Silverpops.configuration.server_number.to_s + '.silverpop.com/XMLAPI'
14
+ end
15
+
16
+ def self.get_token(clear_cache = false)
17
+ tries ||= 2
18
+
19
+ builder = Nokogiri::XML::Builder.new do |xml|
20
+ xml.Envelope {
21
+ xml.Body {
22
+ xml.Login {
23
+ xml.USERNAME Silverpops.configuration.username
24
+ xml.PASSWORD Silverpops.configuration.password
25
+ }
26
+ }
27
+ }
28
+ end
29
+
30
+ faraday = Faraday.new(:url => get_api_base_uri(), :proxy => Silverpops.configuration.proxy) do |faraday|
31
+ faraday.request :url_encoded
32
+ faraday.adapter Faraday.default_adapter
33
+ end
34
+
35
+ response = faraday.post do |req|
36
+ req.url '/XMLAPI'
37
+ req.headers["Content-Type"] = "text/xml"
38
+ req.headers["Accept"] = "text/xml"
39
+ req.body = builder.to_xml
40
+ end
41
+
42
+ if response.status == 200
43
+
44
+ doc = Nokogiri::XML(response.body)
45
+ doc.xpath("//Envelope/Body/RESULT/SUCCESS").each do |node|
46
+
47
+ doc.xpath("//Envelope/Body/RESULT/SESSIONID").each do |session|
48
+ return session.content
49
+ end
50
+
51
+ end
52
+
53
+ return false
54
+
55
+ else
56
+ raise RetryException, response.status.to_s + " " + response.body if response.status == 200
57
+ end
58
+
59
+ rescue RetryException => e
60
+ if (tries -= 1) > 0
61
+ retry
62
+ else
63
+ raise e
64
+ end
65
+ end
66
+
67
+ def self.find_list_member(database_id, email, fields = {})
68
+
69
+ builder = Nokogiri::XML::Builder.new do |xml|
70
+ xml.Envelope {
71
+ xml.Body {
72
+ xml.SelectRecipientData {
73
+ xml.LIST_ID database_id
74
+ xml.EMAIL email
75
+ }
76
+ }
77
+ }
78
+ end
79
+
80
+ faraday = Faraday.new(:url => get_api_base_uri(), :proxy => Silverpops.configuration.proxy) do |faraday|
81
+ faraday.request :url_encoded
82
+ faraday.adapter Faraday.default_adapter
83
+ end
84
+
85
+ response = faraday.post do |req|
86
+ req.url '/XMLAPI'
87
+ req.headers["Content-Type"] = "text/xml"
88
+ req.headers["Accept"] = "text/xml"
89
+ req.body = builder.to_xml
90
+ req.params['jsessionid'] = get_token()
91
+ end
92
+
93
+ doc = Nokogiri::XML(response.body)
94
+ doc.xpath("//Envelope/Body/RESULT/SUCCESS").each do |node|
95
+
96
+
97
+ if node.content.downcase == "true"
98
+
99
+ record_data = {}
100
+
101
+ doc.xpath("//Envelope/Body/RESULT").each do |data|
102
+ record_data["Email"] = data.xpath("EMAIL")[0].content
103
+ record_data["RecipientId"] = data.xpath("RecipientId")[0].content.to_i
104
+ end
105
+
106
+ doc.xpath("//Envelope/Body/RESULT/COLUMNS/COLUMN").each do |data|
107
+ record_data[data.xpath("NAME")[0].content] = data.xpath("VALUE")[0].content
108
+ end
109
+
110
+ return record_data
111
+
112
+ else
113
+ return false
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ def self.add_list_member(database_id, key_data, update_if_found = true, allow_html = true, send_auto_reply = true)
120
+
121
+ builder = Nokogiri::XML::Builder.new do |xml|
122
+ xml.Envelope {
123
+ xml.Body {
124
+ xml.AddRecipient {
125
+ xml.LIST_ID database_id
126
+ xml.CREATED_FROM 1
127
+ xml.SEND_AUTOREPLY send_auto_reply
128
+ xml.UPDATE_IF_FOUND update_if_found
129
+ xml.ALLOW_HTML allow_html
130
+ xml.CONTACT_LISTS ''
131
+
132
+ key_data.each do |key, value|
133
+ xml.COLUMN {
134
+ xml.NAME key
135
+ xml.VALUE value
136
+ }
137
+ end
138
+
139
+ }
140
+ }
141
+ }
142
+ end
143
+
144
+ faraday = Faraday.new(:url => get_api_base_uri(), :proxy => Silverpops.configuration.proxy) do |faraday|
145
+ faraday.request :url_encoded
146
+ faraday.adapter Faraday.default_adapter
147
+ end
148
+
149
+ response = faraday.post do |req|
150
+ req.url '/XMLAPI'
151
+ req.headers["Content-Type"] = "text/xml"
152
+ req.headers["Accept"] = "text/xml"
153
+ req.body = builder.to_xml
154
+ req.params['jsessionid'] = get_token()
155
+ end
156
+
157
+ doc = Nokogiri::XML(response.body)
158
+ doc.xpath("//Envelope/Body/RESULT/SUCCESS").each do |node|
159
+ return node.content.downcase == "true"
160
+ end
161
+
162
+ end
163
+
164
+ def self.configuration
165
+ @configuration ||= Configuration.new
166
+ end
167
+
168
+ def self.configure
169
+ self.configuration ||= Configuration.new
170
+ yield(configuration)
171
+ end
172
+
173
+ class Configuration
174
+ attr_accessor :username
175
+ attr_accessor :password
176
+ attr_accessor :server_number
177
+ attr_accessor :proxy
178
+
179
+ def initialize
180
+ @username = ''
181
+ @password = ''
182
+ @server_number = 1
183
+ @proxy = nil
184
+ end
185
+ end
186
+
187
+ class RetryException < RuntimeError
188
+ end
189
+
190
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Silverpops
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Tom Holder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.6.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.6.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.1
55
+ description: Some basic cheetah mail API end points implemented
56
+ email: tom@simpleweb.co.uk
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - Gemfile
62
+ - lib/silverpops.rb
63
+ homepage: http://rubygems.org/gems/silverpops
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.5
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Silverpops is a clunky campaign manager
87
+ test_files: []