mints 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef89ee973a9cb2bf2e4b77ad15e3481f7fc02e566f47099c7c44b94bdd3cb757
4
- data.tar.gz: d40cf8e0445ce333ad735403f767622cc6428b7ab4f334040a542b0340d4eb49
3
+ metadata.gz: fe61a6e467b376dbb5f8b648cbdf40cf8dcb1f0ef8da711e7d19a901ba2c831d
4
+ data.tar.gz: 3c8f10f1f7cec5dcddaa47a06061c68025350d167045705eefb2b66784849451
5
5
  SHA512:
6
- metadata.gz: d8c404e2894b99bdb95a5db340ca9f47785cfec00fa6c3648b29a9b1c00e65a4a02569ccfdd5086e1911e468c942e93db214d21d2ac11c219934c66d9d3e9478
7
- data.tar.gz: 2c24fc60a2cd29d377bd445cee14fbd611ddc728155eb7e3f2c545eec203100a64254b09e981128f28849dc7a95c1bded45bd592ebe67af3ed794f6e0b786809
6
+ metadata.gz: 8e60803a59051e32a64cb1be95aedf06f98d3ea1ee5ddf1c66f3be2532b6dad76a652e5b38198c4f5cf88c30cf5647b84ef21c07d29d9bc8544d784a26042606
7
+ data.tar.gz: 88f83771ef24027d16ef3b1b145c70ec9e357e9f300522aee58c113522f00d66e8e05a6301c54c6b0a6846bb6a78b5555d1499d10adb8539d0b531f5ef543a15
data/Gemfile CHANGED
@@ -2,4 +2,5 @@ source :rubygems
2
2
 
3
3
  gem 'json'
4
4
  gem 'httparty'
5
- gem 'addressable'
5
+ gem 'addressable'
6
+ gem 'rails-reverse-proxy', '~> 0.9.1'
data/Readme.md CHANGED
@@ -29,18 +29,56 @@ con = Mints::User.new(mints_url, api_key)
29
29
  con.login(email, password)
30
30
  con.get_contacts
31
31
  ```
32
+ ## Generate mints files
33
+ This command will generate the mints_config.yml file, API controlles and routes to have available the mints endpoints
34
+ ```bash
35
+ rails generate mints_files
36
+ ```
32
37
  ## Contact tracking usage
33
- Your app controller need to be inherited from Mints::BaseController
38
+ Your app controller needs to be inherited from Mints::BaseController
34
39
  ```ruby
35
40
  # application_controller.rb
36
41
 
37
42
  class ApplicationController < Mints::BaseController
38
43
  end
