Class: Mints::Pub

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#clientObject (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


295
296
297
# File 'lib/pub.rb', line 295

def get_attributes(options = nil)
  return @client.raw("get", "/config/attributes", options)
end

#get_categories(options = nil) ⇒ Object

Get categories.

Get a collection of categories.

Parameters


253
254
255
# File 'lib/pub.rb', line 253

def get_categories(options = nil)
  return @client.raw("get", "/config/categories", options)
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, options = nil)
  return @client.raw("get", "/config/categories/#{slug}", options)
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, options = nil)
  return @client.raw("get", "/content/content-instances/#{slug}", options)
end

#get_content_instances(options) ⇒ Object

Get Content Instances.

Get a collection of content instances

Parameters


117
118
119
# File 'lib/pub.rb', line 117

def get_content_instances(options) 
  return @client.raw("get", "/content/content-instances", options)
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, options = nil)
  return @client.raw("get", "/content/content-pages/#{slug}", options)
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, options = nil)
  return @client.raw("get", "/content/content-templates/#{slug}", options)
end

#get_content_templates(options = nil) ⇒ Object

Get Content Templates.

Get a collection of content templates

Parameters


96
97
98
# File 'lib/pub.rb', line 96

def get_content_templates(options = nil)
  return @client.raw("get", "/content/content-templates", options)
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, options = nil)
  return @client.raw("get", "/content/forms/#{slug}", options)
end

#get_forms(options = nil) ⇒ Object

Get Forms.

Get a collection of forms

Parameters


159
160
161
# File 'lib/pub.rb', line 159

def get_forms(options = nil)
  return @client.raw("get", "/content/forms", options)
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, options = nil)
  return @client.raw("get", "/ecommerce/products/#{slug}", options)
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, options = nil)
  return @client.raw("get", "/ecommerce/product-brands/#{slug}", options)
end

#get_product_brands(options = nil) ⇒ Object

Get Product Brands.

Get a collection of product brands.

Parameters


211
212
213
# File 'lib/pub.rb', line 211

def get_product_brands(options = nil)
  return @client.raw("get", "/ecommerce/product-brands", options)
end

#get_products(options = nil) ⇒ Object

Get Products.

Get a collection of products.

Parameters


190
191
192
# File 'lib/pub.rb', line 190

def get_products(options = nil)
  return @client.raw("get", "/ecommerce/products", options)
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, options = nil)
  return @client.raw("get", "/ecommerce/skus/#{slug}", options)
end

#get_skus(options = nil) ⇒ Object

Get SKUs.

Get a collection of SKUs.

Parameters


232
233
234
# File 'lib/pub.rb', line 232

def get_skus(options = nil)
  return @client.raw("get", "/ecommerce/skus", options)
end

#get_stories(options = nil) ⇒ Object

Get Stories.

Get a collection of stories

Parameters


138
139
140
# File 'lib/pub.rb', line 138

def get_stories(options = nil)
  return @client.raw("get", "/content/stories", options)
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, options = nil)
  return @client.raw("get", "/content/stories/#{slug}", options)
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, options = nil)
  return @client.raw("get", "/config/tags/#{slug}", options)
end

#get_tags(options = nil) ⇒ Object

Get Tags.

Get a collection of tags.

Parameters


274
275
276
# File 'lib/pub.rb', line 274

def get_tags(options = nil)
  return @client.raw("get", "/config/tags", options)
end

#get_taxonomies(options = nil) ⇒ Object

Get Taxonomies.

Get a collection of taxonomies.

Parameters


305
306
307
# File 'lib/pub.rb', line 305

def get_taxonomies(options = nil)
  return @client.raw("get", "/config/taxonomies", options)
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, options = nil)
  return @client.raw("get", "/config/taxonomies/#{slug}", options)
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