mints 0.0.12 → 0.0.16

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: 97aa9d0890796f3b8d99a99377253cdf6e94dedeb87a7048318073903fbfbe1d
4
- data.tar.gz: 9e4e17583e943160852667e6fa853504818f6ba330529834416c4c2dc232bd85
3
+ metadata.gz: d9cce05094ead82499622fb1f66d7caa52848d7940c484917218563d32defa16
4
+ data.tar.gz: 88e34ca4adfe1f77097206463f6c24a6479b63f2cfdf92bf3106152c00b8dd5a
5
5
  SHA512:
6
- metadata.gz: 762ab3452de8a7e288e51c498daf58141fe2b7068904f68b455871c87493b32943a3e0225b6b2a90e9bd3d87f1331995d82e207ac214b6c545440a2362122e4a
7
- data.tar.gz: 14b2ccb45e7bf43d7c23e43708e2916970e11f49d117e8700e06ff0a00f5f0e7bbb2d7a42ab206879e670e524fb5c87677b4d71de518080026d84c3b23e432da
6
+ metadata.gz: fbd81e5fed7023a5b3d489c66bbcc1efa3304d2fe6a7492aef0f0c72f51ad98c2c77635377858e19df92d61fd5a1c26d7d7758d0fde57c223ee9c9968faf0337
7
+ data.tar.gz: 6f8672d582a57aa9f2128b73b6fb8133387ea604082557b146eadc321cd9fbcd55a9da4bbba4ac9541cfc3225edcc6826858f314b104abea0bf887bd87bc5a0c
data/lib/client.rb CHANGED
@@ -8,12 +8,14 @@ module Mints
8
8
  attr_reader :api_key
9
9
  attr_reader :scope
10
10
  attr_reader :base_url
11
- attr_accessor :session_token
11
+ attr_accessor :session_token
12
+ attr_accessor :contact_token_id
12
13
 
13
- def initialize(host, api_key, scope = nil, session_token = nil, debug = false)
14
+ def initialize(host, api_key, scope = nil, session_token = nil, contact_token_id = nil, debug = false)
14
15
  @host = host
15
16
  @api_key = api_key
16
17
  @session_token = session_token
18
+ @contact_token_id = contact_token_id
17
19
  @debug = debug
18
20
  self.set_scope(scope)
19
21
  end
@@ -22,6 +24,9 @@ module Mints
22
24
  base_url = @base_url if !base_url
23
25
  uri = ""
24
26
  if (options && options.class == Hash)
27
+ if (options[:jfilters] && options[:jfilters].class == Hash)
28
+ options[:jfilters] = Base64.encode64(JSON.generate(options[:jfilters]))
29
+ end
25
30
  uri = Addressable::URI.new
26
31
  uri.query_values = options
27
32
  end
@@ -218,7 +223,7 @@ module Mints
218
223
  headers = {
219
224
  "ApiKey" => @api_key,
220
225
  "Accept" => "application/json",
221
- "ContactToken" => @contact_token
226
+ "ContactToken" => @contact_token_id
222
227
  }
223
228
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
224
229
  return self.http_get(url, headers)
@@ -228,7 +233,7 @@ module Mints
228
233
  headers = {
229
234
  "ApiKey" => @api_key,
230
235
  "Accept" => "application/json",
231
- "ContactToken" => @contact_token
236
+ "ContactToken" => @contact_token_id
232
237
  }
233
238
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
234
239
  return self.http_post(url, headers, data)
@@ -238,7 +243,7 @@ module Mints
238
243
  headers = {
239
244
  "ApiKey" => @api_key,
240
245
  "Accept" => "application/json",
241
- "ContactToken" => @contact_token
246
+ "ContactToken" => @contact_token_id
242
247
  }
243
248
  headers["Authorization"] = "Bearer #{@session_token}" if @session_token
244
249
  return self.http_post(url, headers, data)
@@ -280,7 +285,7 @@ module Mints
280
285
  "Content-Type" => "application/json",
281
286
  "ApiKey" => @api_key
282
287
  }
283
- h["ContactToken"] = @contact_token if @contact_token
288
+ h["ContactToken"] = @contact_token_id if @contact_token_id
284
289
  if headers
285
290
  headers.each do |k,v|
286
291
  h[k] = v
@@ -310,7 +315,7 @@ module Mints
310
315
  "Content-Type" => "application/json",
311
316
  "ApiKey" => @api_key
312
317
  }
313
- h["ContactToken"] = @contact_token if @contact_token
318
+ h["ContactToken"] = @contact_token_id if @contact_token_id
314
319
  if headers
315
320
  headers.each do |k,v|
316
321
  h[k] = v
data/lib/contact.rb CHANGED
@@ -7,8 +7,8 @@ module Mints
7
7
  # === Initialize.
8
8
  # Class constructor
9
9
  #
10
- def initialize(host, api_key, session_token = nil, debug = false)
11
- @client = Mints::Client.new(host, api_key, "contact", session_token, debug)
10
+ def initialize(host, api_key, session_token = nil, contact_token_id = nil, debug = false)
11
+ @client = Mints::Client.new(host, api_key, "contact", session_token, contact_token_id, debug)
12
12
  end
13
13
 
14
14
  ##
@@ -27,6 +27,32 @@ module Mints
27
27
  return response
28
28
  end
29
29
 
30
+ ##
31
+ # === Magic Link Login.
32
+ # Starts a contact session
33
+ #
34
+ def magic_link_login(token)
35
+ response = @client.raw("get", "/contacts/magic-link-login/#{token}", nil, '/api/v1')
36
+ if response.key? "session_token"
37
+ @client.session_token = response["session_token"]
38
+ end
39
+ return response
40
+ end
41
+
42
+ ##
43
+ # === Send magic link to contact
44
+ def send_magic_link(email, template_slug, redirectUrl = '', lifeTime = 1440, maxVisits = nil)
45
+ data = {
46
+ email: email,
47
+ lifeTime: lifeTime,
48
+ maxVisits: maxVisits,
49
+ redirectUrl: redirectUrl,
50
+ templateId: template_slug
51
+ }
52
+ response = @client.raw("post", "/contacts/magic-link", nil, { data: data }, '/api/v1')
53
+ return response
54
+ end
55
+
30
56
  ##
31
57
  # === Logout.
32
58
  # Ends a contact session
@@ -0,0 +1,3 @@
1
+ require 'reverse_proxy/client'
2
+ class MintsAssetsController < Mints::PublicAPIController
3
+ end
@@ -6,12 +6,15 @@ class MintsFilesGenerator < Rails::Generators::Base
6
6
  copy_file 'mints_user_controller.rb', './app/controllers/api/mints_user_controller.rb'
7
7
  copy_file 'mints_contact_controller.rb', './app/controllers/api/v1/mints_contact_controller.rb'
8
8
  copy_file 'mints_public_controller.rb', './app/controllers/api/v1/mints_public_controller.rb'
9
+ copy_file 'mints_assets_controller.rb', './app/controllers/mints_assets_controller.rb'
9
10
  route <<-eos
10
11
  # Mints auto-generated routes (proxy to send request to mints.cloud)
12
+ match '/public-assets/*path' => 'mints_assets#index', via: [:get, :post, :put, :patch, :delete]
11
13
  namespace :api, defaults: { format: :json } do
12
- match '/user/v1/*path' => 'mints_user#index', via: [:get, :post, :put, :patch, :delete]
14
+ match '/user/v1/*path' => 'mints_user#index', via: [:get, :post, :put, :patch, :delete]
15
+ match '/contact/v1/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
13
16
  namespace :v1 do
14
- match '/contacts/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
17
+ match '/contacts/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
15
18
  match '/*path' => 'mints_public#index', via: [:get, :post, :put, :patch, :delete]
16
19
  end
17
20
  end
@@ -2,16 +2,16 @@ module Mints
2
2
  class AdminBaseController < ActionController::Base
3
3
  before_action :set_mints_user_client
4
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
5
+ def mints_user_signed_in?
6
+ # Check status in mints
7
+ response = @mints_user.me
8
+ status = response['data'] ? true : 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
15
 
16
16
  ##
17
17
  # === Mints user Login.
@@ -25,6 +25,21 @@ module Mints
25
25
  cookies.permanent[:mints_user_session_token] = session_token
26
26
  end
27
27
 
28
+ ##
29
+ # === Mints user Login.
30
+ # Starts a user session in mints.cloud and set a session cookie
31
+ def mints_user_magic_link_login(hash)
32
+ # Login in mints
33
+ response = @mints_user.magic_link_login(hash)
34
+ if response['data'] && response['data']['redirect_url']
35
+ # Set a cookie with the session token
36
+ cookies[:mints_user_session_token] = { value: response['data']['api_token'], expires: 1.day }
37
+ redirect_to response['data']['redirect_url']
38
+ else
39
+ redirect_to '/'
40
+ end
41
+ end
42
+
28
43
  ##
29
44
  # === Mints user Logout.
30
45
  # Destroy session from mints.cloud and delete local session cookie
@@ -51,7 +66,8 @@ module Mints
51
66
  raise 'MintsBadCredentialsError'
52
67
  end
53
68
  # Initialize mints user client
54
- @mints_user = Mints::User.new(@host, @api_key, nil, @debug)
69
+ session_token = cookies[:mints_user_session_token] ? cookies[:mints_user_session_token] : nil
70
+ @mints_user = Mints::User.new(@host, @api_key, session_token, @debug)
55
71
  end
56
72
  end
57
73
  end
@@ -1,6 +1,6 @@
1
1
  module Mints
2
2
  class BaseApiController < ActionController::Base
3
- before_action :set_mints_pub_client
3
+ before_action :set_mints_clients
4
4
 
5
5
  ##
6
6
  # === Mints Contact Login.
@@ -15,6 +15,26 @@ module Mints
15
15
  cookies.permanent[:mints_contact_session_token] = session_token
16
16
  cookies.permanent[:mints_contact_id] = id_token
17
17
  @contact_token = id_token
18
+ end
19
+
20
+ ##
21
+ # === Mints cotnact Login.
22
+ # Starts a cotnact session in mints.cloud and set a session cookie
23
+ def mints_contact_magic_link_login(hash)
24
+ # Login in mints
25
+ response = @mints_contact.magic_link_login(hash)
26
+ if response['data']
27
+ # Get session token from response
28
+ session_token = response['data']['session_token']
29
+ id_token = response['data']['contact']['id_token']
30
+ # Set a permanent cookie with the session token
31
+ cookies.permanent[:mints_contact_session_token] = session_token
32
+ cookies.permanent[:mints_contact_id] = id_token
33
+ @contact_token = id_token
34
+ redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
35
+ else
36
+ redirect_to '/'
37
+ end
18
38
  end
19
39
 
20
40
  ##
@@ -28,26 +48,96 @@ module Mints
28
48
  cookies.delete(:mints_contact_id)
29
49
  @contact_token = nil
30
50
  end
51
+
52
+ ##
53
+ # === Mints user Login.
54
+ # Starts a user session in mints.cloud and set a session cookie
55
+ def mints_user_login(email, password)
56
+ # Login in mints
57
+ response = @mints_user.login(email, password)
58
+ # Get session token from response
59
+ session_token = response['api_token']
60
+ # Set a permanent cookie with the session token
61
+ cookies.permanent[:mints_user_session_token] = session_token
62
+ end
63
+
64
+ ##
65
+ # === Mints user Login.
66
+ # Starts a user session in mints.cloud and set a session cookie
67
+ def mints_user_magic_link_login(hash)
68
+ # Login in mints
69
+ response = @mints_user.magic_link_login(hash)
70
+ if response['data']
71
+ # Set a cookie with the session token
72
+ cookies[:mints_user_session_token] = { value: response['data']['api_token'], expires: 1.day }
73
+ redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
74
+ else
75
+ redirect_to '/'
76
+ end
77
+ end
78
+
79
+ ##
80
+ # === Mints user Logout.
81
+ # Destroy session from mints.cloud and delete local session cookie
82
+ def mints_user_logout
83
+ # Logout from mints
84
+ # @mints_user.logout
85
+ # Delete local cookie
86
+ cookies.delete(:mints_user_session_token)
87
+ end
31
88
 
32
89
  private
33
90
 
34
91
  ##
35
- # === Set mints pub.
36
- # Initialize the public client and set the contact token
37
- def set_mints_pub_client
92
+ # === Set mints clients (pub, user and contact)
93
+ # Initialize all clients from mitns
94
+ def set_mints_clients
38
95
  if File.exists?("#{Rails.root}/mints_config.yml.erb")
39
96
  template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
40
97
  config = YAML.load template.result(binding)
41
98
  @host = config["mints"]["host"]
42
99
  @api_key = config["mints"]["api_key"]
43
100
  @debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
101
+
102
+ #public client
103
+ set_mints_pub_client
104
+ #contact client
105
+ set_mints_contact_client
106
+ #user client
107
+ set_mints_user_client
44
108
  else
45
109
  raise 'MintsBadCredentialsError'
46
110
  end
111
+ end
112
+
113
+ ##
114
+ # === Set mints pub.
115
+ # Initialize the public client and set the contact token
116
+ def set_mints_pub_client
117
+
47
118
  # Initialize mints pub client, credentials taken from mints_config.yml.erb file
48
119
  @mints_pub = Mints::Pub.new(@host, @api_key, nil, @debug)
49
120
  # Set contact token from cookie
50
121
  @mints_pub.client.session_token = @contact_token
51
122
  end
123
+
124
+ ##
125
+ # === Set mints contact client.
126
+ # Initialize the public client and set the contact token
127
+ def set_mints_contact_client
128
+ # Initialize mints clontact client
129
+ session_token = cookies[:mints_contact_session_token] ? cookies[:mints_contact_session_token] : nil
130
+ contact_token_id = cookies[:mints_contact_id] ? cookies[:mints_contact_id] : nil
131
+ @mints_contact = Mints::Contact.new(@host, @api_key, session_token, contact_token_id, @debug)
132
+ end
133
+
134
+ ##
135
+ # === Set Mints user client.
136
+ # Initialize the public client and set the user token
137
+ def set_mints_user_client
138
+ # Initialize mints user client
139
+ session_token = cookies[:mints_user_session_token] ? cookies[:mints_user_session_token] : nil
140
+ @mints_user = Mints::User.new(@host, @api_key, session_token, @debug)
141
+ end
52
142
  end
53
143
  end
@@ -31,6 +31,21 @@ module Mints
31
31
  @contact_token = id_token
32
32
  end
33
33
 
34
+ ##
35
+ # === Mints Contact Magic Link Login.
36
+ # Starts a contact session in mints.cloud and set a session cookie
37
+ def mints_contact_magic_link_login(token)
38
+ # Login in mints
39
+ response = @mints_contact.login(email, password)
40
+ # Get session token from response
41
+ session_token = response['session_token']
42
+ id_token = response['contact']['id_token']
43
+ # Set a permanent cookie with the session token
44
+ cookies.permanent[:mints_contact_session_token] = session_token
45
+ cookies.permanent[:mints_contact_id] = id_token
46
+ @contact_token = id_token
47
+ end
48
+
34
49
  ##
35
50
  # === Mints Contact Logout.
36
51
  # Destroy session from mints.cloud and delete local session cookie
@@ -86,7 +101,9 @@ module Mints
86
101
  # Initialize the public client and set the contact token
87
102
  def set_mints_contact_client
88
103
  # Initialize mints clontact client
89
- @mints_contact = Mints::Contact.new(@host, @api_key, nil, @debug)
104
+ session_token = cookies[:mints_contact_session_token] ? cookies[:mints_contact_session_token] : nil
105
+ contact_token_id = cookies[:mints_contact_id] ? cookies[:mints_contact_id] : nil
106
+ @mints_contact = Mints::Contact.new(@host, @api_key, session_token, contact_token_id, @debug)
90
107
  end
91
108
  end
92
109
  end
@@ -14,6 +14,11 @@ module Mints
14
14
  'Content-Type'=> 'application/json',
15
15
  'Accept'=> 'application/json'
16
16
  }
17
+ # Set contact token id as header
18
+ if cookies[:mints_contact_id]
19
+ headers['ContactToken'] = cookies[:mints_contact_id]
20
+ end
21
+ # Set contact session token as header
17
22
  if cookies[:mints_contact_session_token]
18
23
  session_token = cookies[:mints_contact_session_token]
19
24
  headers["Authorization"] = "Bearer #{session_token}"
@@ -14,7 +14,7 @@ module Mints
14
14
  'Content-Type'=> 'application/json',
15
15
  'Accept'=> 'application/json'
16
16
  }
17
- if cookies[:mints_contact_session_token]
17
+ if cookies[:mints_user_session_token]
18
18
  session_token = cookies[:mints_user_session_token]
19
19
  headers["Authorization"] = "Bearer #{session_token}"
20
20
  end
data/lib/pub.rb CHANGED
@@ -5,6 +5,10 @@ module Mints
5
5
  # == Public context API
6
6
  # Pub class contains functions that needs only an API key as authentication
7
7
  # == Usage example
8
+ # === For Mints::BaseController inheritance:
9
+ # If the controller is inheriting from Mints::BaseController, Only use the class variable *mints_pub* _Example:_
10
+ # @mints_pub.get_stories
11
+ # === For standalone usage:
8
12
  # Initialize
9
13
  # pub = Mints::Pub.new(mints_url, api_key)
10
14
  # or if host and api_key are provided by mints_config.yml.erb
@@ -12,23 +16,58 @@ module Mints
12
16
  # Call any function
13
17
  # pub.get_products
14
18
  # == Single resource options
15
- # * +include+ - [String] include a relationship
16
- # * +attributes+ - [Boolean] attach attributes to response
17
- # * +categories+ - [Boolean] attach categories to response
18
- # * +tags+ - [Boolean] attach tags to response
19
+ # * +include+ - [_String_] Specify additional information to be included in the results from the objects relations. _Example:_
20
+ # { "include": "events" }
21
+ # * +attributes+ - [_Boolean_] If present, attributes will be returned for each record in the results. _Example:_
22
+ # { "attributes": true }
23
+ # * +categories+ - [_Boolean_] If present, categories will be returned for each record in the results. _Example:_
24
+ # { "categories": true }
25
+ # * +tags+ - [_Boolean_] If present, tags will be returned for each record in the results. _Example:_
26
+ # { "tags": true }
27
+ # * +fields+ - [_String_] Specify the fields that you want to be returned. If empty, all fields are returned. The object index can also be used to specify specific fields from relations. _Example:_
28
+ # { "fields": "id, title, slug" }
29
+ # { "fields[products]": "id, title, slug" }
30
+ #
19
31
  # == Resource collections options
20
- # * +search+ - [String] filter by a search word
21
- # * +scopes+ - [String] filter by a scope
22
- # * +filters+ - [String] filter by where clauses
23
- # * +jfilters+ - [String] filter using complex condition objects
24
- # * +catfilters+ - [String] filter by categories
25
- # * +fields+ - [String] indicates the columns that will be selected
26
- # * +sort+ - [String] indicates the columns that will be selected
27
- # * +include+ - [String] include a relationship
28
- # * +attributes+ - [Boolean] attach attributes to response
29
- # * +categories+ - [Boolean] attach categories to response
30
- # * +taxonomies+ - [Boolean] attach categories to response
31
- # * +tags+ - [Boolean] attach tags to response
32
+ # * +search+ - [_String_] If present, it will search for records matching the search string. _Example:_
33
+ # { "search": "searchstring" }
34
+ # * +scopes+ - [_String_] If present, it will apply the specified Model's scopes. _Example:_
35
+ # { "scopes": "approved, recent" }
36
+ # * +filters+ - [_String_] This is a powerful parameter that allows the data to be filtered by any of its fields. Currently only exact matches are supported. _Example:_
37
+ # { "filters[title]": "titleToFilter" }
38
+ # * +jfilters+ - [_String_] A complex filter configuration, as used in segments, in JSON format, base64 encoded and URLencoded. _Example:_
39
+ # jfilter = {
40
+ # "type":"group",
41
+ # "items":[
42
+ # {
43
+ # "type":"attribute",
44
+ # "operator":"==",
45
+ # "slug":"title",
46
+ # "value":"Action movies"
47
+ # }
48
+ # ],
49
+ # "operator":"or"
50
+ # }
51
+ # options = { "jfilters": jfilter }
52
+ # * +catfilters+ - [_String_] filter by categories. _Example:_
53
+ # { "catfilters": "categoryName" }
54
+ # * +fields+ - [_String_] Specify the fields that you want to be returned. If empty, all fields are returned. The object index can also be used to specify specific fields from relations. _Example:_
55
+ # { "fields": "id, title, slug" }
56
+ # { "fields[products]": "id, title, slug" }
57
+ # * +sort+ - [_String_] The name of the field to perform the sort. Prefix the value with a minus sign - for ascending order. _Example:_
58
+ # { "sort": "title" }
59
+ # { "sort": "-title" }
60
+ # * +include+ - [_String_] Specify additional information to be included in the results from the objects relations. _Example:_
61
+ # { "include": "events" }
62
+ # * +attributes+ - [_Boolean_] If present, attributes will be returned for each record in the results. _Example:_
63
+ # { "attributes": true }
64
+ # * +categories+ - [_Boolean_] If present, categories will be returned for each record in the results. _Example:_
65
+ # { "categories": true }
66
+ # * +taxonomies+ - [_Boolean_] If present, taxonomies will be returned for each record in the results. _Example:_
67
+ # { "taxonomies": true }
68
+ # * +tags+ - [_Boolean_] If present, tags will be returned for each record in the results. _Example:_
69
+ # { "tags": true }
70
+
32
71
  class Pub
33
72
  attr_reader :client
34
73
 
@@ -42,8 +81,8 @@ module Mints
42
81
  # * +contact_token+ - [String] Cookie 'mints_contact_id' value (mints_contact_token)
43
82
  # ==== Return
44
83
  # Returns a Client object
45
- def initialize(host, api_key, contact_token = nil, debug = false)
46
- @client = Mints::Client.new(host, api_key, 'public', contact_token, debug)
84
+ def initialize(host, api_key, contact_token_id = nil, debug = false)
85
+ @client = Mints::Client.new(host, api_key, 'public', nil, contact_token_id, debug)
47
86
  end
48
87
 
49
88
  ##
@@ -77,58 +116,15 @@ module Mints
77
116
  end
78
117
 
79
118
  ##
80
- # === Get Content Page.
81
- # Get a single content page
82
- #
83
- # ==== Parameters
84
- # * +slug+ - [String] It's the slug
85
- # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
86
- def get_content_page(slug, options = nil)
87
- return @client.raw("get", "/content/content-pages/#{slug}", options)
88
- end
89
-
90
- ##
91
- # === Get Content Templates.
92
- # Get a collection of content templates
93
- #
94
- # ==== Parameters
95
- # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
96
- def get_content_templates(options = nil)
97
- return @client.raw("get", "/content/content-templates", options)
98
- end
99
-
100
- ##
101
- # === Get Content Template.
102
- # Get a single content template.
103
- #
104
- # ==== Parameters
105
- # * +slug+ - [String] It's the string identifier generated by Mints
106
- # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
107
- def get_content_template(slug, options = nil)
108
- return @client.raw("get", "/content/content-templates/#{slug}", options)
109
- end
110
-
111
- ##
112
- # === Get Content Instances.
113
- # Get a collection of content instances
119
+ # === Get Asset Info.
120
+ # Get a description of an Asset
114
121
  #
115
122
  # ==== Parameters
116
- # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
117
- def get_content_instances(options)
118
- return @client.raw("get", "/content/content-instances", options)
123
+ # * +slug+ - [String] It's the string identifier of the asset.
124
+ def get_asset_info(slug)
125
+ return @client.raw("get", "/content/asset-info/#{slug}")
119
126
  end
120
-
121
- ##
122
- # === Get Content Instance.
123
- # Get a single content instance.
124
- #
125
- # ==== Parameters
126
- # * +slug+ - [String] It's the string identifier generated by Mints
127
- # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
128
- def get_content_instance(slug, options = nil)
129
- return @client.raw("get", "/content/content-instances/#{slug}", options)
130
- end
131
-
127
+
132
128
  ##
133
129
  # === Get Stories.
134
130
  # Get a collection of stories
@@ -179,71 +175,81 @@ module Mints
179
175
  # * +data+ - [Hash] Data to be submited
180
176
  def submit_form(data)
181
177
  return @client.raw("post", "/content/forms/submit", nil, data)
182
- end
178
+ end
183
179
 
184
180
  ##
185
- # === Get Products.
186
- # Get a collection of products.
181
+ # === Get Content Instances.
182
+ # Get a collection of content instances
187
183
  #
188
184
  # ==== Parameters
189
185
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
190
- def get_products(options = nil)
191
- return @client.raw("get", "/ecommerce/products", options)
186
+ def get_content_instances(options = nil)
187
+ return @client.raw("get", "/content/content-instances", options)
192
188
  end
193
189
 
194
190
  ##
195
- # === Get Product.
196
- # Get a single product.
191
+ # === Get Content Instance.
192
+ # Get a single content instance.
197
193
  #
198
194
  # ==== Parameters
199
195
  # * +slug+ - [String] It's the string identifier generated by Mints
200
196
  # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
201
- def get_product(slug, options = nil)
202
- return @client.raw("get", "/ecommerce/products/#{slug}", options)
197
+ def get_content_instance(slug, options = nil)
198
+ return @client.raw("get", "/content/content-instances/#{slug}", options)
203
199
  end
204
200
 
205
201
  ##
206
- # === Get Product Brands.
207
- # Get a collection of product brands.
202
+ # === Get Content Pages.
203
+ # Get all content pages.
208
204
  #
209
205
  # ==== Parameters
210
206
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
211
- def get_product_brands(options = nil)
212
- return @client.raw("get", "/ecommerce/product-brands", options)
207
+ def get_content_pages(options = nil)
208
+ return @client.raw("get", "/content/content-pages", options)
213
209
  end
214
210
 
215
211
  ##
216
- # === Get Product Brand.
217
- # Get a product brand.
212
+ # === Get Content Page.
213
+ # Get a single content page
218
214
  #
219
215
  # ==== Parameters
220
- # * +slug+ - [String] It's the string identifier generated by Mints
216
+ # * +slug+ - [String] It's the slug
221
217
  # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
222
- def get_product_brand(slug, options = nil)
223
- return @client.raw("get", "/ecommerce/product-brands/#{slug}", options)
218
+ def get_content_page(slug, options = nil)
219
+ return @client.raw("get", "/content/content-pages/#{slug}", options)
220
+ end
221
+
222
+ ##
223
+ # === Get Locations.
224
+ # Get all locations.
225
+ #
226
+ # ==== Parameters
227
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
228
+ def get_locations(options = nil)
229
+ return @client.raw("get", "/ecommerce/locations", options)
224
230
  end
225
231
 
226
232
  ##
227
- # === Get SKUs.
228
- # Get a collection of SKUs.
233
+ # === Get Products.
234
+ # Get a collection of products.
229
235
  #
230
236
  # ==== Parameters
231
237
  # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
232
- def get_skus(options = nil)
233
- return @client.raw("get", "/ecommerce/skus", options)
238
+ def get_products(options = nil)
239
+ return @client.raw("get", "/ecommerce/products", options)
234
240
  end
235
241
 
236
242
  ##
237
- # === Get SKU.
238
- # Get a single SKU.
243
+ # === Get Product.
244
+ # Get a single product.
239
245
  #
240
246
  # ==== Parameters
241
247
  # * +slug+ - [String] It's the string identifier generated by Mints
242
248
  # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
243
- def get_sku(slug, options = nil)
244
- return @client.raw("get", "/ecommerce/skus/#{slug}", options)
249
+ def get_product(slug, options = nil)
250
+ return @client.raw("get", "/ecommerce/products/#{slug}", options)
245
251
  end
246
-
252
+
247
253
  ##
248
254
  # === Get categories.
249
255
  # Get a collection of categories.
@@ -286,16 +292,6 @@ module Mints
286
292
  return @client.raw("get", "/config/tags/#{slug}", options)
287
293
  end
288
294
 
289
- ##
290
- # === Get Attributes.
291
- # Get a collection of attributes.
292
- #
293
- # ==== Parameters
294
- # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
295
- def get_attributes(options = nil)
296
- return @client.raw("get", "/config/attributes", options)
297
- end
298
-
299
295
  ##
300
296
  # === Get Taxonomies.
301
297
  # Get a collection of taxonomies.
@@ -316,5 +312,15 @@ module Mints
316
312
  def get_taxonomy(slug, options = nil)
317
313
  return @client.raw("get", "/config/taxonomies/#{slug}", options)
318
314
  end
315
+
316
+ ##
317
+ # === Get Attributes.
318
+ # Get a collection of attributes.
319
+ #
320
+ # ==== Parameters
321
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
322
+ def get_attributes(options = nil)
323
+ return @client.raw("get", "/config/attributes", options)
324
+ end
319
325
  end
320
326
  end
data/lib/user.rb CHANGED
@@ -29,7 +29,7 @@ module Mints
29
29
  class User
30
30
  attr_reader :client
31
31
  def initialize(host, api_key, session_token = nil, debug = false)
32
- @client = Mints::Client.new(host, api_key, 'user', session_token, debug)
32
+ @client = Mints::Client.new(host, api_key, 'user', session_token, nil, debug)
33
33
  end
34
34
 
35
35
  def login(email, password)
@@ -43,6 +43,31 @@ module Mints
43
43
  end
44
44
  return response
45
45
  end
46
+
47
+ def magic_link_login(token)
48
+ response = @client.raw("get", "/users/magic-link-login/#{token}", nil, nil, '/api/v1')
49
+ return response
50
+ end
51
+
52
+ ##
53
+ # === Send magic link to user
54
+ def send_magic_link(email, redirectUrl = '', lifeTime = 24)
55
+ data = {
56
+ email: email,
57
+ redirectUrl: redirectUrl,
58
+ lifeTime: lifeTime
59
+ }
60
+ response = @client.raw("post", "/users/magic-link", nil, { data: data }, '/api/v1')
61
+ return response
62
+ end
63
+
64
+ ##
65
+ # === Me.
66
+ # Get contact logged info
67
+ #
68
+ def me
69
+ return @client.get__profile__me
70
+ end
46
71
  ######################################### CRM #########################################
47
72
  ##
48
73
  # === Get contacts.
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.12
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Gomez Garcia, Omar Mora, Luis Payan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-22 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -120,6 +120,7 @@ files:
120
120
  - README.md
121
121
  - lib/client.rb
122
122
  - lib/contact.rb
123
+ - lib/generators/mints_assets_controller.rb
123
124
  - lib/generators/mints_config.yml.erb
124
125
  - lib/generators/mints_contact_controller.rb
125
126
  - lib/generators/mints_files_generator.rb