mints 0.0.3 → 0.0.8

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: 327d7dc897b313289564ea62d790eca41f338394b7d3285a54044004d73c4949
4
- data.tar.gz: 311fef416ffe4b8009752185f7ca974e6ebe4c887692608c03bee69e7432100c
3
+ metadata.gz: d5412170b7e05b67da59931e6af7972b56e329d302012392cfc9d97235e0b9de
4
+ data.tar.gz: ba661a85b759c89e2e6c24b10509bd551a127ec46bf6861855352af474384eb3
5
5
  SHA512:
6
- metadata.gz: 132622f7ce07aed342c56e2c1bf3bc1a15be585fbf747c603b822e184ef55f7fb914d6216ad5b7e7c33d0831cbf33caf6b2927fa46eace7938e40ede898e86cf
7
- data.tar.gz: c5531bb9f2be7d66f8dd2b9951957b90e85b43c3d1e1527b462a3978f05ee9e768177f83aa6313d768d07c3062bee261add211d8dcbc5d5895f4dcf0f8c11ab2
6
+ metadata.gz: 67cad01ac699e1c98f5498cbb4f50fce4195abb6fadced35326c9d5e6d9564d10a0d3b406873b43f67430e9b908409f93fcbae021f99bf1265d01f931ea83d3f
7
+ data.tar.gz: d1bea2eac77eda19886a5e97c9c007137131192409036c1c87e36fefd569ccb36e00a40de621749d21f213e77f7899856f2b998187f321518917d9664dfb3899
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
@@ -6,8 +6,7 @@ This is a library to connect apps built on ruby to Mints.Cloud
6
6
 
7
7
  Add gem to the Gemfile
8
8
  ```bash
9
- gem 'mints', git: 'https://github.com/rubengomez/mints-ruby-sdk'
10
- bundle install
9
+ gem 'mints'
11
10
  ```
12
11
 
13
12
  ## Usage
@@ -30,3 +29,56 @@ con = Mints::User.new(mints_url, api_key)
30
29
  con.login(email, password)
31
30
  con.get_contacts
