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.
124 125 126 |
# File 'lib/pub.rb', line 124 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
322 323 324 |
# File 'lib/pub.rb', line 322 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
259 260 261 |
# File 'lib/pub.rb', line 259 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
270 271 272 |
# File 'lib/pub.rb', line 270 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
197 198 199 |
# File 'lib/pub.rb', line 197 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
Parameters
-
options
- [Hash] List of Resource collection Options shown above can be used as parameter
186 187 188 |
# File 'lib/pub.rb', line 186 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
218 219 220 |
# File 'lib/pub.rb', line 218 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
207 208 209 |
# File 'lib/pub.rb', line 207 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
166 167 168 |
# File 'lib/pub.rb', line 166 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
155 156 157 |
# File 'lib/pub.rb', line 155 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
228 229 230 |
# File 'lib/pub.rb', line 228 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
249 250 251 |
# File 'lib/pub.rb', line 249 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
238 239 240 |
# File 'lib/pub.rb', line 238 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
134 135 136 |
# File 'lib/pub.rb', line 134 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
145 146 147 |
# File 'lib/pub.rb', line 145 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
291 292 293 |
# File 'lib/pub.rb', line 291 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
280 281 282 |
# File 'lib/pub.rb', line 280 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
301 302 303 |
# File 'lib/pub.rb', line 301 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
312 313 314 |
# File 'lib/pub.rb', line 312 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
97 98 99 100 101 102 103 104 105 |
# File 'lib/pub.rb', line 97 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
114 115 116 |
# File 'lib/pub.rb', line 114 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
176 177 178 |
# File 'lib/pub.rb', line 176 def submit_form(data) return @client.raw("post", "/content/forms/submit", nil, data) end |