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
Initialize
pub = Mints::Pub.new(mints_url, api_key)
or if host and api_key are provided by mints_config.yml
pub = Mints::Pub.new
Call any function
pub.get_products
Single resource options
-
include
- [String] include a relationship -
attributes
- [Boolean] attach attributes to response -
categories
- [Boolean] attach categories to response -
tags
- [Boolean] attach tags to response
Resource collections options
-
search
- [String] filter by a search word -
scopes
- [String] filter by a scope -
filters
- [String] filter by where clauses -
jfilters
- [String] filter using complex condition objects -
catfilters
- [String] filter by categories -
fields
- [String] indicates the columns that will be selected -
sort
- [String] indicates the columns that will be selected -
include
- [String] include a relationship -
attributes
- [Boolean] attach attributes to response -
categories
- [Boolean] attach categories to response -
taxonomies
- [Boolean] attach categories to response -
tags
- [Boolean] attach tags to response
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#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) ⇒ Object
Get Content Instances.
-
#get_content_page(slug, options = nil) ⇒ Object
Get Content Page.
-
#get_content_template(slug, options = nil) ⇒ Object
Get Content Template.
-
#get_content_templates(options = nil) ⇒ Object
Get Content Templates.
-
#get_form(slug, options = nil) ⇒ Object
Get Form.
-
#get_forms(options = nil) ⇒ Object
Get Forms.
-
#get_product(slug, options = nil) ⇒ Object
Get Product.
-
#get_product_brand(slug, options = nil) ⇒ Object
Get Product Brand.
-
#get_product_brands(options = nil) ⇒ Object
Get Product Brands.
-
#get_products(options = nil) ⇒ Object
Get Products.
-
#get_sku(slug, options = nil) ⇒ Object
Get SKU.
-
#get_skus(options = nil) ⇒ Object
Get SKUs.
-
#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 = 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 = 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
45 46 47 |
# File 'lib/pub.rb', line 45 def initialize(host, api_key, contact_token = nil, debug = false) @client = Mints::Client.new(host, api_key, contact_token, debug) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
33 34 35 |
# File 'lib/pub.rb', line 33 def client @client end |
Instance Method Details
#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
295 296 297 |
# File 'lib/pub.rb', line 295 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
253 254 255 |
# File 'lib/pub.rb', line 253 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
264 265 266 |
# File 'lib/pub.rb', line 264 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
128 129 130 |
# File 'lib/pub.rb', line 128 def get_content_instance(slug, = nil) return @client.raw("get", "/content/content-instances/#{slug}", ) end |
#get_content_instances(options) ⇒ 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
117 118 119 |
# File 'lib/pub.rb', line 117 def get_content_instances() 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
86 87 88 |
# File 'lib/pub.rb', line 86 def get_content_page(slug, = nil) return @client.raw("get", "/content/content-pages/#{slug}", ) end |
#get_content_template(slug, options = nil) ⇒ Object
Get Content Template.
Get a single content template.
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
107 108 109 |
# File 'lib/pub.rb', line 107 def get_content_template(slug, = nil) return @client.raw("get", "/content/content-templates/#{slug}", ) end |
#get_content_templates(options = nil) ⇒ Object
Get Content Templates.
Get a collection of content templates
Parameters
-
options
- [Hash] List of Resource collection Options shown above can be used as parameter
96 97 98 |
# File 'lib/pub.rb', line 96 def get_content_templates( = nil) return @client.raw("get", "/content/content-templates", ) 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
170 171 172 |
# File 'lib/pub.rb', line 170 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
159 160 161 |
# File 'lib/pub.rb', line 159 def get_forms( = nil) return @client.raw("get", "/content/forms", ) 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
201 202 203 |
# File 'lib/pub.rb', line 201 def get_product(slug, = nil) return @client.raw("get", "/ecommerce/products/#{slug}", ) end |
#get_product_brand(slug, options = nil) ⇒ Object
Get Product Brand.
Get a product brand.
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
222 223 224 |
# File 'lib/pub.rb', line 222 def get_product_brand(slug, = nil) return @client.raw("get", "/ecommerce/product-brands/#{slug}", ) end |
#get_product_brands(options = nil) ⇒ Object
Get Product Brands.
Get a collection of product brands.
Parameters
-
options
- [Hash] List of Resource collection Options shown above can be used as parameter
211 212 213 |
# File 'lib/pub.rb', line 211 def get_product_brands( = nil) return @client.raw("get", "/ecommerce/product-brands", ) 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
190 191 192 |
# File 'lib/pub.rb', line 190 def get_products( = nil) return @client.raw("get", "/ecommerce/products", ) end |
#get_sku(slug, options = nil) ⇒ Object
Get SKU.
Get a single SKU.
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
243 244 245 |
# File 'lib/pub.rb', line 243 def get_sku(slug, = nil) return @client.raw("get", "/ecommerce/skus/#{slug}", ) end |
#get_skus(options = nil) ⇒ Object
Get SKUs.
Get a collection of SKUs.
Parameters
-
options
- [Hash] List of Resource collection Options shown above can be used as parameter
232 233 234 |
# File 'lib/pub.rb', line 232 def get_skus( = nil) return @client.raw("get", "/ecommerce/skus", ) 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
138 139 140 |
# File 'lib/pub.rb', line 138 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
149 150 151 |
# File 'lib/pub.rb', line 149 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
285 286 287 |
# File 'lib/pub.rb', line 285 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
274 275 276 |
# File 'lib/pub.rb', line 274 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
305 306 307 |
# File 'lib/pub.rb', line 305 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
316 317 318 |
# File 'lib/pub.rb', line 316 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
58 59 60 61 62 63 64 65 66 |
# File 'lib/pub.rb', line 58 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) 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
75 76 77 |
# File 'lib/pub.rb', line 75 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
180 181 182 |
# File 'lib/pub.rb', line 180 def submit_form(data) return @client.raw("post", "/forms/store", nil, data) end |