Class: Cxf::Pub
- Inherits:
-
Object
- Object
- Cxf::Pub
- Includes:
- CxfHelper, 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 Cxf::BaseController inheritance:
If the controller is inheriting from Cxf::BaseController, Only use the class variable cxf_pub Example:
@cxf_pub.get_stories
For standalone usage:
Initialize
pub = Cxf::Pub.new(cxf_url, api_key)
or if host and api_key are provided by cxf_config.yml.erb
pub = Cxf::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
- #get_client ⇒ Object
-
#initialize(host, api_key, contact_token_id = nil, visit_id = nil, debug = false, user_agent = nil, 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 PrintVersions
#create_print_version, #create_print_version_from_print_version, #delete_print_version, #duplicate_print_version, #get_print_version, #get_print_versions, #publish_print_version, #update_print_version
Methods included from ContentPrints
#create_content_print, #delete_content_print, #get_content_print, #get_content_prints, #update_content_print
Methods included from PublicAssets
Methods included from CxfHelper
#correct_json, #data_transform, #get_query_results
Constructor Details
#initialize(host, api_key, contact_token_id = nil, visit_id = nil, debug = false, user_agent = nil, timeouts = {}) ⇒ Pub
Initialize.
Class constructor.
Parameters
- host
-
(String) – It’s the visitor IP.
- api_key
-
(String) – Cxf instance api key.
- contact_token_id
-
(Integer) – Cookie ‘cxf_contact_id’ value (cxf_contact_token).
Return
Returns a Client object.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/pub.rb', line 84 def initialize( host, api_key, contact_token_id = nil, visit_id = nil, debug = false, user_agent = nil, timeouts = {} ) @client = Cxf::Client.new( host, api_key, 'public', nil, nil, contact_token_id, visit_id, debug, timeouts ) @client.user_agent = user_agent 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
#get_client ⇒ Object
163 164 165 |
# File 'lib/pub.rb', line 163 def get_client @client end |
#register_visit(request, ip = nil, user_agent = nil, url = nil) ⇒ Object
Register Visit.
Register a ghost/contact visit in Cxf.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 = @cxf_pub.register_visit(request, request["remote_ip"], request["user_agent"], request["fullpath"])
125 126 127 128 129 130 131 132 133 |
# File 'lib/pub.rb', line 125 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 = @cxf_pub.register_visit_timer("60da2325d29acc7e55684472", 4)
145 146 147 |
# File 'lib/pub.rb', line 145 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
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/pub.rb', line 149 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 |