do-list-v8 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6e81728e97985f7f9a3b32e552ce342dd020c40ed36531b59736a0239ef5539c
4
+ data.tar.gz: 1e67836c96ed6b65c51d433980bc2c4d9f0c23619ad4a489c1a5ca4aeb38e4bb
5
+ SHA512:
6
+ metadata.gz: ca6a51583006e11eccd8e43fe0b21504ea103c12f8672396208770ba15244d1e7a022c17d2a04bc7019a8e2a4e65ce6c1ae3d77a70f3c47b84b95c278a7d1cd8
7
+ data.tar.gz: 9e2cfaa93df9128cd371fe62ee1fbf8c274a84af95cf9cc6bf93a5f3f82f827122f05545621f604baee8c857b6864ed9fa5cd8001380cb275c1924c98806a612
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in do-list-v8.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ do-list-v8 (0.1.0)
5
+ nokogiri (~> 1.10)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ mini_portile2 (2.4.0)
12
+ nokogiri (1.10.3)
13
+ mini_portile2 (~> 2.4.0)
14
+ rake (10.5.0)
15
+ rspec (3.8.0)
16
+ rspec-core (~> 3.8.0)
17
+ rspec-expectations (~> 3.8.0)
18
+ rspec-mocks (~> 3.8.0)
19
+ rspec-core (3.8.2)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-expectations (3.8.4)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-mocks (3.8.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-support (3.8.2)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 2.0)
34
+ do-list-v8!
35
+ rake (~> 10.0)
36
+ rspec (~> 3.0)
37
+
38
+ BUNDLED WITH
39
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Roan Mertens
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # do-list-v8-integration-gem
2
+ This is the Ruby gem to integrate with the v8 SOAP api of Do List.
3
+
4
+ Documentation for their v8 api: http://api.dolist.net/doc
5
+ Log in to their extranet to get an api key and accound id: https://extranet.dolist.net/Home.aspx
6
+ See the how to use section in this readme.
7
+
8
+
9
+ ## Do List V8
10
+ The V8 platform is the Do List email and SMS marketing platform. It is a place to store contacts, collect and organise data and set up automatic mail deliveries and personalised messages.
11
+ For more info checkout: https://www.dolist.com/en/solutions/dolist-v8/
12
+
13
+
14
+ ## This gem
15
+ This gem is exclusively to get an authorisation key and to use it to push new entries to the V8 platform.
16
+ The v8 api uses the AccountID and the AuthenticationKey from the use to generate an AuthenticationToken. This token restrains the use of the API to an hour after which another AuthenticationToken needs to be created.
17
+
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'do-list-v8'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install do-list-v8
34
+
35
+
36
+ ## How to use?
37
+ When your account gets created you need to get the AccountID and the AuthenticationKey. For that you need to log in to: https://extranet.dolist.net. When logged in, click on the `administration` tab in the top right corner.
38
+ Then click on the `2. Web services` that appear on the settings bar to the right in the `G. Documentation Services`.
39
+
40
+ Add the IP address of the server you are going to use to connect to their api. Then click on the manage keys tab and create a new key. When the key is created, click on the `see key button` and a popup appears with your ID and key. Save the AccountID and the AuthenticationKey. They will both be used in this gem.
41
+
42
+ When using this gem, create a new integration and pass it the AccountID and the AuthenticationKey that you got.
43
+ * `do_list = DoList::Integration.new(account_id: [AccountID], api_key: [AuthenticationKey])`
44
+
45
+ Pass it to a variable. Use the push_entry method each time you want to push an entry to the Do List V8 platform.
46
+ * `do_list.push_entry(fields)`
47
+
48
+ The push_entry method needs an array with the following key-value pairs. All other key-value pairs will be added as extra fields.
49
+
50
+ ### Required
51
+ `email: 'example@mail.com'`
52
+
53
+ ### Optional
54
+ `mail_opt_out: 1` -- `0 = opt in` -- `1 = opt out` --
55
+ `mobile_opt_out: 0` -- `0 = opt in` -- `1 = opt out` --
56
+ when not specified they fall back to 0.
57
+
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/emocial/do-list-v8.
69
+ If anyone is interested in improving this gem, please don't hesitate to fork and send pull requests ;)
70
+ Look in their v8 documentation (http://api.dolist.net/doc) to see the api methods that aren't added to this gem yet.
71
+
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
76
+
77
+ ## Contributors
78
+
79
+ * Roan Mertens - https://github.com/RoanMertens
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'do-list'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,45 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'do-list/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'do-list-v8'
7
+ spec.version = DoList::VERSION
8
+ spec.authors = ['Roan Mertens']
9
+ spec.email = ['roanmertens91@gmail.com']
10
+
11
+ spec.summary = 'This is the gem to integrate with the Do List V8 platform.'
12
+ spec.description = 'The V8 platform is the Do List email and SMS marketing platform. It is a place to store contacts, collect and organise data and set up automatic mail deliveries and personalised messages.
13
+ For more info checkout: https://www.dolist.com/en/solutions/dolist-v8/'
14
+ spec.homepage = 'https://github.com/RoanMertens/do-list-v8'
15
+ spec.license = 'MIT'
16
+
17
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ # spec.metadata['homepage_uri'] = spec.homepage
23
+ # spec.metadata['source_code_uri'] = "TODO: Put your gem's public repo URL here."
24
+ # spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ # else
26
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
27
+ # 'public gem pushes.'
28
+ # end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = 'exe'
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ['lib']
38
+
39
+ spec.add_development_dependency 'bundler', '~> 2.0'
40
+ # spec.add_development_dependency 'factory_bot', '~> 5.0'
41
+ spec.add_development_dependency 'rake', '~> 10.0'
42
+ spec.add_development_dependency 'rspec', '~> 3.0'
43
+ # spec.add_development_dependency 'webmock', '~> 2.1'
44
+ spec.add_runtime_dependency 'nokogiri', '~> 1.10'
45
+ end
@@ -0,0 +1,44 @@
1
+ # require 'url_parser'
2
+
3
+ module DoList
4
+ class AuthToken
5
+ def initialize(params = {})
6
+ @headers = params[:headers]
7
+ @account_id = params[:account_id]
8
+ @api_key = params[:api_key]
9
+ @uri = DoList::UrlParser.parse_url(params[:url])
10
+ @http = DoList::UrlParser.request_http(@uri)
11
+ @auth_key, @auth_depr_date = request_auth_key
12
+ end
13
+
14
+ def auth_key
15
+ @auth_key, @auth_depr_date = request_auth_key if (DateTime.now + (1 / 24.0)) > @auth_depr_date
16
+ @auth_key
17
+ end
18
+
19
+ private
20
+
21
+ def request_auth_key
22
+ document = DoList::UrlParser.post_http(@http, @uri, body, @headers)
23
+ parsed = []
24
+ parsed << document.xpath('//Key').children.to_s
25
+ parsed << DateTime.parse(document.xpath('//DeprecatedDate').children.to_s)
26
+ end
27
+
28
+ def body
29
+ <<-GETAUTHBODY
30
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://api.dolist.net/v2">
31
+ <soapenv:Header/>
32
+ <soapenv:Body>
33
+ <v2:GetAuthenticationToken>
34
+ <v2:authenticationRequest>
35
+ <v2:AccountID>#{@account_id}</v2:AccountID>
36
+ <v2:AuthenticationKey>#{@api_key}</v2:AuthenticationKey>
37
+ </v2:authenticationRequest>
38
+ </v2:GetAuthenticationToken>
39
+ </soapenv:Body>
40
+ </soapenv:Envelope>
41
+ GETAUTHBODY
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,67 @@
1
+ # require 'url_parser'
2
+
3
+ module DoList
4
+ class PushEntry
5
+ def initialize(params = {})
6
+ @headers = params[:headers]
7
+ @account_id = params[:account_id]
8
+ @auth_token = params[:auth_token]
9
+ @uri = DoList::UrlParser.parse_url(params[:url])
10
+ @http = DoList::UrlParser.request_http(@uri)
11
+ end
12
+
13
+ def push_entry(fields)
14
+ return false unless fields[:email]
15
+
16
+ body = create_body(fields)
17
+ DoList::UrlParser.post_http(@http, @uri, body, @headers)
18
+ end
19
+
20
+ private
21
+
22
+ def create_body(fields)
23
+ email = fields.delete(:email).to_s
24
+ mail_opt_out = fields.delete(:mail_opt_out) == 1 ? 1 : 0
25
+ mobile_opt_out = fields.delete(:mobile_opt_out) == 1 ? 1 : 0
26
+ fields = body_fields(fields)
27
+ xml_body(fields, email, mail_opt_out, mobile_opt_out)
28
+ end
29
+
30
+ def body_fields(database_fields)
31
+ database_fields = database_fields.map do |name, value|
32
+ <<-FIELD
33
+ <ns2:Field>
34
+ <ns2:Name>#{name}</ns2:Name>
35
+ <ns2:Value>#{value}</ns2:Value>
36
+ </ns2:Field>
37
+ FIELD
38
+ end
39
+ return '<ns2:Fields/>' if database_fields.empty?
40
+
41
+ '<ns2:Fields>' + database_fields.join('') + '</ns2:Fields>'
42
+ end
43
+
44
+ def xml_body(fields, email, mail_opt_out, mobile_opt_out)
45
+ <<-ADDENTRYBODY
46
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.dolist.net/v2" xmlns:ns2="http://schemas.datacontract.org/2004/07/Dolist.ContactManagement.API.DataContract.Management">
47
+ <SOAP-ENV:Body>
48
+ <ns1:SaveContact>
49
+ <ns1:token>
50
+ <ns1:AccountID>#{@account_id}</ns1:AccountID>
51
+ <ns1:Key>#{@auth_token}</ns1:Key>
52
+ </ns1:token>
53
+ <ns1:contact>
54
+ <ns2:Email>#{email}</ns2:Email>
55
+ #{fields}
56
+ <ns2:InterestsToAdd/>
57
+ <ns2:InterestsToDelete/>
58
+ <ns2:OptoutEmail>#{mail_opt_out}</ns2:OptoutEmail>
59
+ <ns2:OptoutMobile>#{mobile_opt_out}</ns2:OptoutMobile>
60
+ </ns1:contact>
61
+ </ns1:SaveContact>
62
+ </SOAP-ENV:Body>
63
+ </SOAP-ENV:Envelope>
64
+ ADDENTRYBODY
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,20 @@
1
+ module DoList
2
+ class UrlParser
3
+ class << self
4
+ def parse_url(url)
5
+ URI.parse(url)
6
+ end
7
+
8
+ def request_http(uri)
9
+ http = Net::HTTP.new(uri.host, uri.port)
10
+ http.use_ssl = false
11
+ http
12
+ end
13
+
14
+ def post_http(http, uri, body, headers)
15
+ result = http.post(uri.path, body, headers)
16
+ Nokogiri::XML(result.body).remove_namespaces!
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module DoList
2
+ VERSION = '0.1.0'
3
+ end
data/lib/do_list.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'do-list/version'
2
+ require 'do-list/auth_token'
3
+ require 'do-list/push_entry'
4
+ require 'do-list/url_parser'
5
+
6
+ module DoList
7
+ class Integration
8
+ def initialize(params = {})
9
+ @account_id = params[:account_id]
10
+ @api_key = params[:api_key]
11
+ @auth_url = 'http://api.dolist.net/v2/AuthenticationService.svc/soap1.1'
12
+ @push_url = 'http://api.dolist.net/V2/ContactManagementService.svc/soap1.1'
13
+ @auth_token = DoList::AuthToken.new(account_id: @account_id,
14
+ api_key: @api_key,
15
+ url: @auth_url,
16
+ headers: create_headers('auth'))
17
+ end
18
+
19
+ def auth_key
20
+ @auth_token.auth_key
21
+ end
22
+
23
+ def push_entry(fields)
24
+ entry = DoList::PushEntry.new(auth_token: @auth_token.auth_key,
25
+ account_id: @account_id,
26
+ url: @push_url,
27
+ headers: create_headers('push'))
28
+ entry.push_entry(fields)
29
+ end
30
+
31
+ private
32
+
33
+ def create_headers(type)
34
+ path = 'AuthenticationService/GetAuthenticationToken' if type == 'auth'
35
+ path = 'ContactManagementService/SaveContact' if type == 'push'
36
+ {
37
+ 'Content-Type' => 'text/xml; charset=utf-8',
38
+ 'SOAPAction' => "http://api.dolist.net/v2/#{path}"
39
+ }
40
+ end
41
+ end
42
+ end
43
+
44
+ require 'date'
45
+ require 'net/https'
46
+ require 'uri'
47
+ require 'nokogiri'
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: do-list-v8
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roan Mertens
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ description: |-
70
+ The V8 platform is the Do List email and SMS marketing platform. It is a place to store contacts, collect and organise data and set up automatic mail deliveries and personalised messages.
71
+ For more info checkout: https://www.dolist.com/en/solutions/dolist-v8/
72
+ email:
73
+ - roanmertens91@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - do-list-v8.gemspec
89
+ - lib/do-list/auth_token.rb
90
+ - lib/do-list/push_entry.rb
91
+ - lib/do-list/url_parser.rb
92
+ - lib/do-list/version.rb
93
+ - lib/do_list.rb
94
+ homepage: https://github.com/RoanMertens/do-list-v8
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.7.6
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: This is the gem to integrate with the Do List V8 platform.
118
+ test_files: []