Class: Mints::Pub
- Inherits:
-
Object
- Object
- Mints::Pub
- Includes:
- MintsHelper, PublicConfig, PublicContent, PublicEcommerce, ThreadsHelper
- Defined in:
- lib/pub.rb
Overview
Public context API
Pub class contains functions that needs only an API key as authentication
Usage example
For Mints::BaseController inheritance:
If the controller is inheriting from Mints::BaseController, Only use the class variable mints_pub Example:
@mints_pub.get_stories
For standalone usage:
Initialize
pub = Mints::Pub.new(mints_url, api_key)
or if host and api_key are provided by mints_config.yml.erb
pub = Mints::Pub.new
Call any function
pub.get_products
Single resource options
-
include
- [String] Specify additional information to be included in the results from the objects relations. Example:{ "include": "events" }
-
attributes
- [Boolean] If present, attributes will be returned for each record in the results. Example:{ "attributes": true }
-
taxonomies
- [Boolean] If present, taxonomies will be returned for each record in the results. Example:{ "taxonomies": true }
-
tags
- [Boolean] If present, tags will be returned for each record in the results. Example:{ "tags": true }
-
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:{ fields: "id, title, slug" } { "fields[products]": "id, title, slug" }
Resource collections options
-
search
- [String] If present, it will search for records matching the search string. Example:{ "search": "search string" }
-
scopes
- [String] If present, it will apply the specified Model’s scopes. Example:{ "scopes": "approved, recent" }
-
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:{ "filters[title]": "titleToFilter" }
-
jfilters
- [String] A complex filter configuration, as used in segments, in JSON format, base64 encoded and URLencoded. Example:jfilter = { "type":"group", "items":[ { "type":"attribute", "operator":"==", slug:"title", "value":"Action movies" } ], "operator":"or" } = { "jfilters": jfilter }
-
sort
- [String] The name of the field to perform the sort. Prefix the value with a minus sign - for ascending order. Example:{ sort: "title" } { sort: "-title" }
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(host, api_key, contact_token_id = nil, visit_id = nil, debug = false, timeouts = {}) ⇒ Pub
constructor
Initialize.
-
#register_visit(request, ip = nil, user_agent = nil, url = nil) ⇒ Object
Register Visit.
-
#register_visit_timer(visit, time) ⇒ Object
Register Visit timer.
- #send_user_magic_link(email_or_phone, template_slug, redirect_url = '', life_time = 1440, max_visits = nil, driver = 'email') ⇒ Object
Methods included from ThreadsHelper
Methods included from PublicTaxonomies
#get_taxonomies, #get_taxonomy
Methods included from PublicTags
Methods included from PublicFolders
#get_public_folder, #get_public_folders
Methods included from PublicAttributes
Methods included from PublicOrders
#add_item_to_shopping_cart, #get_my_shopping_cart
Methods included from PublicProductVersions
#get_product_version, #get_product_versions
Methods included from PublicLocations
Methods included from PublicStoryVersions
#get_story_version, #get_story_versions
Methods included from PublicStories
Methods included from PublicForms
#get_form, #get_forms, #submit_form
Methods included from PublicContentInstances
#get_content_instance, #get_content_instances
Methods included from PublicContentInstanceVersions
#get_content_instance_version, #get_content_instance_versions
Methods included from PublicContentBundles
#get_content_bundle, #get_content_bundles, #get_content_page
Methods included from PublicAssets
Methods included from MintsHelper
#correct_json, #data_transform, #get_query_results
Constructor Details
#initialize(host, api_key, contact_token_id = nil, visit_id = nil, debug = false, timeouts = {}) ⇒ Pub
Initialize.
Class constructor.
Parameters
- host
-
(String) – It’s the visitor IP.
- api_key
-
(String) – Mints instance api key.
- contact_token_id
-
(Integer) – Cookie ‘mints_contact_id’ value (mints_contact_token).
Return
Returns a Client object.
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pub.rb', line 84 def initialize(host, api_key, contact_token_id = nil, visit_id = nil, debug = false, timeouts = {}) @client = Mints::Client.new( host, api_key, 'public', nil, contact_token_id, visit_id, debug, timeouts ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
65 66 67 |
# File 'lib/pub.rb', line 65 def client @client end |
Instance Method Details
#register_visit(request, ip = nil, user_agent = nil, url = nil) ⇒ Object
Register Visit.
Register a ghost/contact visit in Mints.Cloud.
Parameters
- request
-
(ActionDispatch::Request) – request.
- ip
-
(String) – It’s the visitor IP.
- user_agent
-
(String) – The visitor’s browser user agent.
- url
-
(String) – URL visited.
Example
request = {
"remote_ip" => "http://1.1.1.1/",
"user_agent" => "User Agent",
"fullpath" => "https://fullpath/example"
}
@data = @mints_pub.register_visit(request, request["remote_ip"], request["user_agent"], request["fullpath"])
114 115 116 117 118 119 120 121 122 |
# File 'lib/pub.rb', line 114 def register_visit(request, ip = nil, user_agent = nil, url = nil) data = { ip_address: ip || request.remote_ip, user_agent: user_agent || request.user_agent, url: url || request.fullpath } @client.raw('post', '/register-visit', nil, data.to_json) end |
#register_visit_timer(visit, time) ⇒ Object
Register Visit timer.
Register a page visit time.
Parameters
- visit
-
(String) – It’s the visitor IP.
- time
-
(Integer) – The visitor’s browser user agent.
Example
@data = @mints_pub.register_visit_timer("60da2325d29acc7e55684472", 4)
134 135 136 |
# File 'lib/pub.rb', line 134 def register_visit_timer(visit, time) @client.raw('get', "/register-visit-timer?visit=#{visit}&time=#{time}") end |
#send_user_magic_link(email_or_phone, template_slug, redirect_url = '', life_time = 1440, max_visits = nil, driver = 'email') ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/pub.rb', line 138 def send_user_magic_link(email_or_phone, template_slug, redirect_url = '', life_time = 1440, max_visits = nil, driver = 'email') data = { driver: driver, lifeTime: life_time, maxVisits: max_visits, redirectUrl: redirect_url, templateId: template_slug } key = %w[sms whatsapp].include? driver ? 'phone' : 'email' data[key] = email_or_phone @client.raw('post', '/users/magic-link', nil, { data: data }.to_json, '/api/v1') end |