campaign_monitor_private 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eed733482bb8fd67b3ccacd7eda58ae397eca3e6c0a1188b2e4432d370eaa0d6
4
+ data.tar.gz: cd26f6908969b458f8b96c2d74b2fd1401bfb194799d0c0d0281782ba8828309
5
+ SHA512:
6
+ metadata.gz: 7a0cb0306d4bd66097509ad74da70274f74719c85d52fb834f4ba2579913af079faf0e15a5758ef1dfa12d93b11b9f69f960946af39fb5678903f08b3332ea2f
7
+ data.tar.gz: 2a2cda11666b717742999c2aef2f305f79230691d0aa7f90166d659c060764609a8889ffd3e0a47b3b3e10e5059b143ffe6854ecd1db57290a9f20dc4c70ae80
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+ campaign_monitor_private-*.gem
@@ -0,0 +1,13 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
+ before_install: gem install bundler -v 1.17.1
11
+ script:
12
+ - bundle exec rake test
13
+ - bundle exec bundle-audit check --update
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 0.1.0 - 2019-08-02
8
+ ### Added
9
+ - Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in campaign_monitor_private.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TODO: Write your name
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.
@@ -0,0 +1,172 @@
1
+ # CampaignMonitorPrivate
2
+
3
+ The Campaign Monitor website and the Campaign Monitor API use entirely independent IDs to reference your data. This gem helps reconcile the two worlds.
4
+
5
+ Please read this whole document before using this gem, especially the sections on **Stability** and **Security and Permissions**
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'campaign_monitor_private'
13
+ ```
14
+
15
+ Or run `gem install campaign_monitor_private` on your command line and add `require 'campaign_monitor_private'` to your code.
16
+
17
+ ## Usage
18
+
19
+ There are a number of ways to instantiate `CampaignMonitorPrivate`:
20
+
21
+ ```ruby
22
+ client = CampaignMonitorPrivate.new(
23
+ username: 'emailaddress@acme.com',
24
+ password: 'blahblahblah'
25
+ )
26
+ ```
27
+
28
+ This is the most basic way to log in. It will log into Campaign Monitor's main site, which will then bounce you to your custom subdomain and it will then log in again. To avoid this double login, you can (and should) provide the subdomain:
29
+
30
+ ```ruby
31
+ client = CampaignMonitorPrivate.new(
32
+ username: 'emailaddress@acme.com',
33
+ password: 'blahblahblah',
34
+ domain: 'acme'
35
+ )
36
+ ```
37
+
38
+ This will halve the login time.
39
+
40
+ This gem is able to handle privileged (superuser) accounts and non-privileged accounts. I'd strongly recommend setting up unprivileged accounts for use with this gem. But if you insist on using a superuser account, you will need to name the subaccount you want to work with. There are two ways to do this.
41
+
42
+ At instantiation:
43
+ ```ruby
44
+ client = CampaignMonitorPrivate.new(
45
+ username: 'superuser@acme.com',
46
+ password: 'blahblahblah',
47
+ domain: 'acme'
48
+ default_customer: 'Some Customer'
49
+ )
50
+ ```
51
+
52
+ Or during runtime:
53
+ ```ruby
54
+ client = CampaignMonitorPrivate.new(
55
+ username: 'superuser@acme.com',
56
+ password: 'blahblahblah',
57
+ domain: 'acme'
58
+ )
59
+
60
+ client.set_active_customer "Customer One"
61
+
62
+ # ...
63
+
64
+ client.set_active_customer "Customer Two"
65
+
66
+ # ...
67
+ ```
68
+
69
+
70
+ ## Two Factor Auth
71
+ The gem is capable of handling Two Factor Auth, in two ways:
72
+
73
+ If you know your 2FA secret and want `CampaignMonitorPrivate` to automatically generate the tokens for you:
74
+ ```ruby
75
+ client = CampaignMonitorPrivate.new(
76
+ username: 'user@acme.com',
77
+ password: 'blahblahblah',
78
+ tfa_secret: 'BCFTP3LNOYIK5O6E1F02KMYTT5A86BCC43UQHWCOYWT8L'
79
+ )
80
+ ```
81
+
82
+ Or if you want to manually provide OTP tokens:
83
+ ```ruby
84
+ my_token = '123456'
85
+
86
+ client = CampaignMonitorPrivate.new(
87
+ username: 'user@acme.com',
88
+ password: 'blahblahblah',
89
+ tfa_token: my_token
90
+ )
91
+ ```
92
+
93
+ **NOTE:** The client will not attempt login until you try to retrieve data from Campaign Monitor. So if you instantiate `CampaignMonitorPrivate` with a 2FA token, but then don't use it for some time; the token may have expired. To avoid this scenario, you can call `client.login` immediately after instantiation to force login.
94
+
95
+ There should be no scenario where you're providing a token and a secret, but if you do, the token will be used. `CampaignMonitorPrivate` will not try to generate one for you using the secret.
96
+
97
+ ## Environment Variables
98
+
99
+ All of the above can be provided via environment variables:
100
+ ```ruby
101
+ username: ENV['CAMPAIGN_MONITOR_USERNAME'],
102
+ password: ENV['CAMPAIGN_MONITOR_PASSWORD'],
103
+ tfa_token: ENV['CAMPAIGN_MONITOR_2FA'],
104
+ tfa_secret: ENV['CAMPAIGN_MONITOR_SECRET'],
105
+ domain: ENV['CAMPAIGN_MONITOR_DOMAIN'],
106
+ default_customer: ENV['CAMPAIGN_MONITOR_DEFAULT_CUSTOMER']
107
+ ```
108
+
109
+ ## Getting IDs
110
+
111
+ That's why we're all here, of course.
112
+
113
+ ```ruby
114
+ list_id = client.get_list_id_for 'Main List'
115
+ # => '164bfaa483d3382b'
116
+
117
+ segments = client.get_segments_for list_id
118
+ # => [{"id"=>"B8C33EE6D6DA33F2",
119
+ # "name"=>"18 people",
120
+ # "systemSegmentType"=>"None",
121
+ # "subscriberCount"=>18,
122
+ # "lastUpdated"=>"2/08/2019 11:41:00 AM",
123
+ # "integrationType"=>[],
124
+ # "advancedSegmentId"=>nil,
125
+ # "isBehavioural"=>false},
126
+ # {"id"=>"E6B17AFF15A93EA9",
127
+ # "name"=>"Newsletter Subscribers",
128
+ # "systemSegmentType"=>"None",
129
+ # "subscriberCount"=>36927348,
130
+ # "lastUpdated"=>"12/03/2015 11:41:00 AM",
131
+ # "integrationType"=>[],
132
+ # "advancedSegmentId"=>nil,
133
+ # "isBehavioural"=>false},
134
+ # {"id"=>"2A0C22D45159D1FF",
135
+ # "name"=>"Example Targeting Segment",
136
+ # "systemSegmentType"=>"None",
137
+ # "subscriberCount"=>1,
138
+ # "lastUpdated"=>"2/08/2019 11:41:00 AM",
139
+ # "integrationType"=>[],
140
+ # "advancedSegmentId"=>nil,
141
+ # "isBehavioural"=>false}]
142
+ ```
143
+
144
+ **NOTE:** The results are cached internally, so watch out for that.
145
+
146
+ ## Stability
147
+
148
+ This gem makes use of the dark arts of screen scraping. This means that it could break at any moment. It has been built to be as robust as possible, but there's no guarantee that it's going to work tomorrow. Bear this in mind, and don't rely on it for anything important.
149
+
150
+ ## Security and Permissions
151
+
152
+ Although this gem supports 2FA, using 2FA doesn't provide much additional security if you're storing your 2FA secret alongside your username and password as you still only have one factor. To get your 2FA secret, you'll need to enable 2FA in Campaign Monitor and extract the secret from the QR code you're presented with. You may also be able to extract the secret from whatever authentication app you're using on your phone.
153
+
154
+ Although this gem can work with superuser accounts (accounts responsible for managing a number of sub-accounts), unless you really need to use a superuser account, it's a much better idea to set up per-customer accounts, and lock-down their permissions. **The only permission you need is "Lists & Subscribers"**
155
+
156
+ ## Development
157
+
158
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
159
+
160
+ 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).
161
+
162
+ ## Contributing
163
+
164
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cyclotron3k/campaign_monitor_private. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
165
+
166
+ ## License
167
+
168
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
169
+
170
+ ## Code of Conduct
171
+
172
+ Everyone interacting in the CampaignMonitorPrivate project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cyclotron3k/campaign_monitor_private/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
11
+
12
+ task :console do
13
+ exec 'pry -I ./lib -r campaign_monitor_private'
14
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "campaign_monitor_private"
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__)
@@ -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,38 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'campaign_monitor_private/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'campaign_monitor_private'
7
+ spec.version = CampaignMonitorPrivate::VERSION
8
+ spec.authors = ['cyclotron3k']
9
+ spec.email = ['aidan.samuel@gmail.com']
10
+
11
+ spec.summary = 'A screen-scraper to retrieve vital information not available via the public API'
12
+ spec.homepage = 'https://github.com/cyclotron3k/campaign_monitor_private'
13
+ spec.license = 'MIT'
14
+
15
+ spec.metadata = {
16
+ 'bug_tracker_uri' => 'https://github.com/cyclotron3k/campaign_monitor_private/issues',
17
+ 'changelog_uri' => 'https://github.com/cyclotron3k/campaign_monitor_private/blob/master/CHANGELOG.md',
18
+ 'documentation_uri' => "https://github.com/cyclotron3k/campaign_monitor_private/blob/v#{CampaignMonitorPrivate::VERSION}/README.md",
19
+ 'source_code_uri' => 'https://github.com/cyclotron3k/campaign_monitor_private'
20
+ }
21
+
22
+ spec.require_paths = ['lib']
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+
27
+ spec.add_runtime_dependency 'mechanize', '~> 2.7'
28
+ spec.add_runtime_dependency 'rotp', '~> 5.0'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.17'
31
+ spec.add_development_dependency 'bundler-audit', '~> 0.6'
32
+ spec.add_development_dependency 'minitest', '~> 5.0'
33
+ spec.add_development_dependency 'pry', '~> 0.12'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ # spec.add_development_dependency 'webmock', '~> 3.5'
36
+
37
+ spec.required_ruby_version = '~> 2.3'
38
+ end
@@ -0,0 +1,191 @@
1
+ require 'campaign_monitor_private/version'
2
+ require 'mechanize'
3
+ require 'uri'
4
+ require 'rotp'
5
+
6
+ class CampaignMonitorPrivate
7
+ class Error < StandardError; end
8
+
9
+ def initialize(
10
+ username: ENV['CAMPAIGN_MONITOR_USERNAME'],
11
+ password: ENV['CAMPAIGN_MONITOR_PASSWORD'],
12
+ tfa_token: ENV['CAMPAIGN_MONITOR_2FA'],
13
+ tfa_secret: ENV['CAMPAIGN_MONITOR_SECRET'],
14
+ domain: ENV['CAMPAIGN_MONITOR_DOMAIN'],
15
+ default_customer: ENV['CAMPAIGN_MONITOR_DEFAULT_CUSTOMER']
16
+ )
17
+
18
+ raise ArgumentError, 'No username provided' unless username
19
+ raise ArgumentError, 'No password provided' unless password
20
+
21
+ @logged_in = false
22
+ @username = username
23
+ @password = password
24
+ @tfa_token = tfa_token
25
+ @totp = tfa_secret ? ROTP::TOTP.new(tfa_secret) : nil
26
+ @domain = domain
27
+ @default_customer = default_customer
28
+
29
+ @active_customer = nil
30
+ @list_cache = {}
31
+ @segment_cache = {}
32
+ @superuser = false
33
+ end
34
+
35
+ class JsonParser < Mechanize::Page
36
+ attr_reader :json
37
+ def initialize(uri=nil, response=nil, body=nil, code=nil)
38
+ @json = JSON.parse body
39
+ super uri, response, body, code
40
+ end
41
+ end
42
+
43
+ def agent
44
+ @agent ||= Mechanize.new do |a|
45
+ a.user_agent = "Campaign Monitor Client/#{VERSION}"
46
+ a.pluggable_parser['application/json'] = JsonParser
47
+ a.max_history = 1
48
+ end
49
+ end
50
+
51
+ def login
52
+ login_without_domain if @domain.nil?
53
+ login_with_domain
54
+ end
55
+
56
+ def set_active_customer(customer_name=@default_customer)
57
+ login unless @logged_in
58
+
59
+ # only superusers need to set the active customer
60
+ return true unless @superuser
61
+
62
+ raise Error, "customer_name required" if customer_name.nil?
63
+
64
+ return if @active_customer == customer_name
65
+
66
+ link = nil
67
+ counter = 0
68
+ loop do
69
+ link = agent.page.link_with(
70
+ text: /\A\s*#{customer_name}\s*\z/,
71
+ href: /\/\?ID=[\h]+\b/
72
+ )
73
+ break if link
74
+ raise Error, "Can't find #{customer_name}" if counter >= 1
75
+ uri = URI "https://#{@domain}.createsend.com/admin/"
76
+ agent.get uri
77
+ counter += 1
78
+ end
79
+
80
+ response = agent.click link
81
+
82
+ raise Error, "Invalid response code: #{response.code}" unless response.code == '200'
83
+ @active_customer = customer_name
84
+ end
85
+
86
+ def get_list_id_for(list_name)
87
+ set_active_customer unless @active_customer
88
+ raise Error, "No active customer" unless @active_customer
89
+
90
+ return @list_cache[@active_customer][list_name] if @list_cache.key? @active_customer
91
+
92
+ if agent.page.uri.to_s != "https://#{@domain}.createsend.com/subscribers/"
93
+ agent.get "https://#{@domain}.createsend.com/subscribers/"
94
+ end
95
+
96
+ @list_cache[@active_customer] = agent.page.links_with(
97
+ href: /listDetail\.aspx\?listID=[\h]+\b/
98
+ ).each_with_object({}) do |link, obj|
99
+ obj[link.text] = link.href[/[\h]+\z/]
100
+ end
101
+
102
+ @list_cache[@active_customer][list_name]
103
+
104
+ end
105
+
106
+ def get_segments_for(list_id)
107
+ login unless @logged_in
108
+
109
+ # @active_customer is not required!!
110
+
111
+ return @segment_cache[list_id] if @segment_cache.key? list_id
112
+
113
+ uri = URI "https://#{@domain}.createsend.com/subscribers/api/#{list_id}/segments"
114
+ response = agent.get uri
115
+ raise Error, "Invalid response code: #{response.code}" unless response.code == '200'
116
+ @segment_cache[list_id] = response.json["segments"]
117
+ end
118
+
119
+ private
120
+
121
+ def login_without_domain
122
+ uri = URI 'https://login.createsend.com/l'
123
+
124
+ response = agent.get(uri).form_with(
125
+ method: 'POST',
126
+ action: '/l'
127
+ ) do |form|
128
+ form.username = @username
129
+ form.password = @password
130
+ if @tfa_token
131
+ form.authenticator = @tfa_token
132
+ elsif @totp
133
+ form.authenticator = @totp.now
134
+ end
135
+ end.submit
136
+
137
+ raise Error, "Login error" if response.code != '200'
138
+
139
+ # response.json = {
140
+ # "MultipleAccounts" => false,
141
+ # "LoginStatus" => "Success",
142
+ # "SiteAddress" => "https://acme.createsend.com",
143
+ # "ErrorMessage" => "",
144
+ # "SessionExpired" => false,
145
+ # "Url" => "https://acme.createsend.com/login?Origin=Marketing",
146
+ # "DomainSwitchAddress" => "https://acme.createsend.com",
147
+ # "DomainSwitchAddressQueryString" => nil,
148
+ # "NeedsDomainSwitch" => false
149
+ # }
150
+
151
+ if response.json.key? 'DomainSwitchAddress'
152
+ dsa = response.json['DomainSwitchAddress']
153
+ raise Error, "Cross domain: #{dsa}" unless /\.createsend\.com\z/ === dsa
154
+ @domain = URI(dsa).host.split('.', 2).first
155
+ else
156
+ raise Error, "Couldn't determine subdomain"
157
+ end
158
+
159
+ true
160
+ end
161
+
162
+ def login_with_domain
163
+ raise Error, 'No subdomain specified' unless @domain
164
+
165
+ uri = URI "https://#{@domain}.createsend.com/login"
166
+
167
+ response = agent.get(uri).form_with(
168
+ method: 'POST',
169
+ action: '/login'
170
+ ) do |form|
171
+ form.username = @username
172
+ form.password = @password
173
+ if @tfa_token
174
+ form.authenticator = @tfa_token
175
+ elsif @totp
176
+ form.authenticator = @totp.now
177
+ end
178
+ end.submit
179
+
180
+ raise Error, "Login error" if response.code != '200'
181
+
182
+ superuser_check
183
+
184
+ @logged_in = true
185
+ end
186
+
187
+ def superuser_check
188
+ @superuser = !agent.page.link_with(text: /Clients/, href: '/admin/clients/').nil?
189
+ end
190
+
191
+ end
@@ -0,0 +1,3 @@
1
+ class CampaignMonitorPrivate
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: campaign_monitor_private
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - cyclotron3k
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rotp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler-audit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ description:
112
+ email:
113
+ - aidan.samuel@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - CHANGELOG.md
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - campaign_monitor_private.gemspec
129
+ - lib/campaign_monitor_private.rb
130
+ - lib/campaign_monitor_private/version.rb
131
+ homepage: https://github.com/cyclotron3k/campaign_monitor_private
132
+ licenses:
133
+ - MIT
134
+ metadata:
135
+ bug_tracker_uri: https://github.com/cyclotron3k/campaign_monitor_private/issues
136
+ changelog_uri: https://github.com/cyclotron3k/campaign_monitor_private/blob/master/CHANGELOG.md
137
+ documentation_uri: https://github.com/cyclotron3k/campaign_monitor_private/blob/v0.1.0/README.md
138
+ source_code_uri: https://github.com/cyclotron3k/campaign_monitor_private
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '2.3'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubygems_version: 3.0.3
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: A screen-scraper to retrieve vital information not available via the public
158
+ API
159
+ test_files: []