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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a54b0021f6a6a02452513928c7a2a26444ba7d214b38fb4d56cd1093f1daf498
4
- data.tar.gz: 46ecf68e572bae394726c72359aa7fc38ed2dfdfa926f1a5aa1e9338ab200872
3
+ metadata.gz: 83d9ab956eb4a63a9fe7ac2058c0b6a198f03922417bf9649233e9b105898d5a
4
+ data.tar.gz: 3ff39dafad06236261e35d3f49b6d581fbcc6983febc402f516563b5704bb4fa
5
5
  SHA512:
6
- metadata.gz: fa1b22f5e64d88427a1a40bd44441a5ae194f8c8e07511a4c89ea6216db4a10c3f5de35d216a9aed88bbe197cf87958d1ecf38e50676df47eabe929c189f6abd
7
- data.tar.gz: 86ff6efdeeb69f59a4258d21902da2b1caf7ce3da4ade1e008d6bec5aa7587a54008d19f06881e1e9f75aed499413f4d6d87fe5924f4c705a5da40407decc774
6
+ metadata.gz: 41766dc265657c87aa256e44bd58358d727d90dfde6a933ff05895b3085d21eb15b4d90cc0c2419c75a7650e61be4d4dad26a2549ca1bd29a2cf08839393dd9f
7
+ data.tar.gz: 0b4e4551b4cdd2a5d60b80a85606b0b641bc3425308f715936d394a6ab09d890be04fcd4bab55d10a919c94b4dda4e5807b495fd867b4f8ca50e68a55d140545
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.4.3
7
+ before_install: gem install bundler -v 1.17.3
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 dsiemailhelper.gemspec
6
+ gemspec
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
@@ -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 "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,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,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
@@ -1,69 +1,70 @@
1
- require 'timeout'
2
- require 'gmail'
3
-
4
-
5
- module DSIEmailHelper
6
-
7
- HTTPS_REGEXP = /https?:\/\/[\S]+/
8
-
9
- def self.connect
10
- # using connect! because only it will throw an exception if an error occurs
11
- # during the connection process with gmail
12
- raise "Please ensure QA_INBOX_EMAIL and QA_INBOX_PASSWORD env vars are configured" unless ENV['QA_INBOX_EMAIL'] && ENV['QA_INBOX_PASSWORD']
13
- @inbox = Gmail.connect!(ENV['QA_INBOX_EMAIL'], ENV['QA_INBOX_PASSWORD'])
14
- end
15
-
16
- def self.get_all_emails
17
- # returns an array of Message objects
18
- @inbox.inbox.emails
19
- end
20
-
21
- def self.find_email_by_gmail_search(search_string, start_time, acceptable_offset=0)
22
- message = nil
23
- Timeout.timeout(120) do
24
- while filter_messages_by_time(@inbox.inbox.find(gm: search_string), start_time, acceptable_offset).length < 1
25
- sleep 0.5
26
- end
27
- message = filter_messages_by_time(@inbox.inbox.find(gm: search_string), start_time, acceptable_offset)[-1]
28
- message
29
- end
30
- rescue Timeout::Error => e
31
- puts "Search string passed: #{search_string}"
32
- puts "Start time passed: #{start_time} (offset: #{acceptable_offset})."
33
- puts "Messages matching search string: #{@inbox.inbox.find(gm: search_string)}"
34
- puts "Message: #{message || @inbox.inbox.find(gm: search_string)}"
35
- raise e
36
- end
37
-
38
- def self.filter_messages_by_time(messages, time, acceptable_offset=0)
39
- messages.delete_if { | message |
40
- message.message.date.to_time.to_f <= time.to_time.round.to_f - acceptable_offset
41
- }
42
- messages
43
- end
44
-
45
- def self.get_email_body(message)
46
- # expects a Message object and returns the body of the email without encoding
47
- message.text_part.body.decoded
48
- end
49
-
50
- def self.parse_link_from_body(decoded_message)
51
- decoded_message.scan(HTTPS_REGEXP)
52
- end
53
-
54
- def self.get_most_recent_email
55
- # Noticed the most recent email in the inbox folder always has the highest index,
56
- # so we can use the size of the array to determine what the most recent message is
57
- messages = get_all_emails
58
- messages[messages.length - 1]
59
- end
60
-
61
- def self.get_newest_password_reset_link(email)
62
- message = find_email_by_gmail_search("subject: Update Your Password to: #{email}", Date.today)
63
- body = get_email_body(message)
64
- # TODO: Archiving doesn't seem to be working, need to look into why
65
- message.delete!
66
- parse_link_from_body(body)
67
- end
68
-
69
- end
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
@@ -0,0 +1,3 @@
1
+ module DSIEmailHelper
2
+ VERSION = "0.0.2"
3
+ 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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bilal Hussein
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-07 00:00:00.000000000 Z
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: bilal.hussein@daysmart.com
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
- - MIT
23
- metadata: {}
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: