message_client 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: a903ae9c8302e905e49c9799dc44f5b6859e9fa88dca58af9bf86dd4f60d6fc8
4
+ data.tar.gz: f388ffccd180c6b39a62564c180a4e0add35a072c4a1ff5b0d125840b5daac1b
5
+ SHA512:
6
+ metadata.gz: db0ff19b4fbea88e28a08905af6bd27518e163559197421bbab009d70849c6bca7d16e5b42dcbde6ee34c3ab807375855c6e86a1dcb4c4560243340e4583386a
7
+ data.tar.gz: 5c7360595cdc3226c2f0feaae242cd07d2e44d10cae125a9c32510930542b5e95bea1414c6ec64bf4524b64e7e2930c36aead48c3670cd5fc22e01ebd008150c
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/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in message_client.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "pry-byebug"
data/Gemfile.lock ADDED
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ message_client (0.1.0)
5
+ railties (>= 5.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (6.1.4.1)
11
+ actionview (= 6.1.4.1)
12
+ activesupport (= 6.1.4.1)
13
+ rack (~> 2.0, >= 2.0.9)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
+ actionview (6.1.4.1)
18
+ activesupport (= 6.1.4.1)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
+ activesupport (6.1.4.1)
24
+ concurrent-ruby (~> 1.0, >= 1.0.2)
25
+ i18n (>= 1.6, < 2)
26
+ minitest (>= 5.1)
27
+ tzinfo (~> 2.0)
28
+ zeitwerk (~> 2.3)
29
+ builder (3.2.4)
30
+ byebug (11.1.3)
31
+ coderay (1.1.3)
32
+ concurrent-ruby (1.1.9)
33
+ crass (1.0.6)
34
+ diff-lcs (1.4.4)
35
+ erubi (1.10.0)
36
+ i18n (1.8.11)
37
+ concurrent-ruby (~> 1.0)
38
+ loofah (2.12.0)
39
+ crass (~> 1.0.2)
40
+ nokogiri (>= 1.5.9)
41
+ method_source (1.0.0)
42
+ mini_portile2 (2.6.1)
43
+ minitest (5.14.4)
44
+ nokogiri (1.12.5)
45
+ mini_portile2 (~> 2.6.1)
46
+ racc (~> 1.4)
47
+ pry (0.13.1)
48
+ coderay (~> 1.1)
49
+ method_source (~> 1.0)
50
+ pry-byebug (3.9.0)
51
+ byebug (~> 11.0)
52
+ pry (~> 0.13.0)
53
+ racc (1.6.0)
54
+ rack (2.2.3)
55
+ rack-test (1.1.0)
56
+ rack (>= 1.0, < 3)
57
+ rails-dom-testing (2.0.3)
58
+ activesupport (>= 4.2.0)
59
+ nokogiri (>= 1.6)
60
+ rails-html-sanitizer (1.4.2)
61
+ loofah (~> 2.3)
62
+ railties (6.1.4.1)
63
+ actionpack (= 6.1.4.1)
64
+ activesupport (= 6.1.4.1)
65
+ method_source
66
+ rake (>= 0.13)
67
+ thor (~> 1.0)
68
+ rake (12.3.3)
69
+ rspec (3.10.0)
70
+ rspec-core (~> 3.10.0)
71
+ rspec-expectations (~> 3.10.0)
72
+ rspec-mocks (~> 3.10.0)
73
+ rspec-core (3.10.1)
74
+ rspec-support (~> 3.10.0)
75
+ rspec-expectations (3.10.1)
76
+ diff-lcs (>= 1.2.0, < 2.0)
77
+ rspec-support (~> 3.10.0)
78
+ rspec-mocks (3.10.2)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.10.0)
81
+ rspec-support (3.10.3)
82
+ thor (1.1.0)
83
+ tzinfo (2.0.4)
84
+ concurrent-ruby (~> 1.0)
85
+ zeitwerk (2.5.1)
86
+
87
+ PLATFORMS
88
+ ruby
89
+
90
+ DEPENDENCIES
91
+ message_client!
92
+ pry-byebug
93
+ rake (~> 12.0)
94
+ rspec (~> 3.0)
95
+
96
+ BUNDLED WITH
97
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # MessageClient
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/message_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'message_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install message_client
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ 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).
30
+
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 "message_client"
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,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ module MessageClient
6
+ class Mailer
7
+ HTML_RAW_TEMPLATE = 'raw-html-integration'
8
+
9
+ attr_accessor :settings
10
+
11
+ def initialize(values)
12
+ build_settings(values)
13
+ end
14
+
15
+ def deliver!(mail)
16
+ message = {
17
+ sender: mail.sender || mail.from.first,
18
+ sender_email: mail.from.first,
19
+ subject: mail.subject,
20
+ recipients: mail.to,
21
+ reply_to: mail.reply_to,
22
+ template_name: HTML_RAW_TEMPLATE,
23
+ template_params: { raw_body: mail.body.raw_source },
24
+ attachments: parse_files(mail.attachments)
25
+ }
26
+
27
+ send_message(message)
28
+ end
29
+
30
+ private
31
+
32
+ def client
33
+ @client ||= Net::HTTP.new(uri.host, uri.port)
34
+ end
35
+
36
+ def send_message(message)
37
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
38
+ request = Net::HTTP::Post.new(uri)
39
+
40
+ request['Authorization'] = "Token token=#{settings[:token]}"
41
+ request.content_type = 'application/json'
42
+
43
+ request.body = message.to_json
44
+
45
+ http.request request
46
+ end
47
+ end
48
+
49
+ def parse_files(files)
50
+ files.map do |file|
51
+ {
52
+ type: file.content_type,
53
+ name: file.filename,
54
+ content: Base64.encode64(file.read)
55
+ }
56
+ end
57
+ end
58
+
59
+ def uri
60
+ @uri ||= URI("#{settings[:url]}/api/messages")
61
+ end
62
+
63
+ def build_settings(values)
64
+ base = {
65
+ url: ENV.fetch('MESSAGE_API_URL', nil),
66
+ token: ENV.fetch('MESSAGE_API_TOKEN', nil)
67
+ }
68
+
69
+ self.settings = base.merge(values)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MessageClient
4
+ class Railtie < ::Rails::Railtie
5
+ initializer 'message_client.initialize', before: :load_config_initializers do
6
+ MessageClient.add_action_mailer_delivery_method
7
+ end
8
+ end
9
+
10
+ def self.add_action_mailer_delivery_method(name = :message_api, options = {})
11
+ ActiveSupport.on_load(:action_mailer) do
12
+ add_delivery_method(name, MessageClient::Mailer, options)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module MessageClient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'message_client/version'
4
+ require 'message_client/mailer'
5
+ require 'message_client/railtie'
6
+
7
+ module MessageClient
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/message_client/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'message_client'
5
+ spec.version = MessageClient::VERSION
6
+ spec.authors = ['Emir Fernandes']
7
+ spec.email = ['emir.fernandes@snappler.com']
8
+
9
+ spec.summary = 'Message Client for message API, with Mailer for Rails app'
10
+ spec.description = spec.summary
11
+ spec.homepage = 'https://gitlab.snappler.com/gems/message_client'
12
+
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = spec.homepage
17
+ spec.metadata['changelog_uri'] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency('railties', '>= 5.2.0')
29
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: message_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Emir Fernandes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ description: Message Client for message API, with Mailer for Rails app
28
+ email:
29
+ - emir.fernandes@snappler.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README.md
39
+ - Rakefile
40
+ - bin/console
41
+ - bin/setup
42
+ - lib/message_client.rb
43
+ - lib/message_client/mailer.rb
44
+ - lib/message_client/railtie.rb
45
+ - lib/message_client/version.rb
46
+ - message_client.gemspec
47
+ homepage: https://gitlab.snappler.com/gems/message_client
48
+ licenses: []
49
+ metadata:
50
+ homepage_uri: https://gitlab.snappler.com/gems/message_client
51
+ source_code_uri: https://gitlab.snappler.com/gems/message_client
52
+ changelog_uri: https://gitlab.snappler.com/gems/message_client
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.1.4
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Message Client for message API, with Mailer for Rails app
72
+ test_files: []