cxf 0.0.1

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 (79) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +12 -0
  3. data/README.md +395 -0
  4. data/lib/client.rb +447 -0
  5. data/lib/contact/config/config.rb +4 -0
  6. data/lib/contact/content/content.rb +4 -0
  7. data/lib/contact/ecommerce/ecommerce.rb +4 -0
  8. data/lib/contact.rb +284 -0
  9. data/lib/cxf/controllers/admin_base_controller.rb +17 -0
  10. data/lib/cxf/controllers/base_api_controller.rb +28 -0
  11. data/lib/cxf/controllers/base_controller.rb +54 -0
  12. data/lib/cxf/controllers/concerns/cxf_clients.rb +104 -0
  13. data/lib/cxf/controllers/concerns/read_config_file.rb +30 -0
  14. data/lib/cxf/controllers/contact_api_controller.rb +17 -0
  15. data/lib/cxf/controllers/public_api_controller.rb +14 -0
  16. data/lib/cxf/controllers/user_api_controller.rb +16 -0
  17. data/lib/cxf/helpers/contact_auth_helper.rb +86 -0
  18. data/lib/cxf/helpers/cxf_helper.rb +52 -0
  19. data/lib/cxf/helpers/proxy_controllers_methods.rb +144 -0
  20. data/lib/cxf/helpers/threads_helper.rb +109 -0
  21. data/lib/cxf/helpers/user_auth_helper.rb +74 -0
  22. data/lib/cxf.rb +15 -0
  23. data/lib/errors.rb +109 -0
  24. data/lib/generators/cxf_assets_controller.rb +7 -0
  25. data/lib/generators/cxf_config.yml.erb +27 -0
  26. data/lib/generators/cxf_contact_controller.rb +7 -0
  27. data/lib/generators/cxf_files_generator.rb +28 -0
  28. data/lib/generators/cxf_public_controller.rb +7 -0
  29. data/lib/generators/cxf_user_controller.rb +7 -0
  30. data/lib/pub/config/config.rb +6 -0
  31. data/lib/pub/content/assets.rb +16 -0
  32. data/lib/pub/content/content.rb +9 -0
  33. data/lib/pub/ecommerce/ecommerce.rb +6 -0
  34. data/lib/pub.rb +163 -0
  35. data/lib/user/config/attribute_groups.rb +79 -0
  36. data/lib/user/config/attributes.rb +88 -0
  37. data/lib/user/config/calendars.rb +91 -0
  38. data/lib/user/config/config.rb +23 -0
  39. data/lib/user/config/relationships.rb +141 -0
  40. data/lib/user/config/seeds.rb +55 -0
  41. data/lib/user/config/system_settings.rb +54 -0
  42. data/lib/user/config/tags.rb +61 -0
  43. data/lib/user/config/taxonomies.rb +120 -0
  44. data/lib/user/config/users.rb +77 -0
  45. data/lib/user/config/views.rb +68 -0
  46. data/lib/user/contacts/contacts.rb +22 -0
  47. data/lib/user/content/assets.rb +294 -0
  48. data/lib/user/content/block_templates.rb +72 -0
  49. data/lib/user/content/blocks.rb +109 -0
  50. data/lib/user/content/content.rb +174 -0
  51. data/lib/user/content/instances.rb +121 -0
  52. data/lib/user/content/print_versions.rb +129 -0
  53. data/lib/user/content/stories.rb +110 -0
  54. data/lib/user/content/story_templates.rb +97 -0
  55. data/lib/user/content/templates.rb +72 -0
  56. data/lib/user/crm/companies.rb +111 -0
  57. data/lib/user/crm/contacts.rb +294 -0
  58. data/lib/user/crm/crm.rb +9 -0
  59. data/lib/user/ecommerce/ecommerce.rb +29 -0
  60. data/lib/user/ecommerce/item_prices.rb +89 -0
  61. data/lib/user/ecommerce/locations.rb +171 -0
  62. data/lib/user/ecommerce/price_lists.rb +75 -0
  63. data/lib/user/ecommerce/product_templates.rb +106 -0
  64. data/lib/user/ecommerce/product_variations.rb +133 -0
  65. data/lib/user/ecommerce/product_versions.rb +107 -0
  66. data/lib/user/ecommerce/products.rb +156 -0
  67. data/lib/user/ecommerce/skus.rb +90 -0
  68. data/lib/user/ecommerce/taxes.rb +84 -0
  69. data/lib/user/ecommerce/variant_options.rb +71 -0
  70. data/lib/user/ecommerce/variant_values.rb +74 -0
  71. data/lib/user/ecommerce/vouchers.rb +90 -0
  72. data/lib/user/helpers/helpers.rb +116 -0
  73. data/lib/user/helpers/object_activities.rb +85 -0
  74. data/lib/user/helpers/object_folders.rb +84 -0
  75. data/lib/user/helpers/user_folders.rb +85 -0
  76. data/lib/user/marketing/marketing.rb +123 -0
  77. data/lib/user/profile/profile.rb +104 -0
  78. data/lib/user.rb +98 -0
  79. metadata +227 -0
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CxfHelper
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-Cxf::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
+ end
18
+ end
19
+
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
+ return data if data.nil?
28
+
29
+ data = correct_json(data)
30
+
31
+ unless data[:data]
32
+ data = { data: data }
33
+ end
34
+
35
+ data.to_json
36
+ end
37
+
38
+ # === Correct json.
39
+ # Receives a json data and convert it to a symbolized object.
40
+ #
41
+ # ==== Parameters
42
+ # data:: (Hash) -- Data to be submitted.
43
+ #
44
+ def correct_json(data)
45
+ if data.is_a? String
46
+ data = JSON.parse(data)
47
+ end
48
+
49
+ data.symbolize_keys
50
+ end
51
+
52
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'redis'
4
+ require 'reverse_proxy/controller'
5
+ require 'reverse_proxy/client'
6
+
7
+ module ProxyControllersMethods
8
+ include ActionController::Cookies
9
+ include ReverseProxy::Controller
10
+
11
+ # === Index
12
+ # Is the base index method for all controllers, manage the headers depending
13
+ # on the controller type (Contact or User)
14
+ #
15
+ # ==== Parameters
16
+ # controller_type:: (String) -- Controller type that be called, this manages the headers to send (contact, user, pub).
17
+ # ==== Return
18
+ # Returns the response returned by send_cxf_request
19
+ #
20
+ def index(controller_type = nil)
21
+ host = @host.gsub('http://', '').gsub('https://', '')
22
+ host = host[0...-1] if host.end_with? '/'
23
+
24
+ headers = {
25
+ 'host' => host,
26
+ 'ApiKey' => @api_key.to_s,
27
+ 'Content-Type' => 'application/json',
28
+ 'Accept' => 'application/json',
29
+ 'SDK' => 'true',
30
+ }
31
+
32
+ if %w[contact user].include? controller_type
33
+ session_token = cookies["cxf_#{controller_type}_session_token".to_sym]
34
+ refresh_token = cookies["cxf_#{controller_type}_refresh_token".to_sym]
35
+ headers['Access-Token'] = session_token
36
+ headers['Refresh-Token'] = refresh_token
37
+ end
38
+
39
+ headers['ContactToken'] = cookies[:cxf_contact_id] if controller_type == 'contact' && cookies[:cxf_contact_id]
40
+
41
+ full_url = request.original_url
42
+ url_need_cache, time = url_need_cache?(full_url)
43
+
44
+ if @debug
45
+ puts "URL: #{full_url}"
46
+ puts "URL need cache: #{url_need_cache}"
47
+ puts "URL time cache: #{time}"
48
+ puts "Headers: #{headers}"
49
+ end
50
+
51
+ if url_need_cache
52
+ cached_response = @redis_server.get(full_url)
53
+
54
+ if cached_response
55
+ puts 'RESPONSE FROM CACHE' if @debug
56
+ return render json: cached_response
57
+ end
58
+
59
+ send_cxf_request(full_url, headers, controller_type, true, time: time)
60
+ else
61
+ send_cxf_request(full_url, headers, controller_type)
62
+ end
63
+ end
64
+
65
+ # === Url need cache?
66
+ # Method used to check if the given URL should be cached and for how long
67
+ #
68
+ # ==== Parameters
69
+ # full_url:: (String) -- URL to check if has cache.
70
+ # ==== Return
71
+ # Returns if the URL has cache and the time to be cached
72
+
73
+ def url_need_cache?(full_url)
74
+ url_need_cache = false
75
+ time = 0
76
+ methods_with_cache = %w[GET]
77
+
78
+ if methods_with_cache.include? request.method && @use_cache
79
+ @redis_config['groups'].each do |group|
80
+ group['urls'].each do |url|
81
+
82
+ if full_url.match url
83
+ time = group['time']
84
+ url_need_cache = true
85
+ break
86
+ end
87
+
88
+ end
89
+
90
+ break if url_need_cache
91
+ end
92
+ end
93
+
94
+ [url_need_cache, time]
95
+ end
96
+
97
+ # === Send cxf request
98
+ # Method used to make each request to Cxf, in addition to verifying and saving
99
+ # the response in cache for cases where it requires cache
100
+ #
101
+ # ==== Parameters
102
+ # full_url:: (String) -- URL to make the request.
103
+ # headers:: (Hash|Object) -- Headers to send in the request.
104
+ # cache_result:: (Boolean) -- This parameter controls whether the response will be cached..
105
+ # time:: (Integer) -- It is the time that the response will be stored in cache.
106
+ # ==== Return
107
+ # Returns the response given by Cxf or Redis
108
+
109
+ def send_cxf_request(full_url, headers, controller_type, cache_result = false, time: 30)
110
+ puts 'RESPONSE FROM MINTS.CLOUD' if @debug
111
+
112
+ reverse_proxy @host, headers: headers, verify_ssl: false do |config|
113
+
114
+ if cache_result
115
+ # Request succeeded!
116
+ config.on_response do |_status_code, response|
117
+ @redis_server.setex(
118
+ full_url,
119
+ time || 30,
120
+ response.body
121
+ )
122
+ end
123
+ end
124
+
125
+ # set Cookies from response headers
126
+ if %w[contact user].include? controller_type
127
+ config.on_response do |_status_code, response|
128
+ session_token_expires_at = Time.parse(response.header['Access-Token-Expires-At']) if response.header['Access-Token-Expires-At']
129
+ refresh_token_expires_at = Time.parse(response.header['Refresh-Token-Expires-At']) if response.header['Refresh-Token-Expires-At']
130
+
131
+ # add expires to cookies
132
+ cookies["cxf_#{controller_type}_session_token".to_sym] = { value: response.header['Access-Token'], secure: true, httponly: true, expires: Time.at(session_token_expires_at) } if response.header['Access-Token']
133
+ cookies["cxf_#{controller_type}_refresh_token".to_sym] = { value: response.header['Refresh-Token'], secure: true, httponly: true, expires: Time.at(refresh_token_expires_at) } if response.header['Refresh-Token']
134
+ end
135
+ end
136
+
137
+ # Request failed!
138
+ config.on_missing do |status_code, _response|
139
+ # We got a 404!
140
+ raise ActionController::RoutingError.new('Not Found') if status_code == 404
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,109 @@
1
+ require 'concurrent/executor/thread_pool_executor'
2
+
3
+ module ThreadsHelper
4
+
5
+ def make_multiple_request(calls)
6
+ set_threads_config
7
+ payload_to_return = []
8
+ now = Time.now
9
+ calls = [calls] if !calls.kind_of?(Array) || (calls.kind_of?(Array) && calls.first.kind_of?(String))
10
+
11
+ if @debug
12
+ puts "min_threads_per_pool: #{@min_threads_per_pool}"
13
+ puts "max_threads_per_pool: #{@max_threads_per_pool}"
14
+ puts "max_threads_queue: #{@max_threads_queue}"
15
+ end
16
+
17
+ pool = Concurrent::ThreadPoolExecutor.new(
18
+ min_threads: @min_threads_per_pool,
19
+ max_threads: @max_threads_per_pool,
20
+ max_queue: @max_threads_queue,
21
+ fallback_policy: :caller_runs
22
+ )
23
+
24
+ calls.each_with_index do |call_data, index|
25
+ pool.post do
26
+ begin
27
+ payload_to_return[index] = make_call(call_data)
28
+ rescue => e
29
+ payload_to_return[index] = e
30
+ end
31
+ end
32
+ end
33
+
34
+ # tell the pool to shutdown in an orderly fashion, allowing in progress work to complete
35
+ pool.shutdown
36
+ # now wait for all work to complete, wait as long as it takes
37
+ pool.wait_for_termination
38
+
39
+ if @debug
40
+ end_time = Time.now
41
+ puts "Time to make all calls: #{end_time - now}"
42
+ end
43
+
44
+ payload_to_return
45
+ end
46
+
47
+ private
48
+
49
+ def set_threads_config
50
+ if File.exists?("#{Rails.root}/cxf_config.yml.erb")
51
+ template = ERB.new File.new("#{Rails.root}/cxf_config.yml.erb").read
52
+ config = YAML.safe_load template.result(binding)
53
+ cxf_config = get_cxf_config(config)
54
+ @debug = !!config['sdk']['debug']
55
+
56
+ # All threads config
57
+ @min_threads_per_pool = cxf_config['min_threads_per_pool'] || 2
58
+ @max_threads_per_pool = cxf_config['max_threads_per_pool'] || 2
59
+ @max_threads_queue = cxf_config['max_threads_queue'] || 10
60
+ end
61
+ end
62
+
63
+ def get_cxf_config(config)
64
+ config['cxf'].kind_of?(Hash) ? config['cxf'] : {}
65
+ end
66
+
67
+ def make_call(call_data)
68
+ action, *all_options = generate_raw_data(call_data)
69
+
70
+ if if_is_raw_action(action)
71
+ self.client.raw(action, *all_options)
72
+ else
73
+ self.send(action, *all_options.compact)
74
+ end
75
+ end
76
+
77
+ def if_is_raw_action(action)
78
+ http_actions = %w[get create post update put patch delete destroy]
79
+ http_actions.include?(action.downcase)
80
+ end
81
+
82
+ def generate_raw_data(payload)
83
+ action = raw_attribute_data(payload, 'action')
84
+ url = raw_attribute_data(payload, 'url', 1)
85
+ options = raw_attribute_data(payload, 'options', 2)
86
+ data = raw_attribute_data(payload, 'data', 3)
87
+ base_url = raw_attribute_data(payload, 'base_url', 4)
88
+ compatibility_options = raw_attribute_data(payload, 'compatibility_options', 5)
89
+ only_tracking = raw_attribute_data(payload, 'only_tracking', 6)
90
+
91
+ [action, url, options, data, base_url, compatibility_options, only_tracking]
92
+ end
93
+
94
+ def raw_attribute_data(payload, attribute, array_index = 0)
95
+ attribute_data = nil
96
+
97
+ if payload.kind_of? Array
98
+ attribute_data = payload[array_index]
99
+ elsif payload.kind_of? Hash
100
+ if payload.key? attribute
101
+ attribute_data = payload[attribute]
102
+ elsif payload.key? attribute.to_sym
103
+ attribute_data = payload[attribute.to_sym]
104
+ end
105
+ end
106
+
107
+ attribute_data
108
+ end
109
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UserAuthHelper
4
+ def cxf_user_signed_in?
5
+ begin
6
+ # Check status in cxf
7
+ response = @cxf_user.me['data']
8
+ rescue => e
9
+ # Handle the client Unauthorized error
10
+ # if cxf response is negative delete the session cookie
11
+ cookies.delete(:cxf_user_session_token)
12
+ cookies.delete(:cxf_user_refresh_token)
13
+ response = nil
14
+ end
15
+
16
+ response
17
+ end
18
+
19
+ ##
20
+ # === Cxf user Login.
21
+ # Starts a user session in cxf.cloud and set a session cookie
22
+ def cxf_user_login(email, password)
23
+ # Login in cxf
24
+ response = @cxf_user.login(email, password)
25
+ # Get session token from response
26
+ if response.key? 'data'
27
+ session_token = response['data']['access_token']
28
+ refresh_token = response['data']['refresh_token']
29
+ session_token_expires_at = Time.parse(response['data']['access_token_expires_at'])
30
+ refresh_token_expires_at = Time.parse(response['data']['refresh_token_expires_at'])
31
+ end
32
+
33
+ # Set a permanent cookie with the session token
34
+ cookies[:cxf_user_session_token] = { value: session_token, secure: true, httponly: true, expires: Time.at(session_token_expires_at) }
35
+ cookies[:cxf_user_refresh_token] = { value: refresh_token, secure: true, httponly: true, expires: Time.at(refresh_token_expires_at) }
36
+ end
37
+
38
+ ##
39
+ # === Cxf user Login.
40
+ # Starts a user session in cxf.cloud and set a session cookie
41
+ def cxf_user_magic_link_login(hash)
42
+ # Login in cxf
43
+ response = @cxf_user.magic_link_login(hash)
44
+ if response['data']
45
+ # Set a cookie with the session token
46
+ cookies[:cxf_user_session_token] = { value: response['data']['access_token'], secure: true, httponly: true }
47
+ cookies[:cxf_user_refresh_token] = { value: response['data']['refresh_token'], secure: true, httponly: true }
48
+ redirect_to response['data']['redirect_url'] || '/'
49
+ else
50
+ redirect_to '/'
51
+ end
52
+ end
53
+
54
+ ##
55
+ # === Cxf user Logout.
56
+ # Destroy session from cxf.cloud and delete local session cookie
57
+ def cxf_user_logout
58
+ # Logout from cxf
59
+ # @cxf_user.logout
60
+ # Delete local cookie
61
+ cookies.delete(:cxf_user_session_token)
62
+ cookies.delete(:cxf_user_refresh_token)
63
+ end
64
+
65
+ def update_user_tokens
66
+ access_token = @cxf_user.get_client.session_token
67
+ refresh_token = @cxf_user.get_client.refresh_token
68
+ access_token_expires_at = @cxf_user.get_client.session_token_expires_at
69
+ refresh_token_expires_at = @cxf_user.get_client.refresh_token_expires_at
70
+
71
+ cookies[:cxf_user_session_token] = { value: access_token, secure: true, httponly: true, expires: Time.at(access_token_expires_at) } if access_token && access_token_expires_at
72
+ cookies[:cxf_user_refresh_token] = { value: refresh_token, secure: true, httponly: true, expires: Time.at(refresh_token_expires_at) } if refresh_token && refresh_token_expires_at
73
+ end
74
+ end
data/lib/cxf.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './pub'
4
+ require_relative './contact'
5
+ require_relative './user'
6
+ require_relative './cxf/controllers/base_controller'
7
+ require_relative './cxf/controllers/base_api_controller'
8
+ require_relative './cxf/controllers/admin_base_controller'
9
+ require_relative './cxf/controllers/public_api_controller'
10
+ require_relative './cxf/controllers/contact_api_controller'
11
+ require_relative './cxf/controllers/user_api_controller'
12
+ require_relative './errors'
13
+
14
+ module Cxf
15
+ end
data/lib/errors.rb ADDED
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cxf
4
+
5
+ module Errors
6
+
7
+ class NonSupportedRubyVersionError < RuntimeError; end
8
+
9
+ class DynamicError < RuntimeError
10
+ ERRORS = {
11
+ '401' => 'AccessDeniedException',
12
+ '404' => 'ResourceNotFoundException',
13
+ '422' => 'ValidationException',
14
+ '405' => 'MethodNotAllowedException',
15
+ 'undefined_id' => 'UndefinedIdException',
16
+ 'default' => 'InternalServerException',
17
+ }
18
+
19
+ def initialize(client, title, detail, http_status, response)
20
+ @http_status = http_status
21
+ @error = error_class.constantize&.new(client, title, detail, http_status, response)
22
+ end
23
+
24
+ attr_reader :error, :http_status
25
+
26
+ def to_s
27
+ error_class
28
+ end
29
+
30
+ private
31
+
32
+ def error_class
33
+ "Cxf::Errors::#{ERRORS[http_status.to_s] || ERRORS['default']}"
34
+ end
35
+ end
36
+
37
+ class ServiceError < RuntimeError
38
+ # @param [Client] client
39
+ # @param [String] title
40
+ # @param [String] detail
41
+ # @param [Integer] http_status
42
+ # @param [String Object Array] response
43
+ def initialize(client, title, detail, http_status, response)
44
+ @title = title
45
+ @client = client
46
+ @response = response
47
+ @http_status = http_status
48
+ @detail = detail && !detail.empty? ? detail : self.class.to_s
49
+
50
+ super(@detail)
51
+ end
52
+
53
+ # @return [String]
54
+ def detail
55
+ @detail
56
+ end
57
+
58
+ def to_h(extra_fields = {})
59
+ default_fields = {
60
+ client: client,
61
+ title: title,
62
+ detail: detail,
63
+ http_status: http_status,
64
+ response: response
65
+ }
66
+
67
+ default_fields.merge(extra_fields)
68
+ end
69
+
70
+ def to_s
71
+ to_h.to_s
72
+ end
73
+
74
+ attr_reader :client, :detail, :title, :http_status, :response
75
+ end
76
+
77
+ class AccessDeniedException < ServiceError; end
78
+
79
+ class ResourceNotFoundException < ServiceError; end
80
+
81
+ class MethodNotAllowedException < ServiceError; end
82
+
83
+ class UndefinedIdException < ServiceError; end
84
+
85
+ class ValidationException < ServiceError
86
+
87
+ def to_h
88
+ super(errors_hash)
89
+ end
90
+
91
+ def errors_hash
92
+ {
93
+ errors: if response.is_a? Hash
94
+ response.keys.reduce([]) do |carry, error_key|
95
+ carry + (response[error_key].is_a?(Array) ? response[error_key] : [response[error_key]] )
96
+ end
97
+ else
98
+ response
99
+ end
100
+ }
101
+ end
102
+
103
+ attr_reader :failed_validations
104
+ end
105
+
106
+ class InternalServerException < ServiceError; end
107
+
108
+ end
109
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'reverse_proxy/client'
4
+ require 'cxf'
5
+
6
+ class CxfAssetsController < Cxf::PublicAPIController
7
+ end
@@ -0,0 +1,27 @@
1
+ # Cxf connection configuration
2
+ cxf:
3
+ host: http://your_host_goes_here.com
4
+ api_key: your_cxf_api_key_goes_here
5
+ cxf_slug: slug_id #save id and token in redis
6
+ redis_cache:
7
+ use_cache: boolean_value_to_enable_and_disable_cache
8
+ redis_host: your_redis_server_host
9
+ redis_port: your_redis_server_port
10
+ redis_db: your_redis_database
11
+ groups:
12
+ - urls:
13
+ - group_of_urls
14
+ time: time_that_will_be_applied_to_urls_in_seconds
15
+ sdk:
16
+ debug: false
17
+ # Timeout is specified in seconds
18
+ default_http_timeout: 30 # Allows setting a default timeout for all HTTP calls.
19
+ get_http_timeout: 30 # Allows setting a default timeout for all GET calls.
20
+ post_http_timeout: 30 # Allows setting a default timeout for all POST calls.
21
+ put_http_timeout: 30 # Allows setting a default timeout for all PUT calls.
22
+ delete_http_timeout: 30 # Allows setting a default timeout for all DELETE calls.
23
+ cookies_iframe:
24
+ activated: boolean_value_to_enable_and_disable_cookies_iframe
25
+ expire_time: expire_time_of_cookies_iframe_in_hours
26
+ hosts:
27
+ - array_of_host_to_send_cookies
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'reverse_proxy/client'
4
+ require 'cxf'
5
+
6
+ class Api::V1::CxfContactController < Cxf::ContactAPIController
7
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CxfFilesGenerator < Rails::Generators::Base
4
+ source_root(File.expand_path(File.dirname(__FILE__)))
5
+ include Rails::Generators::Actions
6
+
7
+ def create_cxf_files
8
+ copy_file 'cxf_config.yml.erb', 'cxf_config.yml.erb'
9
+ copy_file 'cxf_user_controller.rb', './app/controllers/api/cxf_user_controller.rb'
10
+ copy_file 'cxf_contact_controller.rb', './app/controllers/api/v1/cxf_contact_controller.rb'
11
+ copy_file 'cxf_public_controller.rb', './app/controllers/api/v1/cxf_public_controller.rb'
12
+ copy_file 'cxf_assets_controller.rb', './app/controllers/cxf_assets_controller.rb'
13
+
14
+ route <<-eos
15
+ # Cxf auto-generated routes (proxy to send request to cxf.cloud)
16
+ match '/public-assets/*path' => 'cxf_assets#index', via: [:get, :post, :put, :patch, :delete]
17
+ namespace :api, defaults: { format: :json } do
18
+ match '/v1/*path' => 'cxf_user#index', via: [:get, :post, :put, :patch, :delete]
19
+ match '/user/v1/*path' => 'cxf_user#index', via: [:get, :post, :put, :patch, :delete]
20
+ match '/contact/v1/*path' => 'cxf_contact#index', via: [:get, :post, :put, :patch, :delete]
21
+ namespace :v1 do
22
+ match '/contacts/*path' => 'cxf_contact#index', via: [:get, :post, :put, :patch, :delete]
23
+ match '/*path' => 'cxf_public#index', via: [:get, :post, :put, :patch, :delete]
24
+ end
25
+ end
26
+ eos
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'reverse_proxy/client'
4
+ require 'cxf'
5
+
6
+ class Api::V1::CxfPublicController < Cxf::PublicAPIController
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'reverse_proxy/client'
4
+ require 'cxf'
5
+
6
+ class Api::CxfUserController < Cxf::UserAPIController
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ ### V1/CONFIG ###
4
+
5
+ module PublicConfig
6
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PublicAssets
4
+ ##
5
+ # === Get Asset Info.
6
+ # Get a description of an Asset.
7
+ #
8
+ # ==== Parameters
9
+ # slug:: (String) -- It's the string identifier of the asset.
10
+ #
11
+ # ==== Example
12
+ # @data = @cxf_pub.get_asset_info("asset_slug")
13
+ def get_asset_info(slug)
14
+ @client.raw('get', "/content/asset-info/#{slug}")
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ ### V1/CONTENT ###
4
+
5
+ require_relative './assets'
6
+
7
+ module PublicContent
8
+ include PublicAssets
9
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ ### V1/ECOMMERCE ###
4
+
5
+ module PublicEcommerce
6
+ end