kono_mailup 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/README.md +24 -0
- data/app/controllers/kono_mailup/application_controller.rb +1 -1
- data/app/controllers/kono_mailup/tokens_controller.rb +12 -9
- data/db/migrate/20171124083941_create_settings.rb +1 -1
- data/lib/generators/kono_mailup/install/install_generator.rb +6 -4
- data/lib/generators/kono_mailup/install/templates/initializers.rb +4 -0
- data/lib/kono_mailup.rb +5 -0
- data/lib/kono_mailup/engine.rb +4 -0
- data/lib/kono_mailup/version.rb +1 -1
- data/vendor/mailup-ruby/lib/mailup.rb +229 -0
- data/vendor/mailup-ruby/lib/mailup/console/base.rb +115 -0
- data/vendor/mailup-ruby/lib/mailup/console/email.rb +80 -0
- data/vendor/mailup-ruby/lib/mailup/console/group.rb +125 -0
- data/vendor/mailup-ruby/lib/mailup/console/images.rb +69 -0
- data/vendor/mailup-ruby/lib/mailup/console/import.rb +46 -0
- data/vendor/mailup-ruby/lib/mailup/console/list.rb +913 -0
- data/vendor/mailup-ruby/lib/mailup/console/recipient.rb +70 -0
- data/vendor/mailup-ruby/lib/mailup/console/user.rb +77 -0
- data/vendor/mailup-ruby/lib/mailup/errors.rb +18 -0
- data/vendor/mailup-ruby/lib/mailup/public/base.rb +18 -0
- data/vendor/mailup-ruby/lib/mailup/public/console.rb +75 -0
- data/vendor/mailup-ruby/lib/mailup/stats/base.rb +41 -0
- data/vendor/mailup-ruby/lib/mailup/stats/message.rb +284 -0
- data/vendor/mailup-ruby/lib/mailup/stats/recipient.rb +303 -0
- data/vendor/mailup-ruby/lib/mailup/version.rb +4 -0
- data/vendor/mailup-ruby/rails/init.rb +1 -0
- data/vendor/omniauth-mailup/lib/omniauth-mailup.rb +2 -0
- data/vendor/omniauth-mailup/lib/omniauth-mailup/version.rb +5 -0
- data/vendor/omniauth-mailup/lib/omniauth/strategies/mailup.rb +41 -0
- metadata +45 -12
- data/README.rdoc +0 -3
- data/app/assets/images/kono_mailup/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f6e5c55e624989a65b2412be8af0ee4869ddee3
|
4
|
+
data.tar.gz: 5a074578cecaacf1118f0b980e65ed3d9f37c653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed61f652ddd1e2971fc44a95b1c1f66efa7fb6c7ade15710148bedde9b457ff3e1879be4ca5dc56411d09b0ab52a97ba04c3c69d5d54de68a91473922c5a7d5b
|
7
|
+
data.tar.gz: 8a670c52c54aad88ab87da3263214129e9e8ccb4d56399c38c3047f63f82b7b283cd18fcd2b9fdfe987f420ecde568468659229a935420feb1540194528b0e50
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
**KonoMailup**
|
2
|
+
|
3
|
+
**Description**<br>
|
4
|
+
KonoMailup is a Mailup layer for rails applications that
|
5
|
+
provides configuration and saving of user tokens; <br>
|
6
|
+
with mailup gems for autentication/authorization and api connector
|
7
|
+
|
8
|
+
|
9
|
+
**Installation**
|
10
|
+
|
11
|
+
Add To your Gemfile
|
12
|
+
|
13
|
+
gem 'kono_mailup', '~> 0.0.1'
|
14
|
+
|
15
|
+
OR Install directly
|
16
|
+
|
17
|
+
gem install kono_mailup
|
18
|
+
|
19
|
+
Then in your rail application folder
|
20
|
+
|
21
|
+
bin/rails g kono_mailup:install
|
22
|
+
bin/rake kono_mailup:install:migrations
|
23
|
+
|
24
|
+
Remember to configure the file created in the initilizers
|
@@ -1,15 +1,18 @@
|
|
1
|
-
|
2
|
-
class TokensController < ApplicationController
|
1
|
+
class KonoMailup::TokensController < KonoMailup::ApplicationController
|
3
2
|
|
4
|
-
|
3
|
+
def create
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
KonoMailup::API.save_tokens(token: request.env['omniauth.auth'][:credentials][:token],
|
6
|
+
refresh_token: request.env['omniauth.auth'][:credentials][:refresh_token],
|
7
|
+
expires_at: request.env['omniauth.auth'][:credentials][:expires_at])
|
9
8
|
|
10
|
-
|
9
|
+
action_after_create
|
10
|
+
end
|
11
11
|
|
12
|
-
end
|
13
12
|
|
13
|
+
private
|
14
|
+
def action_after_create
|
15
|
+
redirect_to root_path, notice: 'Successfully token configuration'
|
14
16
|
end
|
15
|
-
|
17
|
+
|
18
|
+
end
|
@@ -3,16 +3,18 @@ module KonoMailup
|
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
4
|
source_root File.expand_path('../templates', __FILE__)
|
5
5
|
|
6
|
+
class_option :disable_routes, type: :boolean, default: false
|
7
|
+
|
6
8
|
desc "Creates Initializers"
|
7
9
|
|
8
10
|
def copy_initializer
|
9
11
|
|
10
12
|
template "initializers.rb", "config/initializers/kono_mailup.rb"
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
unless options['disable_routes']
|
15
|
+
route "get '/auth/mailup/callback', to: 'kono_mailup/tokens#create'"
|
16
|
+
route 'mount KonoMailup::Engine => "/kono_mailup"'
|
17
|
+
end
|
16
18
|
|
17
19
|
end
|
18
20
|
|
data/lib/kono_mailup.rb
CHANGED
@@ -22,6 +22,11 @@ module KonoMailup
|
|
22
22
|
mattr_accessor :mailup_client_secret
|
23
23
|
@@mailup_client_secret = 'XXXXXXXXXX'
|
24
24
|
|
25
|
+
##
|
26
|
+
# Controller from where the engine inherit
|
27
|
+
mattr_accessor :base_controller
|
28
|
+
@@base_controller = Proc.new { ::ApplicationController }
|
29
|
+
|
25
30
|
|
26
31
|
# Default way to setup KonoMailup. Run "rails generate kono_mailup_install" to create
|
27
32
|
# a fresh initializer with all configuration values.
|
data/lib/kono_mailup/engine.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
#Remove this after using correct gems
|
2
|
+
$:.unshift File.expand_path("../../../vendor/omniauth-mailup/lib",__FILE__)
|
3
|
+
$:.unshift File.expand_path("../../../vendor/mailup-ruby/lib",__FILE__)
|
4
|
+
|
1
5
|
module KonoMailup
|
2
6
|
class Engine < ::Rails::Engine
|
3
7
|
isolate_namespace KonoMailup
|
data/lib/kono_mailup/version.rb
CHANGED
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
require 'multi_json'
|
3
|
+
require "net/https"
|
4
|
+
require 'json'
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
require 'mailup/version'
|
8
|
+
require 'mailup/errors'
|
9
|
+
require 'mailup/console/base'
|
10
|
+
require 'mailup/console/email'
|
11
|
+
require 'mailup/console/group'
|
12
|
+
require 'mailup/console/images'
|
13
|
+
require 'mailup/console/import'
|
14
|
+
require 'mailup/console/list'
|
15
|
+
require 'mailup/console/recipient'
|
16
|
+
require 'mailup/console/user'
|
17
|
+
require 'mailup/public/base'
|
18
|
+
require 'mailup/public/console'
|
19
|
+
require 'mailup/stats/base'
|
20
|
+
require 'mailup/stats/message'
|
21
|
+
require 'mailup/stats/recipient'
|
22
|
+
|
23
|
+
module MailUp
|
24
|
+
class API
|
25
|
+
attr_accessor :access_token, :debug, :host, :path, :credentials
|
26
|
+
|
27
|
+
# Initialize a new (thread-safe) API instance.
|
28
|
+
#
|
29
|
+
# @param [Hash] credentials for connecting to the MailUp API.
|
30
|
+
# * client_id [String]
|
31
|
+
# * client_secret [String]
|
32
|
+
# * oauth [Hash]
|
33
|
+
# * token [String]
|
34
|
+
# * refresh_token [String]
|
35
|
+
# * expires_at [Integer]
|
36
|
+
# @param [Boolean] debug whether or not to raise errors.
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
#
|
40
|
+
# credentials = {
|
41
|
+
# client_id: "1324567890",
|
42
|
+
# client_secret: "123abc456def",
|
43
|
+
# oauth: {
|
44
|
+
# token: "1324567890",
|
45
|
+
# refresh_token: "1324567890",
|
46
|
+
# expires_at: 123456789,
|
47
|
+
# }
|
48
|
+
# }
|
49
|
+
# mailup = MailUp::API.new(credentials)
|
50
|
+
#
|
51
|
+
def initialize(credentials=nil, debug=false)
|
52
|
+
@debug = debug
|
53
|
+
@host = 'https://services.mailup.com'
|
54
|
+
@path = ''
|
55
|
+
@credentials = credentials
|
56
|
+
|
57
|
+
# Validate the credentials
|
58
|
+
raise Error.new, 'MailUp credentials missing' if credentials.nil? or !credentials.is_a?(Hash)
|
59
|
+
[:client_id, :client_secret, :oauth].each do |key|
|
60
|
+
raise Error.new, "MailUp credentials must include a #{key.to_s} key" unless credentials.has_key?(key)
|
61
|
+
end
|
62
|
+
raise Error.new, 'MailUp credentials :oauth must be a hash' unless credentials[:oauth].is_a?(Hash)
|
63
|
+
[:token, :refresh_token, :expires_at].each do |key|
|
64
|
+
raise Error.new, "MailUp credentials :oauth hash must include a #{key.to_s} key" unless credentials[:oauth].has_key?(key)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Create a OAuth2 client instance
|
68
|
+
client = OAuth2::Client.new(
|
69
|
+
credentials[:client_id],
|
70
|
+
credentials[:client_secret],
|
71
|
+
site: @host,
|
72
|
+
authorize_url: "/Authorization/OAuth/LogOn",
|
73
|
+
token_url: "/Authorization/OAuth/Token",
|
74
|
+
raise_errors: @debug
|
75
|
+
)
|
76
|
+
|
77
|
+
# Create an access_token instance
|
78
|
+
@access_token = OAuth2::AccessToken.new(
|
79
|
+
client,
|
80
|
+
credentials[:oauth][:token],
|
81
|
+
{
|
82
|
+
refresh_token: credentials[:oauth][:refresh_token],
|
83
|
+
expires_at: credentials[:oauth][:expires_at]
|
84
|
+
}
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Make a request with the Access Token.
|
89
|
+
#
|
90
|
+
# @param [Symbol] verb the HTTP request method
|
91
|
+
# @param [String] path the HTTP URL path of the request
|
92
|
+
# @param [Hash] opts the options to make the request with
|
93
|
+
#
|
94
|
+
def request(method, path, opts={}, &block) # :nodoc:
|
95
|
+
unless @access_token == nil
|
96
|
+
# Refresh token if needed
|
97
|
+
@access_token = @access_token.refresh! if @access_token.expired?
|
98
|
+
# Ensure the body is JSON
|
99
|
+
opts[:body] = MultiJson.dump(opts[:body]) if opts[:body]
|
100
|
+
# Set the headers
|
101
|
+
opts[:headers] ||= {}
|
102
|
+
opts[:headers].merge!(headers)
|
103
|
+
# Make the request
|
104
|
+
req = @access_token.send(method, path, opts)
|
105
|
+
# Handle the response
|
106
|
+
handle_response(req)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Make a request with for Provisioning Calls.
|
111
|
+
#
|
112
|
+
# @param [Symbol] verb the HTTP request method
|
113
|
+
# @param [String] path the HTTP URL path of the request
|
114
|
+
# @param [Hash] opts the options to make the request with
|
115
|
+
#
|
116
|
+
def provisioning_request(path, body = nil) # :nodoc:
|
117
|
+
uri = URI.parse(@host)
|
118
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
119
|
+
http.use_ssl = true
|
120
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
121
|
+
|
122
|
+
req = Net::HTTP::Post.new(path, initheader = {'Content-Type' =>'application/json'})
|
123
|
+
req.basic_auth @credentials[:client_id], @credentials[:client_secret]
|
124
|
+
req.body = body.to_json
|
125
|
+
|
126
|
+
http.request(req).body.to_json
|
127
|
+
end
|
128
|
+
|
129
|
+
# Make a GET request with the Access Token
|
130
|
+
# @see #request
|
131
|
+
#
|
132
|
+
def get(path, opts={}, &block) # :nodoc:
|
133
|
+
request(:get, path, opts, &block)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Make a POST request with the Access Token
|
137
|
+
# @see #request
|
138
|
+
#
|
139
|
+
def post(path, opts={}, &block) # :nodoc:
|
140
|
+
request(:post, path, opts, &block)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Make a PUT request with the Access Token
|
144
|
+
# @see #request
|
145
|
+
#
|
146
|
+
def put(path, opts={}, &block) # :nodoc:
|
147
|
+
request(:put, path, opts, &block)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Make a PATCH request with the Access Token
|
151
|
+
# @see #request
|
152
|
+
#
|
153
|
+
def patch(path, opts={}, &block) # :nodoc:
|
154
|
+
request(:patch, path, opts, &block)
|
155
|
+
end
|
156
|
+
|
157
|
+
# Make a DELETE request with the Access Token
|
158
|
+
# @see #request
|
159
|
+
#
|
160
|
+
def delete(path, opts={}, &block) # :nodoc:
|
161
|
+
request(:delete, path, opts, &block)
|
162
|
+
end
|
163
|
+
|
164
|
+
# Handle the response of a request
|
165
|
+
def handle_response(response) # :nodoc:
|
166
|
+
case response.status
|
167
|
+
when 400
|
168
|
+
raise BadRequest.new response.parsed
|
169
|
+
when 401
|
170
|
+
raise Unauthorized.new
|
171
|
+
when 404
|
172
|
+
raise NotFound.new
|
173
|
+
when 400...500
|
174
|
+
raise ClientError.new response.parsed
|
175
|
+
when 500...600
|
176
|
+
raise ServerError.new
|
177
|
+
else
|
178
|
+
case response.body
|
179
|
+
when ''
|
180
|
+
true
|
181
|
+
when is_a?(Integer)
|
182
|
+
response.body
|
183
|
+
else
|
184
|
+
response.parsed
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# Set the request headers
|
190
|
+
def headers # :nodoc:
|
191
|
+
{
|
192
|
+
'User-Agent' => "mailup-ruby-#{VERSION}",
|
193
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
194
|
+
'Accept' => 'application/json'
|
195
|
+
}
|
196
|
+
end
|
197
|
+
|
198
|
+
# Access the console API methods
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
#
|
202
|
+
# lists = mailup.console.user.lists
|
203
|
+
#
|
204
|
+
def console
|
205
|
+
Console::Base.new self
|
206
|
+
end
|
207
|
+
|
208
|
+
# Access the public API methods
|
209
|
+
#
|
210
|
+
# @example
|
211
|
+
#
|
212
|
+
# activation = mailup.public.activation.new(...)
|
213
|
+
#
|
214
|
+
def public
|
215
|
+
Public::Base.new self
|
216
|
+
end
|
217
|
+
|
218
|
+
# Access the email statistics API methods
|
219
|
+
#
|
220
|
+
# @example
|
221
|
+
#
|
222
|
+
# views = mailup.stats.message.views_count(1)
|
223
|
+
#
|
224
|
+
def stats
|
225
|
+
Stats::Base.new self
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module MailUp
|
2
|
+
module Console
|
3
|
+
class Base
|
4
|
+
attr_accessor :api
|
5
|
+
|
6
|
+
def initialize(api) # :nodoc:
|
7
|
+
@api = api
|
8
|
+
@api.path = "/API/v#{MailUp::API_VERSION}/Rest/ConsoleService.svc/Console"
|
9
|
+
end
|
10
|
+
|
11
|
+
# Create an email object
|
12
|
+
#
|
13
|
+
# @return [MailUp::Console::Email]
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
#
|
17
|
+
# email = mailup.console.email
|
18
|
+
#
|
19
|
+
def email
|
20
|
+
Email.new @api
|
21
|
+
end
|
22
|
+
|
23
|
+
# Create a group object
|
24
|
+
#
|
25
|
+
# @param [Integer] id The group_id of the group to access.
|
26
|
+
#
|
27
|
+
# @return [MailUp::Console::Group]
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
#
|
31
|
+
# group = mailup.console.group(1)
|
32
|
+
#
|
33
|
+
def group(id)
|
34
|
+
Group.new id, @api
|
35
|
+
end
|
36
|
+
|
37
|
+
# Create an images object
|
38
|
+
#
|
39
|
+
# @return [MailUp::Console::Images]
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
#
|
43
|
+
# images = mailup.console.images
|
44
|
+
#
|
45
|
+
def images
|
46
|
+
Images.new @api
|
47
|
+
end
|
48
|
+
|
49
|
+
# Create an import object
|
50
|
+
#
|
51
|
+
# @param [Integer] idImport The ID of the import process.
|
52
|
+
#
|
53
|
+
# @return [MailUp::Console::Import]
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
#
|
57
|
+
# import = mailup.console.import(9)
|
58
|
+
#
|
59
|
+
def import(id)
|
60
|
+
Import.new id, @api
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create a list object
|
64
|
+
#
|
65
|
+
# @param [Integer] id The list_id of the list to access.
|
66
|
+
#
|
67
|
+
# @return [MailUp::Console::List]
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
#
|
71
|
+
# list = mailup.console.list(2)
|
72
|
+
#
|
73
|
+
def list(id)
|
74
|
+
List.new id, @api
|
75
|
+
end
|
76
|
+
|
77
|
+
# Create a public methods object
|
78
|
+
#
|
79
|
+
# @return [MailUp::Console::List]
|
80
|
+
#
|
81
|
+
# @example
|
82
|
+
#
|
83
|
+
# list = mailup.console.list(2)
|
84
|
+
#
|
85
|
+
def public
|
86
|
+
Public::Base.new @api
|
87
|
+
end
|
88
|
+
|
89
|
+
# Create a recipient object
|
90
|
+
#
|
91
|
+
# @return [MailUp::Console::Recipient]
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
#
|
95
|
+
# recipient = mailup.console.recipient
|
96
|
+
#
|
97
|
+
def recipient
|
98
|
+
Recipient.new @api
|
99
|
+
end
|
100
|
+
|
101
|
+
# Create a user object
|
102
|
+
#
|
103
|
+
# @return [MailUp::Console::User]
|
104
|
+
#
|
105
|
+
# @example
|
106
|
+
#
|
107
|
+
# user = mailup.console.user
|
108
|
+
#
|
109
|
+
def user
|
110
|
+
User.new @api
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|