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 = 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

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

#content_instances(options) ⇒ Object

Get Content Instances.

Get a collection of content instances

Parameters



126
127
128
# File 'lib/pub.rb', line 126

def content_instances(options) 
  return @client.raw("get", "/content/content-instances", options)
end

#get_attributes(options = nil) ⇒ Object

Get Attributes.

Get a collection of attributes.

Parameters



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

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



263
264
265
# File 'lib/pub.rb', line 263

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



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

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



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

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



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

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



105
106
107
# File 'lib/pub.rb', line 105

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



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

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



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

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



221
222
223
# File 'lib/pub.rb', line 221

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



200
201
202
# File 'lib/pub.rb', line 200

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



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

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



242
243
244
# File 'lib/pub.rb', line 242

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



147
148
149
# File 'lib/pub.rb', line 147

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



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

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



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

def get_tag(slug, options = nil)
  return @client.raw("get", "/config/tags/#{slug}", options)
end

#get_tags(options) ⇒ Object

Get Tags.

Get a collection of tags.

Parameters



284
285
286
# File 'lib/pub.rb', line 284

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

#get_taxonomies(options = nil) ⇒ Object

Get Taxonomies.

Get a collection of taxonomies.

Parameters



315
316
317
# File 'lib/pub.rb', line 315

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



326
327
328
# File 'lib/pub.rb', line 326

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



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