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
-
#content_instance(slug, options = nil) ⇒ Object
Get Content Instance.
-
#content_instances(options) ⇒ Object
Get Content Instances.
-
#get_attributes(options = nil) ⇒ Object
Get Attributes.
-
#get_categories(options = nil) ⇒ Object
Get categories.
-
#get_category(slug, options = nil) ⇒ Object
Get Category.
-
#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) ⇒ Object
Get Tags.
-
#get_taxonomies(options = nil) ⇒ Object
Get Taxonomies.
-
#get_taxonomy(slug, options = nil) ⇒ Object
Get Taxonomy.
-
#initialize(host = nil, api_key = nil, contact_token = nil) ⇒ 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 = nil, api_key = nil, contact_token = nil) ⇒ 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 48 49 50 51 52 53 54 55 56 |
# File 'lib/pub.rb', line 45 def initialize(host=nil, api_key=nil, contact_token=nil) if host === nil and api_key === nil if File.exists?("#{Rails.root}/mints_config.yml") config = YAML.load_file("#{Rails.root}/mints_config.yml") host = config["mints"]["host"] api_key = config["mints"]["api_key"] else raise 'MintsBadCredentialsError' end end @client = Mints::Client.new(host, api_key, contact_token) 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
#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
137 138 139 |
# File 'lib/pub.rb', line 137 def content_instance(slug, = nil) return @client.raw("get", "/content/content-instances/#{slug}", ) end |
#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
126 127 128 |
# File 'lib/pub.rb', line 126 def content_instances() return @client.raw("get", "/content/content-instances", ) 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
305 306 307 |
# File 'lib/pub.rb', line 305 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
263 264 265 |
# File 'lib/pub.rb', line 263 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
274 275 276 |
# File 'lib/pub.rb', line 274 def get_category(slug, = nil) return @client.raw("get", "/config/categories/#{slug}", ) 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
95 96 97 |
# File 'lib/pub.rb', line 95 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
116 117 118 |
# File 'lib/pub.rb', line 116 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
105 106 107 |
# File 'lib/pub.rb', line 105 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
180 181 182 |
# File 'lib/pub.rb', line 180 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
-
slug- [String] It’s the string identifier generated by Mints -
options- [Hash] List of Resource collection Options shown above can be used as parameter
169 170 171 |
# File 'lib/pub.rb', line 169 def get_forms( = nil) return @client.raw("get", "/content/forms/{slug}", ) 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
211 212 213 |
# File 'lib/pub.rb', line 211 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
232 233 234 |
# File 'lib/pub.rb', line 232 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
221 222 223 |
# File 'lib/pub.rb', line 221 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
200 201 202 |
# File 'lib/pub.rb', line 200 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
253 254 255 |
# File 'lib/pub.rb', line 253 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
242 243 244 |
# File 'lib/pub.rb', line 242 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
147 148 149 |
# File 'lib/pub.rb', line 147 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
158 159 160 |
# File 'lib/pub.rb', line 158 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
295 296 297 |
# File 'lib/pub.rb', line 295 def get_tag(slug, = nil) return @client.raw("get", "/config/tags/#{slug}", ) end |
#get_tags(options) ⇒ Object
Get Tags.
Get a collection of tags.
Parameters
-
options- [Hash] List of Resource collection Options shown above can be used as parameter
284 285 286 |
# File 'lib/pub.rb', line 284 def () 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
315 316 317 |
# File 'lib/pub.rb', line 315 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
326 327 328 |
# File 'lib/pub.rb', line 326 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
67 68 69 70 71 72 73 74 75 |
# File 'lib/pub.rb', line 67 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
84 85 86 |
# File 'lib/pub.rb', line 84 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
190 191 192 |
# File 'lib/pub.rb', line 190 def submit_form(data) return @client.raw("post", "/forms/store", nil, data) end |