32
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
+ ```
37
+ ## Contact tracking usage
38
+ Your app controller needs to be inherited from Mints::BaseController
39
+ ```ruby
40
+ # application_controller.rb
41
+
42
+ class ApplicationController < Mints::BaseController
43
+ end
44
+ ```
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) |
79
+
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 |
@@ -9,26 +9,25 @@ 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}"
30
- if action === 'get'
31
- response = self.send("#{@scope}_#{action}", "#{full_url}")
29
+ if action === 'get'
30
+ response = self.send("#{@scope}_#{action}", "#{full_url}")
32
31
  elsif action === 'create' or action === 'post'
33
32
  action = 'post'
34
33
  response = self.send("#{@scope}_#{action}", "#{full_url}", data)
@@ -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
 
@@ -161,7 +183,8 @@ module Mints
161
183
  def contact_get(url)
162
184
  headers = {
163
185
  "ApiKey" => @api_key,
164
- "Accept" => "application/json"
186
+ "Accept" => "application/json",
187
+ "ContactToken" => @contact_token
165
188
  }
166
189
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
167
190
  return self.http_get(url, headers)
@@ -170,7 +193,8 @@ module Mints
170
193
  def contact_post(url, data)
171
194
  headers = {
172
195
  "ApiKey" => @api_key,
173
- "Accept" => "application/json"
196
+ "Accept" => "application/json",
197
+ "ContactToken" => @contact_token
174
198
  }
175
199
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
176
200
  return self.http_post(url, headers, data)
@@ -179,7 +203,8 @@ module Mints
179
203
  def contact_put(url, data)
180
204
  headers = {
181
205
  "ApiKey" => @api_key,
182
- "Accept" => "application/json"
206
+ "Accept" => "application/json",
207
+ "ContactToken" => @contact_token
183
208
  }
184
209
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
185
210
  return self.http_post(url, headers, data)
@@ -208,7 +233,7 @@ module Mints
208
233
  headers = {
209
234
  "ApiKey" => @api_key,
210
235
  "Accept" => "application/json",
211
- "Contet-Type" => "application/json"
236
+ "Content-Type" => "application/json"
212
237
  }
213
238
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
214
239
  return self.http_put(url, headers, data)
@@ -216,7 +241,12 @@ module Mints
216
241
  # End User Context
217
242
 
218
243
  def public_get(url, headers = nil)
219
- h = {"Accept" => "application/json", "Contet-Type" => "application/json", "ApiKey" => @api_key}
244
+ h = {
245
+ "Accept" => "application/json",
246
+ "Content-Type" => "application/json",
247
+ "ApiKey" => @api_key
248
+ }
249
+ h["ContactToken"] = @contact_token if @contact_token
220
250
  if headers
221
251
  headers.each do |k,v|
222
252
  h[k] = v
@@ -226,7 +256,12 @@ module Mints
226
256
  end
227
257
 
228
258
  def public_post(url, headers = nil, data)
229
- h = {"Accept" => "application/json", "Contet-Type" => "application/json", "ApiKey" => @api_key}
259
+ h = {
260
+ "Accept" => "application/json",
261
+ "Content-Type" => "application/json",
262
+ "ApiKey" => @api_key
263
+ }
264
+ h["ContactToken"] = @session_token if @session_token
230
265
  if headers
231
266
  headers.each do |k,v|
232
267
  h[k] = v
@@ -236,7 +271,12 @@ module Mints
236
271
  end
237
272
 
238
273
  def public_put(url, headers = nil, data)
239
- h = {"Accept" => "application/json", "Contet-Type" => "application/json", "ApiKey" => @api_key}
274
+ h = {
275
+ "Accept" => "application/json",
276
+ "Content-Type" => "application/json",
277
+ "ApiKey" => @api_key
278
+ }
279
+ h["ContactToken"] = @contact_token if @contact_token
240
280
  if headers
241
281
  headers.each do |k,v|
242
282
  h[k] = v
@@ -1,4 +1,5 @@
1
1
  require_relative "./client.rb"
2
+ include ActionController::Cookies
2
3
  module Mints
3
4
  class Contact
4
5
  attr_reader :client
@@ -6,22 +7,8 @@ module Mints
6
7
  # === Initialize.
7
8
  # Class constructor
8
9
  #
9
- def initialize(host, api_key, session_token = nil)
10
- @client = Mints::Client.new(host, api_key, "contact", session_token)
11
- end
12
-
13
- ##
14
- # === Register.
15
- # Register a new contact
16
- #
17
- def register(given_name, last_name, email, password)
18
- data = {
19
- given_name: given_name,
20
- last_name: last_name,
21
- email: email,
22
- password: password
23
- }
24
- return @client.raw("post", "/contacts/register", nil, {data: data})
10
+ def initialize(host, api_key, session_token = nil, debug = false)
11
+ @client = Mints::Client.new(host, api_key, "contact", session_token, debug)
25
12
  end
26
13
 
27
14
  ##
@@ -0,0 +1,6 @@
1
+ # Mints connection configuration
2
+ mints:
3
+ host: http://your_host_goes_here.com
4
+ api_key: your_mints_api_key_goes_here
5
+ sdk:
6
+ debug: false
@@ -0,0 +1,3 @@
1
+ require 'reverse_proxy/client'
2
+ class Api::V1::MintsContactController < Mints::ContactAPIController
3
+ end
@@ -0,0 +1,20 @@
1
+ class MintsFilesGenerator < Rails::Generators::Base
2
+ source_root(File.expand_path(File.dirname(__FILE__)))
3
+ include Rails::Generators::Actions
4
+ def create_mints_files
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
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ require 'reverse_proxy/client'
2
+ class Api::V1::MintsPublicController < Mints::PublicAPIController
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'reverse_proxy/client'
2
+ class Api::MintsUserController < Mints::UserAPIController
3
+ end
@@ -1,5 +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/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"
4
9
  module Mints
5
10
  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,91 @@
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
+ id_token = response['contact']['id_token']
28
+ # Set a permanent cookie with the session token
29
+ cookies.permanent[:mints_contact_session_token] = session_token
30
+ cookies.permanent[:mints_contact_id] = id_token
31
+ @contact_token = id_token
32
+ end
33
+
34
+ ##
35
+ # === Mints Contact Logout.
36
+ # Destroy session from mints.cloud and delete local session cookie
37
+ def mints_contact_logout
38
+ # Logout from mints
39
+ @mints_contact.logout
40
+ # Delete local cookie
41
+ cookies.delete(:mints_contact_session_token)
42
+ cookies.delete(:mints_contact_id)
43
+ @contact_token = nil
44
+ end
45
+
46
+ private
47
+
48
+ ##
49
+ # === Register visit.
50
+ # Call register visit method from the public client and set/renew the cookie mints_contact_id
51
+ def register_visit
52
+ response = @mints_pub.register_visit(request)
53
+ @contact_token = response['user_token']
54
+ @visit_id = response['visit_id']
55
+ cookies.permanent[:mints_contact_id] = @contact_token
56
+ end
57
+
58
+ ##
59
+ # === Set mints pub.
60
+ # Initialize the public client and set the contact token
61
+ def set_mints_pub_client
62
+ if File.exists?("#{Rails.root}/mints_config.yml")
63
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
64
+ @host = config["mints"]["host"]
65
+ @api_key = config["mints"]["api_key"]
66
+ @debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
67
+ else
68
+ raise 'MintsBadCredentialsError'
69
+ end
70
+ # Initialize mints pub client, credentials taken from mints_config.yml file
71
+ @mints_pub = Mints::Pub.new(@host, @api_key, nil, @debug)
72
+ # Set contact token from cookie
73
+ @mints_pub.client.session_token = @contact_token
74
+ end
75
+
76
+ ##
77
+ # === Set contact token.
78
+ # Set contact token variable from the mints_contact_id cookie value
79
+ def set_contact_token
80
+ @contact_token = cookies[:mints_contact_id]
81
+ end
82
+
83
+ ##
84
+ # === Set mints contact client.
85
+ # Initialize the public client and set the contact token
86
+ def set_mints_contact_client
87
+ # Initialize mints clontact client
88
+ @mints_contact = Mints::Contact.new(@host, @api_key, nil, @debug)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,42 @@
1
+ require 'reverse_proxy/controller'
2
+ require 'reverse_proxy/client'
3
+ module Mints
4
+ class ContactAPIController < ActionController::API
5
+ include AbstractController::Helpers
6
+ include ActionController::Cookies
7
+ include ReverseProxy::Controller
8
+ before_action :set_config_variables
9
+
10
+ def index
11
+ headers = {
12
+ 'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
13
+ 'ApiKey' => "#{@api_key}",
14
+ 'Content-Type'=> 'application/json',
15
+ 'Accept'=> 'application/json'
16
+ }
17
+ if cookies[:mints_contact_session_token]
18
+ session_token = cookies[:mints_contact_session_token]
19
+ headers["Authorization"] = "Bearer #{session_token}"
20
+ end
21
+ reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
22
+ # We got a 404!
23
+ config.on_missing do |code, response|
24
+ # We got a 404!
25
+ if code == 404
26
+ raise ActionController::RoutingError.new('Not Found')
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def set_config_variables
35
+ if File.exists?("#{Rails.root}/mints_config.yml")
36
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
37
+ @host = config["mints"]["host"]
38
+ @api_key = config["mints"]["api_key"]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,36 @@
1
+ require 'reverse_proxy/controller'
2
+ require 'reverse_proxy/client'
3
+ module Mints
4
+ class PublicAPIController < ActionController::API
5
+ include ReverseProxy::Controller
6
+ before_action :set_config_variables
7
+
8
+ def index
9
+ headers = {
10
+ 'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
11
+ 'ApiKey' => "#{@api_key}",
12
+ 'Content-Type'=> 'application/json',
13
+ 'Accept'=> 'application/json'
14
+ }
15
+ reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
16
+ # Request failed!
17
+ config.on_missing do |code, response|
18
+ # We got a 404!
19
+ if code == 404
20
+ raise ActionController::RoutingError.new('Not Found')
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def set_config_variables
29
+ if File.exists?("#{Rails.root}/mints_config.yml")
30
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
31
+ @host = config["mints"]["host"]
32
+ @api_key = config["mints"]["api_key"]
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,42 @@
1
+ require 'reverse_proxy/controller'
2
+ require 'reverse_proxy/client'
3
+ module Mints
4
+ class UserAPIController < ActionController::API
5
+ include AbstractController::Helpers
6
+ include ActionController::Cookies
7
+ include ReverseProxy::Controller
8
+ before_action :set_config_variables
9
+
10
+ def index
11
+ headers = {
12
+ 'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
13
+ 'ApiKey' => "#{@api_key}",
14
+ 'Content-Type'=> 'application/json',
15
+ 'Accept'=> 'application/json'
16
+ }
17
+ if cookies[:mints_contact_session_token]
18
+ session_token = cookies[:mints_user_session_token]
19
+ headers["Authorization"] = "Bearer #{session_token}"
20
+ end
21
+ reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
22
+ # Request failed!
23
+ config.on_missing do |code, response|
24
+ # We got a 404!
25
+ if code == 404
26
+ raise ActionController::RoutingError.new('Not Found')
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def set_config_variables
35
+ if File.exists?("#{Rails.root}/mints_config.yml")
36
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
37
+ @host = config["mints"]["host"]
38
+ @api_key = config["mints"]["api_key"]
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/pub.rb CHANGED
@@ -1,12 +1,14 @@
1
+ require 'yaml'
1
2
  require_relative './client.rb'
2
3
  module Mints
3
-
4
4
  ##
5
5
  # == Public context API
6
6
  # Pub class contains functions that needs only an API key as authentication
7
7
  # == Usage example
8
8
  # Initialize
9
9
  # pub = Mints::Pub.new(mints_url, api_key)
10
+ # or if host and api_key are provided by mints_config.yml
11
+ # pub = Mints::Pub.new
10
12
  # Call any function
11
13
  # pub.get_products
12
14
  # == Single resource options
@@ -25,6 +27,7 @@ module Mints
25
27
  # * +include+ - [String] include a relationship
26
28
  # * +attributes+ - [Boolean] attach attributes to response
27
29
  # * +categories+ - [Boolean] attach categories to response
30
+ # * +taxonomies+ - [Boolean] attach categories to response
28
31
  # * +tags+ - [Boolean] attach tags to response
29
32
  class Pub
30
33
  attr_reader :client
@@ -36,10 +39,11 @@ module Mints
36
39
  # ==== Parameters
37
40
  # * +host+ - [String] It's the visitor IP
38
41
  # * +api_key+ - [String] Mints instance api key
42
+ # * +contact_token+ - [String] Cookie 'mints_contact_id' value (mints_contact_token)
39
43
  # ==== Return
40
44
  # Returns a Client object
41
- def initialize(host, api_key)
42
- @client = Mints::Client.new(host, api_key)
45
+ def initialize(host, api_key, contact_token = nil, debug = false)
46
+ @client = Mints::Client.new(host, api_key, contact_token, debug)
43
47
  end
44
48
 
45
49
  ##
@@ -47,16 +51,18 @@ module Mints
47
51
  # Register a ghost/contact visit in Mints.Cloud
48
52
  #
49
53
  # ==== Parameters
54
+ # * +request+ - [ActionDispatch::Request] request
50
55
  # * +ip+ - [String] It's the visitor IP
51
56
  # * +user_agent+ - The visitor's browser user agent
52
57
  # * +url+ - [String] URL visited
53
- def register_visit(ip, user_agent, url)
58
+ def register_visit(request, ip = nil, user_agent = nil, url = nil)
54
59
  data = {
55
- ip_address: ip,
56
- user_agent: user_agent,
57
- url: url
60
+ ip_address: ip || request.remote_ip,
61
+ user_agent: user_agent || request.user_agent,
62
+ url: url || request.fullpath
58
63
  }
59
- return @client.raw("post", "/register-visit-timer", nil, data)
64
+ response = @client.raw("post", "/register-visit", nil, data.to_json)
65
+ return response
60
66
  end
61
67
 
62
68
  ##
@@ -88,7 +94,7 @@ module Mints
88
94
  # ==== Parameters
89
95
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
90
96
  def get_content_templates(options = nil)
91
- return @client.raw("get", "/content/content-templates")
97
+ return @client.raw("get", "/content/content-templates", options)
92
98
  end
93
99
 
94
100
  ##
@@ -108,7 +114,7 @@ module Mints
108
114
  #
109
115
  # ==== Parameters
110
116
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
111
- def content_instances(options)
117
+ def get_content_instances(options)
112
118
  return @client.raw("get", "/content/content-instances", options)
113
119
  end
114
120
 
@@ -119,7 +125,7 @@ module Mints
119
125
  # ==== Parameters
120
126
  # * +slug+ - [String] It's the string identifier generated by Mints
121
127
  # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
122
- def content_instance(slug, options = nil)
128
+ def get_content_instance(slug, options = nil)
123
129
  return @client.raw("get", "/content/content-instances/#{slug}", options)
124
130
  end
125
131
 
@@ -146,13 +152,12 @@ module Mints
146
152
 
147
153
  ##
148
154
  # === Get Forms.
149
- # Get a collection of forms.
155
+ # Get a collection of forms
150
156
  #
151
157
  # ==== Parameters
152
- # * +slug+ - [String] It's the string identifier generated by Mints
153
158
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
154
159
  def get_forms(options = nil)
155
- return @client.raw("get", "/content/forms/{slug}", options)
160
+ return @client.raw("get", "/content/forms", options)
156
161
  end
157
162
 
158
163
  ##
@@ -163,7 +168,7 @@ module Mints
163
168
  # * +slug+ - [String] It's the string identifier generated by Mints
164
169
  # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
165
170
  def get_form(slug, options = nil)
166
- return @client.raw("get", "/content/forms/{slug}", options)
171
+ return @client.raw("get", "/content/forms/#{slug}", options)
167
172
  end
168
173
 
169
174
  ##
@@ -266,7 +271,7 @@ module Mints
266
271
  #
267
272
  # ==== Parameters
268
273
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
269
- def get_tags(options)
274
+ def get_tags(options = nil)
270
275
  return @client.raw("get", "/config/tags", options)
271
276
  end
272
277
 
@@ -290,5 +295,26 @@ module Mints
290
295
  def get_attributes(options = nil)
291
296
  return @client.raw("get", "/config/attributes", options)
292
297
  end
298
+
299
+ ##
300
+ # === Get Taxonomies.
301
+ # Get a collection of taxonomies.
302
+ #
303
+ # ==== Parameters
304
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
305
+ def get_taxonomies(options = nil)
306
+ return @client.raw("get", "/config/taxonomies", options)
307
+ end
308
+
309
+ ##
310
+ # === Get Taxonomy.
311
+ # Get a single taxonomy
312
+ #
313
+ # ==== Parameters
314
+ # * +slug+ - [String] It's the string identifier generated by Mints
315
+ # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
316
+ def get_taxonomy(slug, options = nil)
317
+ return @client.raw("get", "/config/taxonomies/#{slug}", options)
318
+ end
293
319
  end
294
320
  end
@@ -1,9 +1,35 @@
1
1
  require_relative './client.rb'
2
2
  module Mints
3
+ ##
4
+ # == User context API
5
+ # User class contains functions that needs an API key and a session token as authentication
6
+ # == Usage example
7
+ # Initialize
8
+ # client = Mints::User.new(mints_url, api_key)
9
+ # Call any function
10
+ # client.get_contacts
11
+ # == Single resource options
12
+ # * +include+ - [String] include a relationship
13
+ # * +attributes+ - [Boolean] attach attributes to response
14
+ # * +categories+ - [Boolean] attach categories to response
15
+ # * +tags+ - [Boolean] attach tags to response
16
+ # == Resource collections options
17
+ # * +search+ - [String] filter by a search word
18
+ # * +scopes+ - [String] filter by a scope
19
+ # * +filters+ - [String] filter by where clauses
20
+ # * +jfilters+ - [String] filter using complex condition objects
21
+ # * +catfilters+ - [String] filter by categories
22
+ # * +fields+ - [String] indicates the columns that will be selected
23
+ # * +sort+ - [String] indicates the columns that will be selected
24
+ # * +include+ - [String] include a relationship
25
+ # * +attributes+ - [Boolean] attach attributes to response
26
+ # * +categories+ - [Boolean] attach categories to response
27
+ # * +taxonomies+ - [Boolean] attach categories to response
28
+ # * +tags+ - [Boolean] attach tags to response
3
29
  class User
4
30
  attr_reader :client
5
- def initialize(host, api_key, session_token = nil)
6
- @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)
7
33
  end
8
34
 
9
35
  def login(email, password)
@@ -18,7 +44,12 @@ module Mints
18
44
  return response
19
45
  end
20
46
  ######################################### CRM #########################################
21
- ### Contacts ###
47
+ ##
48
+ # === Get contacts.
49
+ # Get a collection of contacts
50
+ #
51
+ # ==== Parameters
52
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
22
53
  def get_contacts(options = nil)
23
54
  return @client.get__crm__contacts(options)
24
55
  end
@@ -34,7 +65,12 @@ module Mints
34
65
  def update_contact(id, data, options = nil)
35
66
  return @client.update__crm__contacts(id, data, options)
36
67
  end
37
- ### Companies ###
68
+
69
+ # === Get companies.
70
+ # Get a collection of companies
71
+ #
72
+ # ==== Parameters
73
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
38
74
  def get_companies(options = nil)
39
75
  return @client.get__crm__companies(options)
40
76
  end
@@ -51,7 +87,11 @@ module Mints
51
87
  return @client.update__crm__companies(id, data, options)
52
88
  end
53
89
 
54
- ### Deals ###
90
+ # === Get deals.
91
+ # Get a collection of deals
92
+ #
93
+ # ==== Parameters
94
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
55
95
  def get_deals(options = nil)
56
96
  return @client.get__crm__deals(options)
57
97
  end
@@ -69,7 +109,11 @@ module Mints
69
109
  end
70
110
 
71
111
  ######################################### Content #########################################
72
- ### Stories ###
112
+ # === Get stories.
113
+ # Get a collection of stories
114
+ #
115
+ # ==== Parameters
116
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
73
117
  def get_stories(options = nil)
74
118
  return @client.get__content__stories(options)
75
119
  end
@@ -86,7 +130,11 @@ module Mints
86
130
  return @client.update__content__stories(id, data, options)
87
131
  end
88
132
 
89
- ### Stories templates ###
133
+ # === Get story templates.
134
+ # Get a collection of story templates
135
+ #
136
+ # ==== Parameters
137
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
90
138
  def get_story_templates(options = nil)
91
139
  return @client.get__content__story_templates(options)
92
140
  end
@@ -103,7 +151,11 @@ module Mints
103
151
  return @client.update__content__story_templates(id, data, options)
104
152
  end
105
153
 
106
- ### Content instances ###
154
+ # === Get content instances.
155
+ # Get a collection of content instances
156
+ #
157
+ # ==== Parameters
158
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
107
159
  def get_content_instances(options = nil)
108
160
  return @client.get__content__instances(options)
109
161
  end
@@ -120,7 +172,11 @@ module Mints
120
172
  return @client.update__content__instances(id, data, options)
121
173
  end
122
174
 
123
- ### Content pages ###
175
+ # === Get content pages.
176
+ # Get a collection of content pages
177
+ #
178
+ # ==== Parameters
179
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
124
180
  def get_content_pages(options = nil)
125
181
  return @client.get__content__pages(options)
126
182
  end
@@ -137,25 +193,32 @@ module Mints
137
193
  return @client.update__content__pages(id, data, options)
138
194
  end
139
195
 
140
- ### Content templates ###
196
+ # === Get content templates.
197
+ # Get a collection of content templates
198
+ #
199
+ # ==== Parameters
200
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
141
201
  def get_content_templates(options = nil)
142
202
  return @client.get__content__templates(options)
143
203
  end
144
204
 
145
- def get_content_page(id, options = nil)
205
+ def get_content_template(id, options = nil)
146
206
  return @client.get__content__templates(id, options)
147
207
  end
148
208
 
149
- def create_content_page(data, options = nil)
209
+ def create_content_template(data, options = nil)
150
210
  return @client.create__content__templates(data, options)
151
211
  end
152
212
 
153
- def update_content_page(id, data, options = nil)
213
+ def update_content_template(id, data, options = nil)
154
214
  return @client.update__content__templates(id, data, options)
155
215
  end
156
216
 
157
- ######################################### Ecommerce #########################################
158
- ### Products ###
217
+ # === Get products.
218
+ # Get a collection of products
219
+ #
220
+ # ==== Parameters
221
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
159
222
  def get_products(options = nil)
160
223
  return @client.get__ecommerce__products(options)
161
224
  end
@@ -172,7 +235,11 @@ module Mints
172
235
  return @client.update__ecommerce__products(id, data, options)
173
236
  end
174
237
 
175
- ### SKUs ###
238
+ # === Get skus.
239
+ # Get a collection of skus
240
+ #
241
+ # ==== Parameters
242
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
176
243
  def get_skus(options = nil)
177
244
  return @client.get__ecommerce__skus(options)
178
245
  end
@@ -189,7 +256,11 @@ module Mints
189
256
  return @client.update__ecommerce__skus(id, data, options)
190
257
  end
191
258
 
192
- ### Prices ###
259
+ # === Get prices.
260
+ # Get a collection of prices
261
+ #
262
+ # ==== Parameters
263
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
193
264
  def get_prices(options = nil)
194
265
  return @client.get__ecommerce__prices(options)
195
266
  end
@@ -206,7 +277,11 @@ module Mints
206
277
  return @client.update__ecommerce__prices(id, data, options)
207
278
  end
208
279
 
209
- ### Price lists ###
280
+ # === Get prece lists.
281
+ # Get a collection of prece lists
282
+ #
283
+ # ==== Parameters
284
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
210
285
  def get_price_lists(options = nil)
211
286
  return @client.get__ecommerce__price_lists(options)
212
287
  end
@@ -223,7 +298,11 @@ module Mints
223
298
  return @client.update__ecommerce__price_lists(id, data, options)
224
299
  end
225
300
 
226
- ### Product brands ###
301
+ # === Get product brands.
302
+ # Get a collection of product brands
303
+ #
304
+ # ==== Parameters
305
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
227
306
  def get_product_brands(options = nil)
228
307
  return @client.get__ecommerce__product_brands(options)
229
308
  end
@@ -240,7 +319,11 @@ module Mints
240
319
  return @client.update__ecommerce__product_brands(id, data, options)
241
320
  end
242
321
 
243
- ### Product types ###
322
+ # === Get product types.
323
+ # Get a collection of product types
324
+ #
325
+ # ==== Parameters
326
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
244
327
  def get_product_types(options = nil)
245
328
  return @client.get__ecommerce__product_types(options)
246
329
  end
@@ -257,7 +340,11 @@ module Mints
257
340
  return @client.update__ecommerce__product_types(id, data, options)
258
341
  end
259
342
 
260
- ### Product templates ###
343
+ # === Get product templates.
344
+ # Get a collection of product templates
345
+ #
346
+ # ==== Parameters
347
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
261
348
  def get_product_templates(options = nil)
262
349
  return @client.get__ecommerce__product_templates(options)
263
350
  end
@@ -275,7 +362,11 @@ module Mints
275
362
  end
276
363
 
277
364
 
278
- ### Locations ###
365
+ # === Get locations.
366
+ # Get a collection of locations
367
+ #
368
+ # ==== Parameters
369
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
279
370
  def get_locations(options = nil)
280
371
  return @client.get__ecommerce__locations(options)
281
372
  end
@@ -291,5 +382,26 @@ module Mints
291
382
  def update_location(id, data, options = nil)
292
383
  return @client.update__ecommerce__locations(id, data, options)
293
384
  end
294
- end
385
+
386
+ # === Get taxonomies.
387
+ # Get a collection of taxonomies
388
+ #
389
+ # ==== Parameters
390
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
391
+ def get_taxonomies(options = nil)
392
+ return @client.get__config__taxonomies(options)
393
+ end
394
+
395
+ def get_taxonomy(id, options = nil)
396
+ return @client.get__config__taxonomies(id, options)
397
+ end
398
+
399
+ def create_taxonomy(data, options = nil)
400
+ return @client.create__config__taxonomies(data, options)
401
+ end
402
+
403
+ def update_taxonomy(id, data, options = nil)
404
+ return @client.update__config__taxonomies(id, data, options)
405
+ end
406
+ end
295
407
  end
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.3
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
- - Ruben Gomez Garcia, Omar Mora
7
+ - Ruben Gomez Garcia, Omar Mora, Luis Payan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-05-28 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: []
@@ -80,7 +100,17 @@ files:
80
100
  - Readme.md
81
101
  - lib/client.rb
82
102
  - lib/contact.rb
103
+ - lib/generators/mints_config.yml
104
+ - lib/generators/mints_contact_controller.rb
105
+ - lib/generators/mints_files_generator.rb
106
+ - lib/generators/mints_public_controller.rb
107
+ - lib/generators/mints_user_controller.rb
83
108
  - lib/mints.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
84
114
  - lib/pub.rb
85
115
  - lib/user.rb
86
116
  homepage: https://github.com/rubengomez/mints-ruby-sdk
@@ -89,6 +119,7 @@ metadata: {}
89
119
  post_install_message:
90
120
  rdoc_options: []
91
121
  require_paths:
122
+ - app
92
123
  - lib
93
124
  required_ruby_version: !ruby/object:Gem::Requirement
94
125
  requirements: