mints 0.0.28 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/lib/client.rb +287 -385
  3. data/lib/contact/config/appointments.rb +201 -0
  4. data/lib/contact/config/config.rb +7 -0
  5. data/lib/contact/content/content.rb +7 -0
  6. data/lib/contact/content/conversations.rb +121 -0
  7. data/lib/contact/ecommerce/ecommerce.rb +14 -0
  8. data/lib/contact/ecommerce/order_items.rb +19 -0
  9. data/lib/contact/ecommerce/order_items_groups.rb +95 -0
  10. data/lib/contact/ecommerce/orders.rb +132 -0
  11. data/lib/contact/ecommerce/vouchers.rb +18 -0
  12. data/lib/contact.rb +54 -603
  13. data/lib/errors.rb +4 -2
  14. data/lib/generators/mints_assets_controller.rb +4 -1
  15. data/lib/generators/mints_contact_controller.rb +4 -1
  16. data/lib/generators/mints_files_generator.rb +16 -13
  17. data/lib/generators/mints_link.rb +7 -4
  18. data/lib/generators/mints_public_controller.rb +4 -1
  19. data/lib/generators/mints_user_controller.rb +3 -0
  20. data/lib/generators/short_link_controller.rb +4 -1
  21. data/lib/mints/controllers/admin_base_controller.rb +5 -3
  22. data/lib/mints/controllers/base_api_controller.rb +6 -4
  23. data/lib/mints/controllers/base_controller.rb +5 -3
  24. data/lib/mints/controllers/concerns/mints_clients.rb +4 -2
  25. data/lib/mints/controllers/concerns/read_config_file.rb +3 -1
  26. data/lib/mints/controllers/contact_api_controller.rb +12 -10
  27. data/lib/mints/controllers/public_api_controller.rb +10 -8
  28. data/lib/mints/controllers/user_api_controller.rb +11 -9
  29. data/lib/mints/helpers/contact_auth_helper.rb +5 -3
  30. data/lib/mints/helpers/mints_helper.rb +39 -38
  31. data/lib/mints/helpers/proxy_controllers_methods.rb +24 -24
  32. data/lib/mints/helpers/user_auth_helper.rb +5 -3
  33. data/lib/mints.rb +12 -10
  34. data/lib/pub/config/attributes.rb +13 -0
  35. data/lib/pub/config/config.rb +15 -0
  36. data/lib/pub/config/public_folders.rb +51 -0
  37. data/lib/pub/config/tags.rb +42 -0
  38. data/lib/pub/config/taxonomies.rb +49 -0
  39. data/lib/pub/content/assets.rb +16 -0
  40. data/lib/pub/content/content.rb +22 -0
  41. data/lib/pub/content/content_bundles.rb +40 -0
  42. data/lib/pub/content/content_instance_versions.rb +56 -0
  43. data/lib/pub/content/content_instances.rb +37 -0
  44. data/lib/pub/content/forms.rb +47 -0
  45. data/lib/pub/content/stories.rb +44 -0
  46. data/lib/pub/content/story_versions.rb +46 -0
  47. data/lib/pub/ecommerce/ecommerce.rb +14 -0
  48. data/lib/pub/ecommerce/locations.rb +25 -0
  49. data/lib/pub/ecommerce/orders.rb +31 -0
  50. data/lib/pub/ecommerce/products.rb +45 -0
  51. data/lib/pub.rb +22 -461
  52. data/lib/user/config/api_keys.rb +63 -61
  53. data/lib/user/config/appointments.rb +217 -215
  54. data/lib/user/config/attribute_groups.rb +74 -72
  55. data/lib/user/config/attributes.rb +83 -81
  56. data/lib/user/config/calendars.rb +88 -86
  57. data/lib/user/config/config.rb +31 -63
  58. data/lib/user/config/public_folders.rb +105 -104
  59. data/lib/user/config/relationships.rb +135 -132
  60. data/lib/user/config/roles.rb +76 -79
  61. data/lib/user/config/seeds.rb +52 -51
  62. data/lib/user/config/system_settings.rb +50 -49
  63. data/lib/user/config/tags.rb +57 -59
  64. data/lib/user/config/taxonomies.rb +115 -119
  65. data/lib/user/config/teams.rb +2 -0
  66. data/lib/user/config/users.rb +2 -0
  67. data/lib/user/contacts/contacts.rb +2 -0
  68. data/lib/user/content/assets.rb +3 -3
  69. data/lib/user/content/content.rb +224 -223
  70. data/lib/user/content/content_instances.rb +4 -2
  71. data/lib/user/content/content_templates.rb +2 -0
  72. data/lib/user/content/conversations.rb +2 -0
  73. data/lib/user/content/dam.rb +2 -0
  74. data/lib/user/content/forms.rb +2 -0
  75. data/lib/user/content/message_templates.rb +2 -0
  76. data/lib/user/content/messages.rb +2 -0
  77. data/lib/user/content/pages.rb +4 -2
  78. data/lib/user/content/stories.rb +3 -3
  79. data/lib/user/content/story_templates.rb +5 -3
  80. data/lib/user/content/story_versions.rb +2 -0
  81. data/lib/user/crm/companies.rb +3 -1
  82. data/lib/user/crm/contacts.rb +2 -0
  83. data/lib/user/crm/crm.rb +2 -0
  84. data/lib/user/crm/deals.rb +2 -0
  85. data/lib/user/crm/favorites.rb +2 -0
  86. data/lib/user/crm/segments.rb +2 -0
  87. data/lib/user/crm/users.rb +2 -0
  88. data/lib/user/crm/workflow_step_objects.rb +2 -0
  89. data/lib/user/crm/workflow_steps.rb +2 -0
  90. data/lib/user/crm/workflows.rb +2 -0
  91. data/lib/user/ecommerce/ecommerce.rb +4 -0
  92. data/lib/user/ecommerce/item_prices.rb +2 -0
  93. data/lib/user/ecommerce/locations.rb +4 -2
  94. data/lib/user/ecommerce/order_items_groups.rb +5 -2
  95. data/lib/user/ecommerce/order_statuses.rb +2 -0
  96. data/lib/user/ecommerce/orders.rb +4 -1
  97. data/lib/user/ecommerce/price_lists.rb +2 -0
  98. data/lib/user/ecommerce/product_templates.rb +3 -1
  99. data/lib/user/ecommerce/product_variations.rb +2 -0
  100. data/lib/user/ecommerce/products.rb +3 -1
  101. data/lib/user/ecommerce/skus.rb +2 -0
  102. data/lib/user/ecommerce/taxes.rb +2 -0
  103. data/lib/user/ecommerce/variant_options.rb +2 -0
  104. data/lib/user/ecommerce/variant_values.rb +2 -0
  105. data/lib/user/ecommerce/vouchers.rb +90 -0
  106. data/lib/user/helpers/helpers.rb +2 -0
  107. data/lib/user/helpers/object_activities.rb +2 -0
  108. data/lib/user/helpers/object_folders.rb +2 -0
  109. data/lib/user/helpers/user_folders.rb +2 -0
  110. data/lib/user/marketing/marketing.rb +2 -0
  111. data/lib/user/profile/profile.rb +2 -0
  112. data/lib/user.rb +32 -41
  113. metadata +42 -16
  114. data/lib/user/config/importers.rb +0 -184
data/lib/errors.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mints
2
4
 
3
5
  module Errors
@@ -9,7 +11,7 @@ module Mints
9
11
  '401' => 'AccessDeniedException',
10
12
  '404' => 'ResourceNotFoundException',
11
13
  '422' => 'ValidationException',
12
- '405' => 'MethodNotAllowed',
14
+ '405' => 'MethodNotAllowedException',
13
15
  'default' => 'InternalServerException',
14
16
  }
15
17
 
@@ -85,7 +87,7 @@ module Mints
85
87
 
86
88
  def errors_hash
87
89
  {
88
- errors: response.keys.reduce([]) {|carry, error_key| carry + response[error_key]}
90
+ errors: response.keys.reduce([]) { |carry, error_key| carry + response[error_key] }
89
91
  }
90
92
  end
91
93
 
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'reverse_proxy/client'
2
- class MintsAssetsController < Mints::PublicAPIController
4
+
5
+ class MintsAssetsController < Mints::PublicAPIController
3
6
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'reverse_proxy/client'
2
- class Api::V1::MintsContactController < Mints::ContactAPIController
4
+
5
+ class Api::V1::MintsContactController < Mints::ContactAPIController
3
6
  end
@@ -1,15 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  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.erb', 'mints_config.yml.erb'
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
- copy_file 'mints_assets_controller.rb', './app/controllers/mints_assets_controller.rb'
10
- copy_file 'short_link_controller.rb', './app/controllers/short_link_controller.rb'
11
- copy_file 'mints_link.rb', './config/initializers/mints_link.rb'
12
- route <<-eos
4
+ source_root(File.expand_path(File.dirname(__FILE__)))
5
+ include Rails::Generators::Actions
6
+
7
+ def create_mints_files
8
+ copy_file 'mints_config.yml.erb', 'mints_config.yml.erb'
9
+ copy_file 'mints_user_controller.rb', './app/controllers/api/mints_user_controller.rb'
10
+ copy_file 'mints_contact_controller.rb', './app/controllers/api/v1/mints_contact_controller.rb'
11
+ copy_file 'mints_public_controller.rb', './app/controllers/api/v1/mints_public_controller.rb'
12
+ copy_file 'mints_assets_controller.rb', './app/controllers/mints_assets_controller.rb'
13
+ copy_file 'short_link_controller.rb', './app/controllers/short_link_controller.rb'
14
+ copy_file 'mints_link.rb', './config/initializers/mints_link.rb'
15
+ route <<-eos
13
16
  # Mints auto-generated routes (proxy to send request to mints.cloud)
14
17
  match '/public-assets/*path' => 'mints_assets#index', via: [:get, :post, :put, :patch, :delete]
15
18
  namespace :api, defaults: { format: :json } do
@@ -24,6 +27,6 @@ class MintsFilesGenerator < Rails::Generators::Base
24
27
  get '/sl/visits', to: 'short_link#visits'
25
28
  post '/sl/generate', to: 'short_link#generate'
26
29
  get '/sl/:code', to: 'short_link#redirect'
27
- eos
28
- end
30
+ eos
31
+ end
29
32
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MintsLink
2
4
  def initialize
3
5
  @host = ENV['MONGO_HOST'] || '127.0.0.1'
4
6
  @database = ENV['MONGO_DATABASE'] || 'mints'
5
7
  @port = ENV['MONGO_PORT'] || '27017'
6
- @client = Mongo::Client.new([ "#{@host}:#{@port}" ], :database => @database)
8
+ @client = Mongo::Client.new(["#{@host}:#{@port}"], :database => @database)
7
9
  @short_links = @client[:short_links]
8
10
  @sl_visits = @client[:sl_visits]
9
11
  generate_indexes
@@ -27,7 +29,7 @@ class MintsLink
27
29
 
28
30
  def get_url(code)
29
31
  collection = @short_links
30
- record = collection.find( { 'code' => code } ).first
32
+ record = collection.find({ 'code' => code }).first
31
33
  record["url"]
32
34
  end
33
35
 
@@ -46,16 +48,17 @@ class MintsLink
46
48
 
47
49
  def get_visits(filter, page = 1, page_size = 1000)
48
50
  collection = @sl_visits
49
- collection.find(filter).sort( {_id: 1}).skip(page * page_size - page_size).limit(page_size)
51
+ collection.find(filter).sort({ _id: 1 }).skip(page * page_size - page_size).limit(page_size)
50
52
  end
51
53
 
52
54
  private
55
+
53
56
  def random_string(length = 6)
54
57
  rand((32 ** length).to_i).to_s(32)
55
58
  end
56
59
 
57
60
  def generate_indexes
58
61
  collection = @short_links
59
- collection.indexes.create_one({ code: 1 }, {unique: true })
62
+ collection.indexes.create_one({ code: 1 }, { unique: true })
60
63
  end
61
64
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'reverse_proxy/client'
2
- class Api::V1::MintsPublicController < Mints::PublicAPIController
4
+
5
+ class Api::V1::MintsPublicController < Mints::PublicAPIController
3
6
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'reverse_proxy/client'
4
+
2
5
  class Api::MintsUserController < Mints::UserAPIController
3
6
  end
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ShortLinkController < Mints::BaseController
2
4
  skip_before_action :verify_authenticity_token
5
+
3
6
  def redirect
4
7
  code = params[:code]
5
8
  mints_link = MintsLink.new
@@ -36,6 +39,6 @@ class ShortLinkController < Mints::BaseController
36
39
  end
37
40
  mints_link = MintsLink.new
38
41
  visits = mints_link.get_visits(filter, page, page_size)
39
- render json: { data: {visits: visits }}
42
+ render json: { data: { visits: visits } }
40
43
  end
41
44
  end
@@ -1,5 +1,7 @@
1
- require_relative "./concerns/mints_clients.rb"
2
- require_relative "../helpers/user_auth_helper.rb"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './concerns/mints_clients'
4
+ require_relative '../helpers/user_auth_helper'
3
5
 
4
6
  module Mints
5
7
  class AdminBaseController < ActionController::Base
@@ -9,7 +11,7 @@ module Mints
9
11
 
10
12
  # Override default values for mints clients concern
11
13
  def define_mints_clients
12
- %w[ user service_account ]
14
+ %w[user service_account]
13
15
  end
14
16
  end
15
17
  end
@@ -1,6 +1,8 @@
1
- require_relative "./concerns/mints_clients.rb"
2
- require_relative "../helpers/user_auth_helper.rb"
3
- require_relative "../helpers/contact_auth_helper.rb"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './concerns/mints_clients'
4
+ require_relative '../helpers/user_auth_helper'
5
+ require_relative '../helpers/contact_auth_helper'
4
6
 
5
7
  module Mints
6
8
  class BaseApiController < ActionController::Base
@@ -12,7 +14,7 @@ module Mints
12
14
  include UserAuthHelper
13
15
 
14
16
  def define_mints_clients
15
- %w[ contact pub ]
17
+ %w[contact pub]
16
18
  end
17
19
 
18
20
  ##
@@ -1,5 +1,7 @@
1
- require_relative "./concerns/mints_clients.rb"
2
- require_relative "../helpers/contact_auth_helper.rb"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './concerns/mints_clients'
4
+ require_relative '../helpers/contact_auth_helper'
3
5
 
4
6
  module Mints
5
7
  class BaseController < ActionController::Base
@@ -13,7 +15,7 @@ module Mints
13
15
 
14
16
  # Override default values for mints clients concern
15
17
  def define_mints_clients
16
- %w[ contact pub ]
18
+ %w[contact pub]
17
19
  end
18
20
 
19
21
  private
@@ -1,4 +1,6 @@
1
- require_relative "./read_config_file.rb"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./read_config_file"
2
4
 
3
5
  module MintsClients
4
6
  extend ActiveSupport::Concern
@@ -11,7 +13,7 @@ module MintsClients
11
13
  # Define the clients that will have
12
14
  # Override in the controller if you dont wanna all clients
13
15
  def define_mints_clients
14
- %w[ contact user pub service_account ]
16
+ %w[contact user pub service_account]
15
17
  end
16
18
 
17
19
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ReadConfigFile
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -16,7 +18,7 @@ module ReadConfigFile
16
18
  @redis_config = config['redis_cache']
17
19
  @use_cache = config['redis_cache']['use_cache']
18
20
 
19
- if config['redis_cache']['use_cache']
21
+ if @use_cache
20
22
  @redis_server = Redis.new(
21
23
  host: config['redis_cache']['redis_host'],
22
24
  port: config['redis_cache']['redis_port'] || 6379,
@@ -1,15 +1,17 @@
1
- require_relative "./concerns/read_config_file.rb"
2
- require_relative "../helpers/proxy_controllers_methods.rb"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './concerns/read_config_file'
4
+ require_relative '../helpers/proxy_controllers_methods'
3
5
 
4
6
  module Mints
5
- class ContactAPIController < ActionController::API
6
- include AbstractController::Helpers
7
- include ReverseProxy::Controller
8
- include ReadConfigFile
9
- include ProxyControllersMethods
7
+ class ContactAPIController < ActionController::API
8
+ include AbstractController::Helpers
9
+ include ReverseProxy::Controller
10
+ include ReadConfigFile
11
+ include ProxyControllersMethods
10
12
 
11
- def index
12
- super('contact')
13
- end
13
+ def index
14
+ super('contact')
14
15
  end
16
+ end
15
17
  end
@@ -1,12 +1,14 @@
1
- require_relative "./concerns/read_config_file.rb"
2
- require_relative "../helpers/proxy_controllers_methods.rb"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './concerns/read_config_file'
4
+ require_relative '../helpers/proxy_controllers_methods'
3
5
 
4
6
  module Mints
5
- class PublicAPIController < ActionController::API
6
- include ReverseProxy::Controller
7
- include AbstractController::Helpers
8
- include ReadConfigFile
9
- include ProxyControllersMethods
7
+ class PublicAPIController < ActionController::API
8
+ include ReverseProxy::Controller
9
+ include AbstractController::Helpers
10
+ include ReadConfigFile
11
+ include ProxyControllersMethods
10
12
 
11
- end
13
+ end
12
14
  end
@@ -1,14 +1,16 @@
1
- require_relative "./concerns/read_config_file.rb"
2
- require_relative "../helpers/proxy_controllers_methods.rb"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './concerns/read_config_file'
4
+ require_relative '../helpers/proxy_controllers_methods'
3
5
 
4
6
  module Mints
5
- class UserAPIController < ActionController::API
6
- include AbstractController::Helpers
7
- include ReadConfigFile
8
- include ProxyControllersMethods
7
+ class UserAPIController < ActionController::API
8
+ include AbstractController::Helpers
9
+ include ReadConfigFile
10
+ include ProxyControllersMethods
9
11
 
10
- def index
11
- super('user')
12
- end
12
+ def index
13
+ super('user')
13
14
  end
15
+ end
14
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ContactAuthHelper
2
4
  ##
3
5
  # === Mints Contact Login.
@@ -29,7 +31,7 @@ module ContactAuthHelper
29
31
  cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
30
32
  cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
31
33
  @contact_token = id_token
32
- redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/' if redirect_in_error
34
+ redirect_to response['data']['redirect_url'] || '/' if redirect_in_error
33
35
  else
34
36
  redirect_to '/' if redirect_in_error
35
37
  end
@@ -41,9 +43,9 @@ module ContactAuthHelper
41
43
  def mints_contact_logout
42
44
  # Logout from mints
43
45
  @mints_contact.logout
44
- # Delete local cookie
46
+ # Delete session token and keep the contact token id
47
+ # Never delete the mints_contact_id cookie to avoid the creation of ghosts
45
48
  cookies.delete(:mints_contact_session_token)
46
- cookies.delete(:mints_contact_id)
47
49
  @contact_token = nil
48
50
  end
49
51
 
@@ -1,49 +1,50 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module MintsHelper
3
- # === Get query results.
4
- # Method used to give the options to make a 'post' or 'get' request.
5
- #
6
- # ==== Parameters
7
- # url:: (String) -- Url to make the request.
8
- # options:: (Hash) -- List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter.
9
- # use_post:: (Boolean) -- Variable to determine if the request is by 'post' or 'get' functions.
10
- #
11
- def get_query_results(url, options = nil, use_post = true)
12
- if use_post
13
- @client.raw('post', "#{url}/query", options)
14
- else
15
- @client.raw('get', url, options)
16
- end
4
+ # === Get query results.
5
+ # Method used to give the options to make a 'post' or 'get' request.
6
+ #
7
+ # ==== Parameters
8
+ # url:: (String) -- Url to make the request.
9
+ # options:: (Hash) -- List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter.
10
+ # use_post:: (Boolean) -- Variable to determine if the request is by 'post' or 'get' functions.
11
+ #
12
+ def get_query_results(url, options = nil, use_post = true)
13
+ if use_post
14
+ @client.raw('post', "#{url}/query", options)
15
+ else
16
+ @client.raw('get', url, options)
17
17
  end
18
+ end
18
19
 
19
- # === Data transform.
20
- # Transform a 'data' variable to a standardized 'data' variable.
21
- #
22
- # ==== Parameters
23
- # data:: (Hash) -- Data to be submitted.
24
- #
25
- def data_transform(data)
26
- data = correct_json(data)
20
+ # === Data transform.
21
+ # Transform a 'data' variable to a standardized 'data' variable.
22
+ #
23
+ # ==== Parameters
24
+ # data:: (Hash) -- Data to be submitted.
25
+ #
26
+ def data_transform(data)
27
+ data = correct_json(data)
27
28
 
28
- unless data[:data]
29
- data = {data: data}
30
- end
31
-
32
- data.to_json
29
+ unless data[:data]
30
+ data = { data: data }
33
31
  end
34
32
 
35
- # === Correct json.
36
- # Receives a json data and convert it to a symbolized object.
37
- #
38
- # ==== Parameters
39
- # data:: (Hash) -- Data to be submitted.
40
- #
41
- def correct_json(data)
42
- if data.is_a? String
43
- data = JSON.parse(data)
44
- end
33
+ data.to_json
34
+ end
45
35
 
46
- data.symbolize_keys
36
+ # === Correct json.
37
+ # Receives a json data and convert it to a symbolized object.
38
+ #
39
+ # ==== Parameters
40
+ # data:: (Hash) -- Data to be submitted.
41
+ #
42
+ def correct_json(data)
43
+ if data.is_a? String
44
+ data = JSON.parse(data)
47
45
  end
48
46
 
47
+ data.symbolize_keys
48
+ end
49
+
49
50
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'redis'
2
4
  require 'reverse_proxy/controller'
3
5
  require 'reverse_proxy/client'
@@ -17,18 +19,18 @@ module ProxyControllersMethods
17
19
  #
18
20
  def index(controller_type = nil)
19
21
  headers = {
20
- 'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
21
- 'ApiKey' => "#{@api_key}",
22
- 'Content-Type'=> 'application/json',
23
- 'Accept'=> 'application/json'
22
+ 'host' => @host.gsub('http://', '').gsub('https://', ''),
23
+ 'ApiKey' => @api_key.to_s,
24
+ 'Content-Type' => 'application/json',
25
+ 'Accept' => 'application/json'
24
26
  }
25
27
 
26
28
  if %w[contact user].include? controller_type
27
29
  session_token = cookies["mints_#{controller_type}_session_token".to_sym]
28
- headers["Authorization"] = session_token ? "Bearer #{session_token}" : request.headers["Authorization"]
30
+ headers['Authorization'] = session_token ? "Bearer #{session_token}" : request.headers['Authorization']
29
31
  end
30
32
 
31
- headers['ContactToken'] = cookies[:mints_contact_id] if controller_type === 'contact' and cookies[:mints_contact_id]
33
+ headers['ContactToken'] = cookies[:mints_contact_id] if controller_type == 'contact' && cookies[:mints_contact_id]
32
34
 
33
35
  full_url = request.original_url
34
36
  url_need_cache, time = url_need_cache?(full_url)
@@ -44,7 +46,7 @@ module ProxyControllersMethods
44
46
  cached_response = @redis_server.get(full_url)
45
47
 
46
48
  if cached_response
47
- puts "RESPONSE FROM CACHE" if @debug
49
+ puts 'RESPONSE FROM CACHE' if @debug
48
50
  return render json: cached_response
49
51
  end
50
52
 
@@ -67,21 +69,19 @@ module ProxyControllersMethods
67
69
  time = 0
68
70
  methods_with_cache = %w[GET]
69
71
 
70
- if methods_with_cache.include? request.method
71
- if @use_cache
72
- @redis_config['groups'].each do |group|
73
- group['urls'].each do |url|
74
-
75
- if full_url.match url
76
- time = group['time']
77
- url_need_cache = true
78
- break
79
- end
72
+ if methods_with_cache.include? request.method && @use_cache
73
+ @redis_config['groups'].each do |group|
74
+ group['urls'].each do |url|
80
75
 
76
+ if full_url.match url
77
+ time = group['time']
78
+ url_need_cache = true
79
+ break
81
80
  end
82
81
 
83
- break if url_need_cache
84
82
  end
83
+
84
+ break if url_need_cache
85
85
  end
86
86
  end
87
87
 
@@ -100,14 +100,14 @@ module ProxyControllersMethods
100
100
  # ==== Return
101
101
  # Returns the response given by CXF or Redis
102
102
 
103
- def send_mints_request(full_url, headers, cache_result = false, time = 30)
104
- puts "RESPONSE FROM MINTS.CLOUD" if @debug
103
+ def send_mints_request(full_url, headers, cache_result = false, time: 30)
104
+ puts 'RESPONSE FROM MINTS.CLOUD' if @debug
105
105
 
106
- reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
106
+ reverse_proxy @host, headers: headers, verify_ssl: false do |config|
107
107
 
108
108
  if cache_result
109
109
  # Request succeeded!
110
- config.on_response do |code, response|
110
+ config.on_response do |_status_code, response|
111
111
  @redis_server.setex(
112
112
  full_url,
113
113
  time || 30,
@@ -117,9 +117,9 @@ module ProxyControllersMethods
117
117
  end
118
118
 
119
119
  # Request failed!
120
- config.on_missing do |code, response|
120
+ config.on_missing do |status_code, _response|
121
121
  # We got a 404!
122
- raise ActionController::RoutingError.new('Not Found') if code == 404
122
+ raise ActionController::RoutingError.new('Not Found') if status_code == 404
123
123
  end
124
124
  end
125
125
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module UserAuthHelper
2
4
 
3
5
  def mints_user_signed_in?
@@ -34,8 +36,8 @@ module UserAuthHelper
34
36
  response = @mints_user.magic_link_login(hash)
35
37
  if response['data']
36
38
  # Set a cookie with the session token
37
- cookies[:mints_user_session_token] = { value: response['data']['api_token'], secure: true, httponly: true, expires: 1.day }
38
- redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
39
+ cookies[:mints_user_session_token] = { value: response['data']['api_token'], secure: true, httponly: true, expires: 1.day }
40
+ redirect_to response['data']['redirect_url'] || '/'
39
41
  else
40
42
  redirect_to '/'
41
43
  end
@@ -50,4 +52,4 @@ module UserAuthHelper
50
52
  # Delete local cookie
51
53
  cookies.delete(:mints_user_session_token)
52
54
  end
53
- end
55
+ end
data/lib/mints.rb CHANGED
@@ -1,13 +1,15 @@
1
- require_relative "./pub.rb"
2
- require_relative "./contact.rb"
3
- require_relative "./user.rb"
4
- require_relative "./mints/controllers/base_controller.rb"
5
- require_relative "./mints/controllers/base_api_controller.rb"
6
- require_relative "./mints/controllers/admin_base_controller.rb"
7
- require_relative "./mints/controllers/public_api_controller.rb"
8
- require_relative "./mints/controllers/contact_api_controller.rb"
9
- require_relative "./mints/controllers/user_api_controller.rb"
10
- require_relative './errors.rb'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './pub'
4
+ require_relative './contact'
5
+ require_relative './user'
6
+ require_relative './mints/controllers/base_controller'
7
+ require_relative './mints/controllers/base_api_controller'
8
+ require_relative './mints/controllers/admin_base_controller'
9
+ require_relative './mints/controllers/public_api_controller'
10
+ require_relative './mints/controllers/contact_api_controller'
11
+ require_relative './mints/controllers/user_api_controller'
12
+ require_relative './errors'
11
13
 
12
14
  module Mints
13
15
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Attributes
4
+ ##
5
+ # === Get Attributes.
6
+ # Get a collection of attributes.
7
+ #
8
+ # ==== Example
9
+ # @data = @mints_pub.get_attributes
10
+ def get_attributes
11
+ @client.raw('get', '/config/attributes')
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ ### V1/CONFIG ###
4
+
5
+ require_relative './attributes'
6
+ require_relative './public_folders'
7
+ require_relative './tags'
8
+ require_relative './taxonomies'
9
+
10
+ module Config
11
+ include Attributes
12
+ include PublicFolders
13
+ include Tags
14
+ include Taxonomies
15
+ end