Class: Mints::Pub
- Inherits:
-
Object
- Object
- Mints::Pub
- 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 } -
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.
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- [String] Cookie ‘mints_contact_id’ value (mints_contact_token)
Return
Returns a Client object
84 85 86 |
# File 'lib/pub.rb', line 84 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.
72 73 74 |
# File 'lib/pub.rb', line 72 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("quaerat")
141 142 143 |
# File 'lib/pub.rb', line 141 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
419 420 421 |
# File 'lib/pub.rb', line 419 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()
329 330 331 |
# File 'lib/pub.rb', line 329 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("atm", )
347 348 349 |
# File 'lib/pub.rb', line 347 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("bill-gates")
245 246 247 |
# File 'lib/pub.rb', line 245 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
230 231 232 |
# File 'lib/pub.rb', line 230 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 slug -
options- [Hash] List of Single Resource Options shown above can be used as parameter
Example
@mints_pub.get_content_page("test-page")
270 271 272 |
# File 'lib/pub.rb', line 270 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
255 256 257 |
# File 'lib/pub.rb', line 255 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("survey")
199 200 201 |
# File 'lib/pub.rb', line 199 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
184 185 186 |
# File 'lib/pub.rb', line 184 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
284 285 286 |
# File 'lib/pub.rb', line 284 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("batman-shirt")
313 314 315 |
# File 'lib/pub.rb', line 313 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
298 299 300 |
# File 'lib/pub.rb', line 298 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
155 156 157 |
# File 'lib/pub.rb', line 155 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("getting-ready-for-e3")
170 171 172 |
# File 'lib/pub.rb', line 170 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("ad-0")
376 377 378 |
# File 'lib/pub.rb', line 376 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.
361 362 363 |
# File 'lib/pub.rb', line 361 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
390 391 392 |
# File 'lib/pub.rb', line 390 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("unit_pricing_measure")
405 406 407 |
# File 'lib/pub.rb', line 405 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- The visitor’s browser user agent -
url- [String] URL visited
Example
request = {
"remote_ip" => "http://864.401.156.12/",
"user_agent" => "User Agent",
"fullpath" => "https://mints.cloud/blog"
}
@mints_pub.register_visit(request, request["remote_ip"], request["user_agent"], request["fullpath"])
106 107 108 109 110 111 112 113 114 |
# File 'lib/pub.rb', line 106 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.
Parameters
-
data- [Hash] Data to be submited
Example
data_form = {
"data": {
'form_slug': 'formulario',
'email': '[email protected]',
'ingrese-un-texto': 'hola'
}
}
@mints_pub.submit_form(data_form.to_json)
220 221 222 |
# File 'lib/pub.rb', line 220 def submit_form(data) return @client.raw("post", "/content/forms/submit", nil, data) end |