dsiemailhelper 0.0.1 → 0.0.2
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 +4 -4
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dsiemailhelper.gemspec +39 -0
- data/lib/dsiemailhelper.rb +70 -69
- data/lib/dsiemailhelper/version.rb +3 -0
- metadata +76 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d9ab956eb4a63a9fe7ac2058c0b6a198f03922417bf9649233e9b105898d5a
|
4
|
+
data.tar.gz: 3ff39dafad06236261e35d3f49b6d581fbcc6983febc402f516563b5704bb4fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41766dc265657c87aa256e44bd58358d727d90dfde6a933ff05895b3085d21eb15b4d90cc0c2419c75a7650e61be4d4dad26a2549ca1bd29a2cf08839393dd9f
|
7
|
+
data.tar.gz: 0b4e4551b4cdd2a5d60b80a85606b0b641bc3425308f715936d394a6ab09d890be04fcd4bab55d10a919c94b4dda4e5807b495fd867b4f8ca50e68a55d140545
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Dsiemailhelper
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dsiemailhelper`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'dsiemailhelper'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install dsiemailhelper
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dsiemailhelper.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dsiemailhelper"
|
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,39 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "dsiemailhelper/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dsiemailhelper"
|
8
|
+
spec.version = DSIEmailHelper::VERSION
|
9
|
+
spec.authors = ["Bilal Hussein"]
|
10
|
+
spec.email = ["bilal.hussein@daysmart.com"]
|
11
|
+
|
12
|
+
spec.summary = "DSI Email Helper"
|
13
|
+
spec.description = "Wrapper to slightly simplify interactions with gmail"
|
14
|
+
spec.homepage = "http://www.daysmart.com"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
38
|
+
spec.add_dependency "gmail", "~> 0.6.0"
|
39
|
+
end
|
data/lib/dsiemailhelper.rb
CHANGED
@@ -1,69 +1,70 @@
|
|
1
|
-
require
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
message
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
puts "
|
33
|
-
puts "
|
34
|
-
puts "
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
#
|
57
|
-
|
58
|
-
messages
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
1
|
+
require "dsiemailhelper/version"
|
2
|
+
require 'timeout'
|
3
|
+
require 'gmail'
|
4
|
+
|
5
|
+
|
6
|
+
module DSIEmailHelper
|
7
|
+
|
8
|
+
HTTPS_REGEXP = /https?:\/\/[\S]+/
|
9
|
+
|
10
|
+
def self.connect
|
11
|
+
# using connect! because only it will throw an exception if an error occurs
|
12
|
+
# during the connection process with gmail
|
13
|
+
raise "Please ensure QA_INBOX_EMAIL and QA_INBOX_PASSWORD env vars are configured" unless ENV['QA_INBOX_EMAIL'] && ENV['QA_INBOX_PASSWORD']
|
14
|
+
@inbox = Gmail.connect!(ENV['QA_INBOX_EMAIL'], ENV['QA_INBOX_PASSWORD'])
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_all_emails
|
18
|
+
# returns an array of Message objects
|
19
|
+
@inbox.inbox.emails
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find_email_by_gmail_search(search_string, start_time, acceptable_offset=0)
|
23
|
+
message = nil
|
24
|
+
Timeout.timeout(120) do
|
25
|
+
while filter_messages_by_time(@inbox.inbox.find(gm: search_string), start_time, acceptable_offset).length < 1
|
26
|
+
sleep 0.5
|
27
|
+
end
|
28
|
+
message = filter_messages_by_time(@inbox.inbox.find(gm: search_string), start_time, acceptable_offset)[-1]
|
29
|
+
message
|
30
|
+
end
|
31
|
+
rescue Timeout::Error => e
|
32
|
+
puts "Search string passed: #{search_string}"
|
33
|
+
puts "Start time passed: #{start_time} (offset: #{acceptable_offset})."
|
34
|
+
puts "Messages matching search string: #{@inbox.inbox.find(gm: search_string)}"
|
35
|
+
puts "Message: #{message || @inbox.inbox.find(gm: search_string)}"
|
36
|
+
raise e
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.filter_messages_by_time(messages, time, acceptable_offset=0)
|
40
|
+
messages.delete_if { | message |
|
41
|
+
message.message.date.to_time.to_f <= time.to_time.round.to_f - acceptable_offset
|
42
|
+
}
|
43
|
+
messages
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.get_email_body(message)
|
47
|
+
# expects a Message object and returns the body of the email without encoding
|
48
|
+
message.text_part.body.decoded
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.parse_link_from_body(decoded_message)
|
52
|
+
decoded_message.scan(HTTPS_REGEXP)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get_most_recent_email
|
56
|
+
# Noticed the most recent email in the inbox folder always has the highest index,
|
57
|
+
# so we can use the size of the array to determine what the most recent message is
|
58
|
+
messages = get_all_emails
|
59
|
+
messages[messages.length - 1]
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.get_newest_password_reset_link(email)
|
63
|
+
message = find_email_by_gmail_search("subject: Update Your Password to: #{email}", Date.today)
|
64
|
+
body = get_email_body(message)
|
65
|
+
# TODO: Archiving doesn't seem to be working, need to look into why
|
66
|
+
message.delete!
|
67
|
+
parse_link_from_body(body)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
metadata
CHANGED
@@ -1,26 +1,94 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsiemailhelper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bilal Hussein
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
12
|
-
dependencies:
|
11
|
+
date: 2019-01-08 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: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
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.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: gmail
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.6.0
|
13
69
|
description: Wrapper to slightly simplify interactions with gmail
|
14
|
-
email:
|
70
|
+
email:
|
71
|
+
- bilal.hussein@daysmart.com
|
15
72
|
executables: []
|
16
73
|
extensions: []
|
17
74
|
extra_rdoc_files: []
|
18
75
|
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- dsiemailhelper.gemspec
|
19
85
|
- lib/dsiemailhelper.rb
|
86
|
+
- lib/dsiemailhelper/version.rb
|
20
87
|
homepage: http://www.daysmart.com
|
21
|
-
licenses:
|
22
|
-
|
23
|
-
|
88
|
+
licenses: []
|
89
|
+
metadata:
|
90
|
+
allowed_push_host: https://rubygems.org
|
91
|
+
homepage_uri: http://www.daysmart.com
|
24
92
|
post_install_message:
|
25
93
|
rdoc_options: []
|
26
94
|
require_paths:
|