kono_mailup 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +26 -0
- data/app/assets/images/kono_mailup/.keep +0 -0
- data/app/assets/javascripts/kono_mailup/application.js +13 -0
- data/app/assets/stylesheets/kono_mailup/application.css +15 -0
- data/app/controllers/kono_mailup/application_controller.rb +3 -0
- data/app/controllers/kono_mailup/main_controller.rb +12 -0
- data/app/controllers/kono_mailup/test_apis_controller.rb +18 -0
- data/app/controllers/kono_mailup/tokens_controller.rb +15 -0
- data/app/helpers/kono_mailup/application_helper.rb +4 -0
- data/app/helpers/kono_mailup/main_helper.rb +4 -0
- data/app/models/kono_mailup/cfg.rb +7 -0
- data/app/views/kono_mailup/main/index.html.erb +0 -0
- data/app/views/kono_mailup/test_apis/list.html.erb +3 -0
- data/app/views/kono_mailup/tokens/create.html.erb +0 -0
- data/app/views/layouts/kono_mailup/application.html.erb +29 -0
- data/config/app.yml +15 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20171124083941_create_settings.rb +17 -0
- data/lib/generators/kono_mailup/install/USAGE +9 -0
- data/lib/generators/kono_mailup/install/install_generator.rb +22 -0
- data/lib/generators/kono_mailup/install/templates/initializers.rb +13 -0
- data/lib/kono_mailup.rb +32 -0
- data/lib/kono_mailup/api.rb +60 -0
- data/lib/kono_mailup/engine.rb +33 -0
- data/lib/kono_mailup/version.rb +3 -0
- data/lib/tasks/kono_mailup_tasks.rake +4 -0
- data/spec/dummy/.gitignore +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/kono_mailup.rb +13 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/dummy/config/secrets_example.yml +25 -0
- data/spec/dummy/db/migrate/20171124094841_create_settings.kono_mailup.rb +18 -0
- data/spec/dummy/db/schema.rb +27 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- metadata +265 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5490a86115b7c60d580d9d2c245b3b69877f50e5
|
4
|
+
data.tar.gz: 582c527df50614e1b19a7b191081178fdec89a95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38a4cb172052704977d7fb9f6f97ae0b31676541d086f5e0cd8b32fe97ad6491485b350d976e2951cb102bb0e1284a5c4bdea8465ef00711ba711b01e0cd3526
|
7
|
+
data.tar.gz: 9ffd1556ebd0a6e80c35f41e23747e713c3e8f413a31bc5a4b6b55e8216e51d7c47048edac5f5b764011d6a0c1f66dc8fd4b1dd8c77b64e3013c66637dc0c954
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Marino Bonetti
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'KonoMailup'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module KonoMailup
|
2
|
+
class TokensController < ApplicationController
|
3
|
+
|
4
|
+
def create
|
5
|
+
|
6
|
+
API.save_tokens(token: request.env['omniauth.auth'][:credentials][:token],
|
7
|
+
refresh_token: request.env['omniauth.auth'][:credentials][:refresh_token],
|
8
|
+
expires_at: request.env['omniauth.auth'][:credentials][:expires_at])
|
9
|
+
|
10
|
+
redirect_to root_path, notice: 'Successfully token configuration'
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>KonoMailup</title>
|
5
|
+
<%= stylesheet_link_tag "kono_mailup/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "kono_mailup/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<% if flash[:notice] %>
|
11
|
+
<div class="notice"><%= flash[:notice] %></div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<%= link_to 'Get Tokens', '/auth/mailup' %>
|
15
|
+
|
16
|
+
|
17
|
+
<% if KonoMailup::API.client_ready? %>
|
18
|
+
<div>
|
19
|
+
<h3>Test Api</h3>
|
20
|
+
<%= link_to "Get List", list_test_api_path %>
|
21
|
+
</div>
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
<div>
|
25
|
+
<%= yield %>
|
26
|
+
</div>
|
27
|
+
|
28
|
+
</body>
|
29
|
+
</html>
|
data/config/app.yml
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateSettings < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :settings do |t|
|
4
|
+
t.string :var, null: false
|
5
|
+
t.text :value, null: true
|
6
|
+
t.integer :thing_id, null: true
|
7
|
+
t.string :thing_type, null: true, limit: 30
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :settings, %i(thing_type thing_id var), unique: true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :settings
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module KonoMailup
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
desc "Creates Initializers"
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
|
10
|
+
template "initializers.rb", "config/initializers/kono_mailup.rb"
|
11
|
+
|
12
|
+
|
13
|
+
route "get '/auth/mailup/callback', to: 'kono_mailup/sessions#create'"
|
14
|
+
route 'mount KonoMailup::Engine => "/kono_mailup"'
|
15
|
+
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/kono_mailup.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "kono_mailup/engine"
|
2
|
+
|
3
|
+
module KonoMailup
|
4
|
+
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
|
7
|
+
autoload :Engine
|
8
|
+
autoload :API
|
9
|
+
|
10
|
+
eager_autoload do
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
##
|
16
|
+
# MAILUP_CLIENT_ID
|
17
|
+
mattr_accessor :mailup_client_id
|
18
|
+
@@mailup_client_id = 'XXXXXXXXXX'
|
19
|
+
|
20
|
+
##
|
21
|
+
# MAILUP_CLIENT_SECRET
|
22
|
+
mattr_accessor :mailup_client_secret
|
23
|
+
@@mailup_client_secret = 'XXXXXXXXXX'
|
24
|
+
|
25
|
+
|
26
|
+
# Default way to setup KonoMailup. Run "rails generate kono_mailup_install" to create
|
27
|
+
# a fresh initializer with all configuration values.
|
28
|
+
def self.setup
|
29
|
+
yield self
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
module KonoMailup
|
3
|
+
##
|
4
|
+
# Classe che si occupa restituire il client di mailup configurato
|
5
|
+
#
|
6
|
+
class API < DelegateClass(MailUp::API)
|
7
|
+
|
8
|
+
attr_accessor :original_api
|
9
|
+
|
10
|
+
def self.client_ready?
|
11
|
+
#TODO could be made better?
|
12
|
+
self.new
|
13
|
+
true
|
14
|
+
rescue Exception => e
|
15
|
+
Rails.logger.warn { "MailupClient not responding, #{e.message}" }
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(debug: false)
|
20
|
+
# build up file path/name in var tmpname...
|
21
|
+
|
22
|
+
@original_api = MailUp::API.new({
|
23
|
+
client_id: KonoMailup.mailup_client_id,
|
24
|
+
client_secret: KonoMailup.mailup_client_secret,
|
25
|
+
oauth: {
|
26
|
+
token: KonoMailup::Cfg.token,
|
27
|
+
refresh_token: KonoMailup::Cfg.refresh_token,
|
28
|
+
expires_at: KonoMailup::Cfg.expires_at
|
29
|
+
}
|
30
|
+
}, debug)
|
31
|
+
|
32
|
+
super(@original_api)
|
33
|
+
|
34
|
+
refresh_access_token
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def refresh_access_token
|
39
|
+
if self.access_token
|
40
|
+
if self.access_token.expired?
|
41
|
+
self.access_token = self.access_token.refresh!
|
42
|
+
|
43
|
+
API.save_tokens(token: self.access_token.token,
|
44
|
+
refresh_token: self.access_token.refresh_token,
|
45
|
+
expires_at: self.access_token.expires_at)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def self.save_tokens(token:, refresh_token:, expires_at:, expires: true)
|
52
|
+
KonoMailup::Cfg.token=token
|
53
|
+
KonoMailup::Cfg.refresh_token=refresh_token
|
54
|
+
KonoMailup::Cfg.expires_at=expires_at
|
55
|
+
KonoMailup::Cfg.expires=expires
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module KonoMailup
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace KonoMailup
|
4
|
+
|
5
|
+
|
6
|
+
require 'mailup'
|
7
|
+
require 'omniauth-mailup'
|
8
|
+
require 'rails-settings-cached'
|
9
|
+
|
10
|
+
config.eager_load_namespaces << KonoMailup
|
11
|
+
|
12
|
+
# config.autoload_paths << File.expand_path("../../lib/**/*.rb", __FILE__)
|
13
|
+
|
14
|
+
config.generators do |g|
|
15
|
+
g.test_framework :rspec
|
16
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
17
|
+
end
|
18
|
+
|
19
|
+
initializer 'kono_mailup.add_omniauthmiddleware' do |app|
|
20
|
+
app.config.middleware.use OmniAuth::Builder do
|
21
|
+
provider :mailup,
|
22
|
+
KonoMailup.mailup_client_id,
|
23
|
+
KonoMailup.mailup_client_secret
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
initializer 'kono_mailup.add_locales' do |app|
|
28
|
+
I18n.load_path += Dir[::KonoMailup::Engine.root.join('config', 'locales', '**', '*.{rb,yml}')]
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|