Class: Mints::Pub
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 }
-
categories
- [Boolean] If present, categories will be returned for each record in the results. Example:{ "categories": 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": "searchstring" }
-
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 }
-
catfilters
- [String] filter by categories. Example:{ "catfilters": "categoryName" }
-
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" }
-
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" }
-
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 }
-
categories
- [Boolean] If present, categories will be returned for each record in the results. Example:{ "categories": 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 }
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#get_asset_info(slug) ⇒ Object
Get Asset Info.
-
#get_attributes(options = nil) ⇒ Object
Get Attributes.
-
#get_categories(options = nil) ⇒ Object
Get categories.
-
#get_category(slug, options = nil) ⇒ Object
Get Category.
-
#get_content_instance(slug, options = nil) ⇒ Object
Get Content Instance.
-
#get_content_instances(options = nil) ⇒ Object
Get Content Instances.
-
#get_content_page(slug, options = nil) ⇒ Object
Get Content Page.
-
#get_content_pages(options = nil) ⇒ Object
Get Content Pages.
-
#get_form(slug, options = nil) ⇒ Object
Get Form.
-
#get_forms(options = nil) ⇒ Object
Get Forms.
-
#get_locations(options = nil) ⇒ Object
Get Locations.
-
#get_product(slug, options = nil) ⇒ Object
Get Product.
-
#get_products(options = nil) ⇒ Object
Get Products.
-
#get_stories(options = nil) ⇒ Object
Get Stories.
-
#get_story(slug, options = nil) ⇒ Object
Get Story.
-
#get_tag(slug, options = nil) ⇒ Object
Get Tag.
-
#get_tags(options = nil) ⇒ Object
Get Tags.
-
#get_taxonomies(options = nil) ⇒ Object
Get Taxonomies.
-
#get_taxonomy(slug, options = nil) ⇒ Object
Get Taxonomy.
-
#initialize(host, api_key, contact_token_id = nil, debug = false) ⇒ 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.
-
#submit_form(data) ⇒ Object
Submit Form.
Methods included from MintsHelper
#correct_json, #data_transform, #get_query_results
Constructor Details
#initialize(host, api_key, contact_token_id = nil, debug = false) ⇒ 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.
86 87 88 |
# File 'lib/pub.rb', line 86 def initialize(host, api_key, contact_token_id = nil, debug = false) @client = Mints::Client.new(host, api_key, 'public', nil, contact_token_id, debug) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
74 75 76 |
# File 'lib/pub.rb', line 74 def client @client end |
Instance Method Details
#get_asset_info(slug) ⇒ Object
Get Asset Info.
Get a description of an Asset.
Parameters
- slug
-
(String) – It’s the string identifier of the asset.
Example
@mints_pub.get_asset_info("asset_slug")
140 141 142 |
# File 'lib/pub.rb', line 140 def get_asset_info(slug) return @client.raw("get", "/content/asset-info/#{slug}") end |
#get_attributes(options = nil) ⇒ Object
Get Attributes.
Get a collection of attributes.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
Example
@mints_pub.get_attributes
403 404 405 |
# File 'lib/pub.rb', line 403 def get_attributes( = nil) return @client.raw("get", "/config/attributes", ) end |
#get_categories(options = nil) ⇒ Object
Get categories.
Get a collection of categories.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
Example
= {
"object_type": "stories"
}
@mints_pub.get_categories()
319 320 321 |
# File 'lib/pub.rb', line 319 def get_categories( = nil) return @client.raw("get", "/config/categories", ) end |
#get_category(slug, options = nil) ⇒ Object
Get Category.
Get a single category.
Parameters
- slug
-
(String) – It’s the string identifier generated by Mints.
- options
-
(Hash) – List of Single Resource Options shown above can be used as parameter.
Example
= {
"object_type": "locations"
}
@mints_pub.get_category("asset_slug", )
336 337 338 |
# File 'lib/pub.rb', line 336 def get_category(slug, = nil) return @client.raw("get", "/config/categories/#{slug}", ) end |
#get_content_instance(slug, options = nil) ⇒ Object
Get Content Instance.
Get a single content instance.
Parameters
- slug
-
(String) – It’s the string identifier generated by Mints.
- options
-
(Hash) – List of Single Resource Options shown above can be used as parameter.
Example
@mints_pub.get_content_instance("content_instance_slug")
239 240 241 |
# File 'lib/pub.rb', line 239 def get_content_instance(slug, = nil) return @client.raw("get", "/content/content-instances/#{slug}", ) end |
#get_content_instances(options = nil) ⇒ Object
Get Content Instances.
Get a collection of content instances. Note: Options must be specified.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
225 226 227 |
# File 'lib/pub.rb', line 225 def get_content_instances( = nil) return @client.raw("get", "/content/content-instances", ) end |
#get_content_page(slug, options = nil) ⇒ Object
Get Content Page.
Get a single content page.
Parameters
- slug
-
(String) – It’s the string identifier generated by Mints.
- options
-
(Hash) – List of Single Resource Options shown above can be used as parameter.
Example
@mints_pub.get_content_page("test-page")
263 264 265 |
# File 'lib/pub.rb', line 263 def get_content_page(slug, = nil) return @client.raw("get", "/content/content-pages/#{slug}", ) end |
#get_content_pages(options = nil) ⇒ Object
Get Content Pages.
Get all content pages.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
249 250 251 |
# File 'lib/pub.rb', line 249 def get_content_pages( = nil) return @client.raw("get", "/content/content-pages", ) end |
#get_form(slug, options = nil) ⇒ Object
Get Form.
Get a single form.
Parameters
- slug
-
(String) – It’s the string identifier generated by Mints.
- options
-
(Hash) – List of Single Resource Options shown above can be used as parameter.
Example
@mints_pub.get_form("form_slug")
194 195 196 |
# File 'lib/pub.rb', line 194 def get_form(slug, = nil) return @client.raw("get", "/content/forms/#{slug}", ) end |
#get_forms(options = nil) ⇒ Object
Get Forms.
Get a collection of forms.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
Example
@mints_pub.get_forms
180 181 182 |
# File 'lib/pub.rb', line 180 def get_forms( = nil) return @client.raw("get", "/content/forms", ) end |
#get_locations(options = nil) ⇒ Object
Get Locations.
Get all locations.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
Example
@mints_pub.get_locations
276 277 278 |
# File 'lib/pub.rb', line 276 def get_locations( = nil) return @client.raw("get", "/ecommerce/locations", ) end |
#get_product(slug, options = nil) ⇒ Object
Get Product.
Get a single product.
Parameters
- slug
-
(String) – It’s the string identifier generated by Mints.
- options
-
(Hash) – List of Single Resource Options shown above can be used as parameter.
Example
@mints_pub.get_product("product_slug")
303 304 305 |
# File 'lib/pub.rb', line 303 def get_product(slug, = nil) return @client.raw("get", "/ecommerce/products/#{slug}", ) end |
#get_products(options = nil) ⇒ Object
Get Products.
Get a collection of products.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
Example
@mints_pub.get_products
289 290 291 |
# File 'lib/pub.rb', line 289 def get_products( = nil) return @client.raw("get", "/ecommerce/products", ) end |
#get_stories(options = nil) ⇒ Object
Get Stories.
Get a collection of stories.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
Example
@mints_pub.get_stories
153 154 155 |
# File 'lib/pub.rb', line 153 def get_stories( = nil) return @client.raw("get", "/content/stories", ) end |
#get_story(slug, options = nil) ⇒ Object
Get Story.
Get a single story.
Parameters
- slug
-
(String) – It’s the string identifier generated by Mints.
- options
-
(Hash) – List of Single Resource Options shown above can be used as parameter.
Example
@mints_pub.get_story("story_slug")
167 168 169 |
# File 'lib/pub.rb', line 167 def get_story(slug, = nil) return @client.raw("get", "/content/stories/#{slug}", ) end |
#get_tag(slug, options = nil) ⇒ Object
Get Tag.
Get a single tag.
Parameters
- slug
-
(String) – It’s the string identifier generated by Mints.
- options
-
(Hash) – List of Single Resource Options shown above can be used as parameter.
Example
@mints_pub.get_tag("tag_slug")
363 364 365 |
# File 'lib/pub.rb', line 363 def get_tag(slug, = nil) return @client.raw("get", "/config/tags/#{slug}", ) end |
#get_tags(options = nil) ⇒ Object
Get Tags.
Get a collection of tags.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
Example
@mints_pub.
349 350 351 |
# File 'lib/pub.rb', line 349 def ( = nil) return @client.raw("get", "/config/tags", ) end |
#get_taxonomies(options = nil) ⇒ Object
Get Taxonomies.
Get a collection of taxonomies.
Parameters
- options
-
(Hash) – List of Resource collection Options shown above can be used as parameter.
Example
@mints_pub.get_taxonomies
376 377 378 |
# File 'lib/pub.rb', line 376 def get_taxonomies( = nil) return @client.raw("get", "/config/taxonomies", ) end |
#get_taxonomy(slug, options = nil) ⇒ Object
Get Taxonomy.
Get a single taxonomy.
Parameters
- slug
-
(String) – It’s the string identifier generated by Mints.
- options
-
(Hash) – List of Single Resource Options shown above can be used as parameter.
Example
@mints_pub.get_taxonomy("taxonomy_slug")
390 391 392 |
# File 'lib/pub.rb', line 390 def get_taxonomy(slug, = nil) return @client.raw("get", "/config/taxonomies/#{slug}", ) end |
#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"
}
@mints_pub.register_visit(request, request["remote_ip"], request["user_agent"], request["fullpath"])
107 108 109 110 111 112 113 114 115 |
# File 'lib/pub.rb', line 107 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 } response = @client.raw("post", "/register-visit", nil, data.to_json) return response 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
@mints_pub.register_visit_timer("60da2325d29acc7e55684472", 4)
127 128 129 |
# File 'lib/pub.rb', line 127 def register_visit_timer(visit, time) return @client.raw("get", "/register-visit-timer?visit=#{visit}&time=#{time}") end |
#submit_form(data) ⇒ Object
Submit Form.
Submit a form with data.
Parameters
- data
-
(Hash) – Data to be submited.
Example
data = {
'form_slug': 'form_slug',
'email': 'email@example.com',
'given_name': 'given_name',
'f1': 'Field 1 answer',
'f2': 'Field 2 answer',
'f3': 'Field 3 answer'
}
@data = @mints_pub.submit_form(data)
215 216 217 |
# File 'lib/pub.rb', line 215 def submit_form(data) return @client.raw("post", "/content/forms/submit", nil, data_transform(data)) end |