39
44
  ```
40
- This controller will make the following class variables available:
45
+ This heritance will make the following class variables available:
46
+
47
+ | Variable | Description |
48
+ | --- | :---: |
49
+ | @host | Host defined in mints_config.yml file |
50
+ | @api_key | API key defined in mints_config.yml file |
51
+ | @mints_pub | An already instanced public client |
52
+ | @contact_token | A token used by mints to identify the contact |
53
+ | @visit_id | An identifier of the visit registered |
54
+ | @mints_contact | An already instanced contact client (not usable until call the contact login method) |
55
+
56
+ And the following controller methods:
57
+ | Method | Parameters | Return value | Description |
58
+ | --- | :---: | :---: | :---: |
59
+ | mints_contact_signed_in? | none | boolean | Indicates if the contact has an active session |
60
+ | mints_contact_login | email, password| void | Starts a contact session |
61
+ | mints_contact_logout | none | void | Ends a contact session |
62
+
63
+ ## Admin controller usage
64
+ If want to have a private section where only a mints user can acces and use the private user api is needed to inherit from the AdminBaseController.
65
+
66
+ ```ruby
67
+ # admin_controller.rb
68
+
69
+ class AdminController < Mints::AdminBaseController
70
+ end
71
+ ```
72
+
73
+ This heritance will make the following class variables available:
74
+ | Variable | Description |
75
+ | --- | :---: |
76
+ | @host | Host defined in mints_config.yml file |
77
+ | @api_key | API key defined in mints_config.yml file |
78
+ | @mints_user | An already instanced user client (not usable until call the user login method) |
41
79
 
42
- | Variable | Description |
43
- | --- | :---: |
44
- | @mints_pub | An already instanced public client |
45
- | @contact_token | A token used by mints to identify the contact |
46
- | @visit_id | An identifier of the visit registered |
80
+ And the following controller methods:
81
+ | Method | Parameters | Return value | Description |
82
+ | --- | :---: | :---: | :---: |
83
+ | mints_user_login | email, password| void | Starts a user session |
84
+ | mints_user_logout | none | void | Ends a user session |
data/lib/client.rb CHANGED
@@ -9,21 +9,20 @@ module Mints
9
9
  attr_reader :base_url
10
10
  attr_accessor :session_token
11
11
 
12
- def initialize(host, api_key, scope = nil, session_token = nil)
12
+ def initialize(host, api_key, scope = nil, session_token = nil, debug = false)
13
13
  @host = host
14
14
  @api_key = api_key
15
15
  @session_token = session_token
16
+ @debug = debug
16
17
  self.set_scope(scope)
17
18
  end
18
19
 
19
20
  def raw(action, url, options = nil, data = nil, base_url = nil)
20
- base_url = @base_url if !base_url
21
-
21
+ base_url = @base_url if !base_url
22
+ uri = ""
22
23
  if (options && options.class == Hash)
23
24
  uri = Addressable::URI.new
24
25
  uri.query_values = options
25
- else
26
- uri = ""
27
26
  end
28
27
 
29
28
  full_url = "#{@host}#{base_url}#{url}#{uri}"
@@ -46,7 +45,8 @@ module Mints
46
45
  return parsed_response
47
46
  end
48
47
 
49
- def method_missing(name, *args, &block)
48
+ def method_missing(name, *args, &block)
49
+ puts name
50
50
  name.to_s.include?("__") ? separator = "__" : separator = "_"
51
51
  # split the name to identify their elements
52
52
  name_spplited = name.to_s.split(separator)
@@ -144,16 +144,38 @@ module Mints
144
144
  ##### HTTTP CLIENTS ######
145
145
  # Simple HTTP GET
146
146
  def http_get(url, headers = nil)
147
+ if @debug
148
+ puts "Url:"
149
+ puts url
150
+ puts "Headers:"
151
+ puts headers
152
+ end
147
153
  return headers ? HTTParty.get(url, :headers => headers) : HTTParty.get(url)
148
154
  end
149
155
 
150
156
  # Simple HTTP POST
151
157
  def http_post(url, headers = nil, data = nil)
158
+ if @debug
159
+ puts "Url:"
160
+ puts url
161
+ puts "Headers:"
162
+ puts headers
163
+ puts "Data:"
164
+ puts data
165
+ end
152
166
  return headers ? HTTParty.post(url, :headers=> headers, :body => data) : HTTParty.post(url, :body => data)
153
167
  end
154
168
 
155
169
  # Simple HTTP PUT
156
170
  def http_put(url, headers = nil, data = nil)
171
+ if @debug
172
+ puts "Url:"
173
+ puts url
174
+ puts "Headers:"
175
+ puts headers
176
+ puts "Data:"
177
+ puts data
178
+ end
157
179
  return headers ? HTTParty.put(url, :headers=> headers, :body => data) : HTTParty.put(url, :body => data)
158
180
  end
159
181
 
@@ -208,7 +230,7 @@ module Mints
208
230
  headers = {
209
231
  "ApiKey" => @api_key,
210
232
  "Accept" => "application/json",
211
- "Contet-Type" => "application/json"
233
+ "Content-Type" => "application/json"
212
234
  }
213
235
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
214
236
  return self.http_put(url, headers, data)
@@ -218,7 +240,7 @@ module Mints
218
240
  def public_get(url, headers = nil)
219
241
  h = {
220
242
  "Accept" => "application/json",
221
- "Contet-Type" => "application/json",
243
+ "Content-Type" => "application/json",
222
244
  "ApiKey" => @api_key,
223
245
  "ContactToken" => @session_token
224
246
  }
@@ -233,7 +255,7 @@ module Mints
233
255
  def public_post(url, headers = nil, data)
234
256
  h = {
235
257
  "Accept" => "application/json",
236
- "Contet-Type" => "application/json",
258
+ "Content-Type" => "application/json",
237
259
  "ApiKey" => @api_key,
238
260
  "ContactToken" => @session_token
239
261
  }
@@ -248,7 +270,7 @@ module Mints
248
270
  def public_put(url, headers = nil, data)
249
271
  h = {
250
272
  "Accept" => "application/json",
251
- "Contet-Type" => "application/json",
273
+ "Content-Type" => "application/json",
252
274
  "ApiKey" => @api_key,
253
275
  "ContactToken" => @session_token
254
276
  }
data/lib/contact.rb CHANGED
@@ -6,8 +6,8 @@ module Mints
6
6
  # === Initialize.
7
7
  # Class constructor
8
8
  #
9
- def initialize(host, api_key, session_token = nil)
10
- @client = Mints::Client.new(host, api_key, "contact", session_token)
9
+ def initialize(host, api_key, session_token = nil, debug = false)
10
+ @client = Mints::Client.new(host, api_key, "contact", session_token, debug)
11
11
  end
12
12
 
13
13
  ##
@@ -1,4 +1,6 @@
1
1
  # Mints connection configuration
2
2
  mints:
3
3
  host: http://your_host_goes_here.com
4
- api_key: your_mints_api_key_goes_here
4
+ api_key: your_mints_api_key_goes_here
5
+ sdk:
6
+ debug: false
@@ -0,0 +1,2 @@
1
+ class Api::V1::MintsContactController < Mints::ContactAPIController
2
+ end
@@ -1,6 +1,20 @@
1
1
  class MintsFilesGenerator < Rails::Generators::Base
2
2
  source_root(File.expand_path(File.dirname(__FILE__)))
3
+ include Rails::Generators::Actions
3
4
  def create_mints_files
4
5
  copy_file 'mints_config.yml', 'mints_config.yml'
6
+ copy_file 'mints_user_controller.rb', './app/controllers/api/mints_user_controller.rb'
7
+ copy_file 'mints_contact_controller.rb', './app/controllers/api/v1/mints_contact_controller.rb'
8
+ copy_file 'mints_public_controller.rb', './app/controllers/api/v1/mints_public_controller.rb'
9
+ route <<-eos
10
+ # Mints auto-generated routes (proxy to send request to mints.cloud)
11
+ namespace :api, defaults: { format: :json } do
12
+ match '/user/v1/*path' => 'mints_user#index', via: [:get, :post, :put, :patch, :delete]
13
+ namespace :v1 do
14
+ match '/contacts/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
15
+ match '/*path' => 'mints_public#index', via: [:get, :post, :put, :patch, :delete]
16
+ end
17
+ end
18
+ eos
5
19
  end
6
20
  end
@@ -0,0 +1,2 @@
1
+ class Api::V1::MintsPublicController < Mints::PublicAPIController
2
+ end
@@ -0,0 +1,2 @@
1
+ class Api::MintsUserController < Mints::UserAPIController
2
+ end
@@ -0,0 +1,56 @@
1
+ module Mints
2
+ class AdminBaseController < ActionController::Base
3
+ before_action :set_mints_user_client
4
+
5
+ # def mints_user_signed_in?
6
+ # # Check status in mints
7
+ # response = @mints_user.status
8
+ # status = response['success'] ? response['success'] : false
9
+ # unless status
10
+ # # if mints response is negative delete the session cookie
11
+ # cookies.delete(:mints_user_session_token)
12
+ # end
13
+ # return status
14
+ # end
15
+
16
+ ##
17
+ # === Mints user Login.
18
+ # Starts a user session in mints.cloud and set a session cookie
19
+ def mints_user_login(email, password)
20
+ # Login in mints
21
+ response = @mints_user.login(email, password)
22
+ # Get session token from response
23
+ session_token = response['api_token']
24
+ # Set a permanent cookie with the session token
25
+ cookies.permanent[:mints_user_session_token] = session_token
26
+ end
27
+
28
+ ##
29
+ # === Mints user Logout.
30
+ # Destroy session from mints.cloud and delete local session cookie
31
+ def mints_user_logout
32
+ # Logout from mints
33
+ # @mints_user.logout
34
+ # Delete local cookie
35
+ cookies.delete(:mints_user_session_token)
36
+ end
37
+
38
+ private
39
+
40
+ ##
41
+ # === Set Mints user client.
42
+ # Initialize the public client and set the user token
43
+ def set_mints_user_client
44
+ if File.exists?("#{Rails.root}/mints_config.yml")
45
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
46
+ @host = config["mints"]["host"]
47
+ @api_key = config["mints"]["api_key"]
48
+ @debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
49
+ else
50
+ raise 'MintsBadCredentialsError'
51
+ end
52
+ # Initialize mints user client
53
+ @mints_user = Mints::User.new(@host, @api_key, nil, @debug)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,86 @@
1
+ module Mints
2
+ class BaseController < ActionController::Base
3
+ before_action :set_contact_token
4
+ before_action :set_mints_pub_client
5
+ before_action :register_visit
6
+ before_action :set_mints_contact_client
7
+
8
+ def mints_contact_signed_in?
9
+ # Check status in mints
10
+ response = @mints_contact.status
11
+ status = response['success'] ? response['success'] : false
12
+ unless status
13
+ # if mints response is negative delete the session cookie
14
+ cookies.delete(:mints_contact_session_token)
15
+ end
16
+ return status
17
+ end
18
+
19
+ ##
20
+ # === Mints Contact Login.
21
+ # Starts a contact session in mints.cloud and set a session cookie
22
+ def mints_contact_login(email, password)
23
+ # Login in mints
24
+ response = @mints_contact.login(email, password)
25
+ # Get session token from response
26
+ session_token = response['session_token']
27
+ # Set a permanent cookie with the session token
28
+ cookies.permanent[:mints_contact_session_token] = session_token
29
+ end
30
+
31
+ ##
32
+ # === Mints Contact Logout.
33
+ # Destroy session from mints.cloud and delete local session cookie
34
+ def mints_contact_logout
35
+ # Logout from mints
36
+ @mints_contact.logout
37
+ # Delete local cookie
38
+ cookies.delete(:mints_contact_session_token)
39
+ end
40
+
41
+ private
42
+
43
+ ##
44
+ # === Register visit.
45
+ # Call register visit method from the public client and set/renew the cookie mints_contact_id
46
+ def register_visit
47
+ response = @mints_pub.register_visit(request)
48
+ @contact_token = response['user_token']
49
+ @visit_id = response['visit_id']
50
+ cookies.permanent[:mints_contact_id] = @contact_token
51
+ end
52
+
53
+ ##
54
+ # === Set mints pub.
55
+ # Initialize the public client and set the contact token
56
+ def set_mints_pub_client
57
+ if File.exists?("#{Rails.root}/mints_config.yml")
58
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
59
+ @host = config["mints"]["host"]
60
+ @api_key = config["mints"]["api_key"]
61
+ @debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
62
+ else
63
+ raise 'MintsBadCredentialsError'
64
+ end
65
+ # Initialize mints pub client, credentials taken from mints_config.yml file
66
+ @mints_pub = Mints::Pub.new(@host, @api_key, nil, @debug)
67
+ # Set contact token from cookie
68
+ @mints_pub.client.session_token = @contact_token
69
+ end
70
+
71
+ ##
72
+ # === Set contact token.
73
+ # Set contact token variable from the mints_contact_id cookie value
74
+ def set_contact_token
75
+ @contact_token = cookies[:mints_contact_id]
76
+ end
77
+
78
+ ##
79
+ # === Set mints contact client.
80
+ # Initialize the public client and set the contact token
81
+ def set_mints_contact_client
82
+ # Initialize mints clontact client
83
+ @mints_contact = Mints::Contact.new(@host, @api_key, nil, @debug)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,38 @@
1
+ require 'reverse_proxy/controller'
2
+ module Mints
3
+ class ContactAPIController < ActionController::API
4
+ include AbstractController::Helpers
5
+ include ActionController::Cookies
6
+ include ReverseProxy::Controller
7
+ before_action :set_config_variables
8
+
9
+ def index
10
+ headers = {
11
+ 'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
12
+ 'ApiKey' => "#{@api_key}",
13
+ 'Content-Type'=> 'application/json',
14
+ 'Accept'=> 'application/json'
15
+ }
16
+ if cookies[:mints_contact_session_token]
17
+ session_token = cookies[:mints_contact_session_token]
18
+ headers["Authorization"] = "Bearer #{session_token}"
19
+ end
20
+ reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
21
+ # We got a 404!
22
+ config.on_missing do |code, response|
23
+ raise ActionController::RoutingError.new('Not Found')
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def set_config_variables
31
+ if File.exists?("#{Rails.root}/mints_config.yml")
32
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
33
+ @host = config["mints"]["host"]
34
+ @api_key = config["mints"]["api_key"]
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ require 'reverse_proxy/controller'
2
+ module Mints
3
+ class PublicAPIController < ActionController::API
4
+ include ReverseProxy::Controller
5
+ before_action :set_config_variables
6
+
7
+ def index
8
+ headers = {
9
+ 'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
10
+ 'ApiKey' => "#{@api_key}",
11
+ 'Content-Type'=> 'application/json',
12
+ 'Accept'=> 'application/json'
13
+ }
14
+ reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
15
+ # We got a 404!
16
+ config.on_missing do |code, response|
17
+ raise ActionController::RoutingError.new('Not Found')
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def set_config_variables
25
+ if File.exists?("#{Rails.root}/mints_config.yml")
26
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
27
+ @host = config["mints"]["host"]
28
+ @api_key = config["mints"]["api_key"]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ require 'reverse_proxy/controller'
2
+ module Mints
3
+ class UserAPIController < ActionController::API
4
+ include AbstractController::Helpers
5
+ include ActionController::Cookies
6
+ include ReverseProxy::Controller
7
+ before_action :set_config_variables
8
+
9
+ def index
10
+ headers = {
11
+ 'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
12
+ 'ApiKey' => "#{@api_key}",
13
+ 'Content-Type'=> 'application/json',
14
+ 'Accept'=> 'application/json'
15
+ }
16
+ if cookies[:mints_contact_session_token]
17
+ session_token = cookies[:mints_user_session_token]
18
+ headers["Authorization"] = "Bearer #{session_token}"
19
+ end
20
+ reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
21
+ # We got a 404!
22
+ config.on_missing do |code, response|
23
+ raise ActionController::RoutingError.new('Not Found')
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def set_config_variables
31
+ if File.exists?("#{Rails.root}/mints_config.yml")
32
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
33
+ @host = config["mints"]["host"]
34
+ @api_key = config["mints"]["api_key"]
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/mints.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require_relative "./pub.rb"
2
2
  require_relative "./contact.rb"
3
3
  require_relative "./user.rb"
4
- require_relative "./mints/controllers/mints_base_controller.rb"
4
+ require_relative "./mints/controllers/base_controller.rb"
5
+ require_relative "./mints/controllers/admin_base_controller.rb"
6
+ require_relative "./mints/controllers/public_api_controller.rb"
7
+ require_relative "./mints/controllers/contact_api_controller.rb"
8
+ require_relative "./mints/controllers/user_api_controller.rb"
5
9
  module Mints
6
10
  end
data/lib/pub.rb CHANGED
@@ -42,17 +42,8 @@ module Mints
42
42
  # * +contact_token+ - [String] Cookie 'mints_contact_id' value (mints_contact_token)
43
43
  # ==== Return
44
44
  # Returns a Client object
45
- def initialize(host=nil, api_key=nil, contact_token=nil)
46
- if host === nil and api_key === nil
47
- if File.exists?("#{Rails.root}/mints_config.yml")
48
- config = YAML.load_file("#{Rails.root}/mints_config.yml")
49
- host = config["mints"]["host"]
50
- api_key = config["mints"]["api_key"]
51
- else
52
- raise 'MintsBadCredentialsError'
53
- end
54
- end
55
- @client = Mints::Client.new(host, api_key, contact_token)
45
+ def initialize(host, api_key, contact_token = nil, debug = false)
46
+ @client = Mints::Client.new(host, api_key, contact_token, debug)
56
47
  end
57
48
 
58
49
  ##
@@ -64,7 +55,7 @@ module Mints
64
55
  # * +ip+ - [String] It's the visitor IP
65
56
  # * +user_agent+ - The visitor's browser user agent
66
57
  # * +url+ - [String] URL visited
67
- def register_visit(request, ip=nil, user_agent=nil, url=nil)
58
+ def register_visit(request, ip = nil, user_agent = nil, url = nil)
68
59
  data = {
69
60
  ip_address: ip || request.remote_ip,
70
61
  user_agent: user_agent || request.user_agent,
@@ -103,7 +94,7 @@ module Mints
103
94
  # ==== Parameters
104
95
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
105
96
  def get_content_templates(options = nil)
106
- return @client.raw("get", "/content/content-templates")
97
+ return @client.raw("get", "/content/content-templates", options)
107
98
  end
108
99
 
109
100
  ##
@@ -123,7 +114,7 @@ module Mints
123
114
  #
124
115
  # ==== Parameters
125
116
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
126
- def content_instances(options)
117
+ def get_content_instances(options)
127
118
  return @client.raw("get", "/content/content-instances", options)
128
119
  end
129
120
 
@@ -134,7 +125,7 @@ module Mints
134
125
  # ==== Parameters
135
126
  # * +slug+ - [String] It's the string identifier generated by Mints
136
127
  # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
137
- def content_instance(slug, options = nil)
128
+ def get_content_instance(slug, options = nil)
138
129
  return @client.raw("get", "/content/content-instances/#{slug}", options)
139
130
  end
140
131
 
@@ -161,13 +152,12 @@ module Mints
161
152
 
162
153
  ##
163
154
  # === Get Forms.
164
- # Get a collection of forms.
155
+ # Get a collection of forms
165
156
  #
166
157
  # ==== Parameters
167
- # * +slug+ - [String] It's the string identifier generated by Mints
168
158
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
169
159
  def get_forms(options = nil)
170
- return @client.raw("get", "/content/forms/{slug}", options)
160
+ return @client.raw("get", "/content/forms", options)
171
161
  end
172
162
 
173
163
  ##
@@ -178,7 +168,7 @@ module Mints
178
168
  # * +slug+ - [String] It's the string identifier generated by Mints
179
169
  # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
180
170
  def get_form(slug, options = nil)
181
- return @client.raw("get", "/content/forms/{slug}", options)
171
+ return @client.raw("get", "/content/forms/#{slug}", options)
182
172
  end
183
173
 
184
174
  ##
@@ -281,7 +271,7 @@ module Mints
281
271
  #
282
272
  # ==== Parameters
283
273
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
284
- def get_tags(options)
274
+ def get_tags(options = nil)
285
275
  return @client.raw("get", "/config/tags", options)
286
276
  end
287
277
 
data/lib/user.rb CHANGED
@@ -28,8 +28,8 @@ module Mints
28
28
  # * +tags+ - [Boolean] attach tags to response
29
29
  class User
30
30
  attr_reader :client
31
- def initialize(host, api_key, session_token = nil)
32
- @client = Mints::Client.new(host, api_key, 'user', session_token)
31
+ def initialize(host, api_key, session_token = nil, debug = false)
32
+ @client = Mints::Client.new(host, api_key, 'user', session_token, debug)
33
33
  end
34
34
 
35
35
  def login(email, password)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Gomez Garcia, Omar Mora
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-12 00:00:00.000000000 Z
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -70,6 +70,26 @@ dependencies:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 2.7.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: rails-reverse-proxy
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 0.9.1
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.1
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.1
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.9.1
73
93
  description:
74
94
  email:
75
95
  executables: []
@@ -81,9 +101,16 @@ files:
81
101
  - lib/client.rb
82
102
  - lib/contact.rb
83
103
  - lib/generators/mints_config.yml
104
+ - lib/generators/mints_contact_controller.rb
84
105
  - lib/generators/mints_files_generator.rb
106
+ - lib/generators/mints_public_controller.rb
107
+ - lib/generators/mints_user_controller.rb
85
108
  - lib/mints.rb
86
- - lib/mints/controllers/mints_base_controller.rb
109
+ - lib/mints/controllers/admin_base_controller.rb
110
+ - lib/mints/controllers/base_controller.rb
111
+ - lib/mints/controllers/contact_api_controller.rb
112
+ - lib/mints/controllers/public_api_controller.rb
113
+ - lib/mints/controllers/user_api_controller.rb
87
114
  - lib/pub.rb
88
115
  - lib/user.rb
89
116
  homepage: https://github.com/rubengomez/mints-ruby-sdk
@@ -1,35 +0,0 @@
1
- module Mints
2
- class BaseController < ActionController::Base
3
- before_action :set_contact_token
4
- before_action :set_mints_pub
5
- before_action :register_visit
6
-
7
- private
8
- ##
9
- # === Register visit.
10
- # Call register visit method from the public client and set/renew the cookie mints_contact_id
11
- def register_visit
12
- response = @mints_pub.register_visit(request)
13
- @contact_token = response['user_token']
14
- @visit_id = response['visit_id']
15
- cookies.permanent[:mints_contact_id] = @contact_token
16
- end
17
-
18
- ##
19
- # === Set mints pub.
20
- # Initialize the public client and set the contact token
21
- def set_mints_pub
22
- # Initialize mints pub client, credentials taken from mints_config.yml file
23
- @mints_pub = Mints::Pub.new
24
- # Set contact token from cookie
25
- @mints_pub.client.session_token = @contact_token
26
- end
27
-
28
- ##
29
- # === Set contact token.
30
- # Set contact token variable from the mints_contact_id cookie value
31
- def set_contact_token
32
- @contact_token = cookies[:mints_contact_id]
33
- end
34
- end
35
- end