mints 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 327d7dc897b313289564ea62d790eca41f338394b7d3285a54044004d73c4949
4
- data.tar.gz: 311fef416ffe4b8009752185f7ca974e6ebe4c887692608c03bee69e7432100c
3
+ metadata.gz: ef89ee973a9cb2bf2e4b77ad15e3481f7fc02e566f47099c7c44b94bdd3cb757
4
+ data.tar.gz: d40cf8e0445ce333ad735403f767622cc6428b7ab4f334040a542b0340d4eb49
5
5
  SHA512:
6
- metadata.gz: 132622f7ce07aed342c56e2c1bf3bc1a15be585fbf747c603b822e184ef55f7fb914d6216ad5b7e7c33d0831cbf33caf6b2927fa46eace7938e40ede898e86cf
7
- data.tar.gz: c5531bb9f2be7d66f8dd2b9951957b90e85b43c3d1e1527b462a3978f05ee9e768177f83aa6313d768d07c3062bee261add211d8dcbc5d5895f4dcf0f8c11ab2
6
+ metadata.gz: d8c404e2894b99bdb95a5db340ca9f47785cfec00fa6c3648b29a9b1c00e65a4a02569ccfdd5086e1911e468c942e93db214d21d2ac11c219934c66d9d3e9478
7
+ data.tar.gz: 2c24fc60a2cd29d377bd445cee14fbd611ddc728155eb7e3f2c545eec203100a64254b09e981128f28849dc7a95c1bded45bd592ebe67af3ed794f6e0b786809
data/Readme.md CHANGED
@@ -6,8 +6,7 @@ This is a library to connect apps built on ruby to Mints.Cloud
6
6
 
7
7
  Add gem to the Gemfile
8
8
  ```bash
9
- gem 'mints', git: 'https://github.com/rubengomez/mints-ruby-sdk'
10
- bundle install
9
+ gem 'mints'
11
10
  ```
12
11
 
13
12
  ## Usage
@@ -30,3 +29,18 @@ con = Mints::User.new(mints_url, api_key)
30
29
  con.login(email, password)
31
30
  con.get_contacts
32
31
  ```
32
+ ## Contact tracking usage
33
+ Your app controller need to be inherited from Mints::BaseController
34
+ ```ruby
35
+ # application_controller.rb
36
+
37
+ class ApplicationController < Mints::BaseController
38
+ end
39
+ ```
40
+ This controller will make the following class variables available:
41
+
42
+ | Variable | Description |
43
+ | --- | :---: |
44
+ | @mints_pub | An already instanced public client |
45
+ | @contact_token | A token used by mints to identify the contact |
46
+ | @visit_id | An identifier of the visit registered |
@@ -216,7 +216,12 @@ module Mints
216
216
  # End User Context
217
217
 
218
218
  def public_get(url, headers = nil)
219
- h = {"Accept" => "application/json", "Contet-Type" => "application/json", "ApiKey" => @api_key}
219
+ h = {
220
+ "Accept" => "application/json",
221
+ "Contet-Type" => "application/json",
222
+ "ApiKey" => @api_key,
223
+ "ContactToken" => @session_token
224
+ }
220
225
  if headers
221
226
  headers.each do |k,v|
222
227
  h[k] = v
@@ -226,7 +231,12 @@ module Mints
226
231
  end
227
232
 
228
233
  def public_post(url, headers = nil, data)
229
- h = {"Accept" => "application/json", "Contet-Type" => "application/json", "ApiKey" => @api_key}
234
+ h = {
235
+ "Accept" => "application/json",
236
+ "Contet-Type" => "application/json",
237
+ "ApiKey" => @api_key,
238
+ "ContactToken" => @session_token
239
+ }
230
240
  if headers
231
241
  headers.each do |k,v|
232
242
  h[k] = v
@@ -236,7 +246,12 @@ module Mints
236
246
  end
237
247
 
238
248
  def public_put(url, headers = nil, data)
239
- h = {"Accept" => "application/json", "Contet-Type" => "application/json", "ApiKey" => @api_key}
249
+ h = {
250
+ "Accept" => "application/json",
251
+ "Contet-Type" => "application/json",
252
+ "ApiKey" => @api_key,
253
+ "ContactToken" => @session_token
254
+ }
240
255
  if headers
241
256
  headers.each do |k,v|
242
257
  h[k] = v
@@ -0,0 +1,4 @@
1
+ # Mints connection configuration
2
+ mints:
3
+ host: http://your_host_goes_here.com
4
+ api_key: your_mints_api_key_goes_here
@@ -0,0 +1,6 @@
1
+ class MintsFilesGenerator < Rails::Generators::Base
2
+ source_root(File.expand_path(File.dirname(__FILE__)))
3
+ def create_mints_files
4
+ copy_file 'mints_config.yml', 'mints_config.yml'
5
+ end
6
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative "./pub.rb"
2
2
  require_relative "./contact.rb"
3
3
  require_relative "./user.rb"
4
+ require_relative "./mints/controllers/mints_base_controller.rb"
4
5
  module Mints
5
6
  end
@@ -0,0 +1,35 @@
1
+ module Mints
2
+ class BaseController < ActionController::Base
3
+ before_action :set_contact_token
4
+ before_action :set_mints_pub
5
+ before_action :register_visit
6
+
7
+ private
8
+ ##
9
+ # === Register visit.
10
+ # Call register visit method from the public client and set/renew the cookie mints_contact_id
11
+ def register_visit
12
+ response = @mints_pub.register_visit(request)
13
+ @contact_token = response['user_token']
14
+ @visit_id = response['visit_id']
15
+ cookies.permanent[:mints_contact_id] = @contact_token
16
+ end
17
+
18
+ ##
19
+ # === Set mints pub.
20
+ # Initialize the public client and set the contact token
21
+ def set_mints_pub
22
+ # Initialize mints pub client, credentials taken from mints_config.yml file
23
+ @mints_pub = Mints::Pub.new
24
+ # Set contact token from cookie
25
+ @mints_pub.client.session_token = @contact_token
26
+ end
27
+
28
+ ##
29
+ # === Set contact token.
30
+ # Set contact token variable from the mints_contact_id cookie value
31
+ def set_contact_token
32
+ @contact_token = cookies[:mints_contact_id]
33
+ end
34
+ end
35
+ end
data/lib/pub.rb CHANGED
@@ -1,12 +1,14 @@
1
+ require 'yaml'
1
2
  require_relative './client.rb'
2
3
  module Mints
3
-
4
4
  ##
5
5
  # == Public context API
6
6
  # Pub class contains functions that needs only an API key as authentication
7
7
  # == Usage example
8
8
  # Initialize
9
9
  # pub = Mints::Pub.new(mints_url, api_key)
10
+ # or if host and api_key are provided by mints_config.yml
11
+ # pub = Mints::Pub.new
10
12
  # Call any function
11
13
  # pub.get_products
12
14
  # == Single resource options
@@ -25,6 +27,7 @@ module Mints
25
27
  # * +include+ - [String] include a relationship
26
28
  # * +attributes+ - [Boolean] attach attributes to response
27
29
  # * +categories+ - [Boolean] attach categories to response
30
+ # * +taxonomies+ - [Boolean] attach categories to response
28
31
  # * +tags+ - [Boolean] attach tags to response
29
32
  class Pub
30
33
  attr_reader :client
@@ -36,10 +39,20 @@ module Mints
36
39
  # ==== Parameters
37
40
  # * +host+ - [String] It's the visitor IP
38
41
  # * +api_key+ - [String] Mints instance api key
42
+ # * +contact_token+ - [String] Cookie 'mints_contact_id' value (mints_contact_token)
39
43
  # ==== Return
40
44
  # Returns a Client object
41
- def initialize(host, api_key)
42
- @client = Mints::Client.new(host, api_key)
45
+ def initialize(host=nil, api_key=nil, contact_token=nil)
46
+ if host === nil and api_key === nil
47
+ if File.exists?("#{Rails.root}/mints_config.yml")
48
+ config = YAML.load_file("#{Rails.root}/mints_config.yml")
49
+ host = config["mints"]["host"]
50
+ api_key = config["mints"]["api_key"]
51
+ else
52
+ raise 'MintsBadCredentialsError'
53
+ end
54
+ end
55
+ @client = Mints::Client.new(host, api_key, contact_token)
43
56
  end
44
57
 
45
58
  ##
@@ -47,16 +60,18 @@ module Mints
47
60
  # Register a ghost/contact visit in Mints.Cloud
48
61
  #
49
62
  # ==== Parameters
63
+ # * +request+ - [ActionDispatch::Request] request
50
64
  # * +ip+ - [String] It's the visitor IP
51
65
  # * +user_agent+ - The visitor's browser user agent
52
66
  # * +url+ - [String] URL visited
53
- def register_visit(ip, user_agent, url)
67
+ def register_visit(request, ip=nil, user_agent=nil, url=nil)
54
68
  data = {
55
- ip_address: ip,
56
- user_agent: user_agent,
57
- url: url
69
+ ip_address: ip || request.remote_ip,
70
+ user_agent: user_agent || request.user_agent,
71
+ url: url || request.fullpath
58
72
  }
59
- return @client.raw("post", "/register-visit-timer", nil, data)
73
+ response = @client.raw("post", "/register-visit", nil, data)
74
+ return response
60
75
  end
61
76
 
62
77
  ##
@@ -290,5 +305,26 @@ module Mints
290
305
  def get_attributes(options = nil)
291
306
  return @client.raw("get", "/config/attributes", options)
292
307
  end
308
+
309
+ ##
310
+ # === Get Taxonomies.
311
+ # Get a collection of taxonomies.
312
+ #
313
+ # ==== Parameters
314
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::Pub-label-Resource+collections+options+] shown above can be used as parameter
315
+ def get_taxonomies(options = nil)
316
+ return @client.raw("get", "/config/taxonomies", options)
317
+ end
318
+
319
+ ##
320
+ # === Get Taxonomy.
321
+ # Get a single taxonomy
322
+ #
323
+ # ==== Parameters
324
+ # * +slug+ - [String] It's the string identifier generated by Mints
325
+ # * +options+ - [Hash] List of {Single Resource Options}[#class-Mints::Pub-label-Single+resource+options] shown above can be used as parameter
326
+ def get_taxonomy(slug, options = nil)
327
+ return @client.raw("get", "/config/taxonomies/#{slug}", options)
328
+ end
293
329
  end
294
330
  end
@@ -1,5 +1,31 @@
1
1
  require_relative './client.rb'
2
2
  module Mints
3
+ ##
4
+ # == User context API
5
+ # User class contains functions that needs an API key and a session token as authentication
6
+ # == Usage example
7
+ # Initialize
8
+ # client = Mints::User.new(mints_url, api_key)
9
+ # Call any function
10
+ # client.get_contacts
11
+ # == Single resource options
12
+ # * +include+ - [String] include a relationship
13
+ # * +attributes+ - [Boolean] attach attributes to response
14
+ # * +categories+ - [Boolean] attach categories to response
15
+ # * +tags+ - [Boolean] attach tags to response
16
+ # == Resource collections options
17
+ # * +search+ - [String] filter by a search word
18
+ # * +scopes+ - [String] filter by a scope
19
+ # * +filters+ - [String] filter by where clauses
20
+ # * +jfilters+ - [String] filter using complex condition objects
21
+ # * +catfilters+ - [String] filter by categories
22
+ # * +fields+ - [String] indicates the columns that will be selected
23
+ # * +sort+ - [String] indicates the columns that will be selected
24
+ # * +include+ - [String] include a relationship
25
+ # * +attributes+ - [Boolean] attach attributes to response
26
+ # * +categories+ - [Boolean] attach categories to response
27
+ # * +taxonomies+ - [Boolean] attach categories to response
28
+ # * +tags+ - [Boolean] attach tags to response
3
29
  class User
4
30
  attr_reader :client
5
31
  def initialize(host, api_key, session_token = nil)
@@ -18,7 +44,12 @@ module Mints
18
44
  return response
19
45
  end
20
46
  ######################################### CRM #########################################
21
- ### Contacts ###
47
+ ##
48
+ # === Get contacts.
49
+ # Get a collection of contacts
50
+ #
51
+ # ==== Parameters
52
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
22
53
  def get_contacts(options = nil)
23
54
  return @client.get__crm__contacts(options)
24
55
  end
@@ -34,7 +65,12 @@ module Mints
34
65
  def update_contact(id, data, options = nil)
35
66
  return @client.update__crm__contacts(id, data, options)
36
67
  end
37
- ### Companies ###
68
+
69
+ # === Get companies.
70
+ # Get a collection of companies
71
+ #
72
+ # ==== Parameters
73
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
38
74
  def get_companies(options = nil)
39
75
  return @client.get__crm__companies(options)
40
76
  end
@@ -51,7 +87,11 @@ module Mints
51
87
  return @client.update__crm__companies(id, data, options)
52
88
  end
53
89
 
54
- ### Deals ###
90
+ # === Get deals.
91
+ # Get a collection of deals
92
+ #
93
+ # ==== Parameters
94
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
55
95
  def get_deals(options = nil)
56
96
  return @client.get__crm__deals(options)
57
97
  end
@@ -69,7 +109,11 @@ module Mints
69
109
  end
70
110
 
71
111
  ######################################### Content #########################################
72
- ### Stories ###
112
+ # === Get stories.
113
+ # Get a collection of stories
114
+ #
115
+ # ==== Parameters
116
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
73
117
  def get_stories(options = nil)
74
118
  return @client.get__content__stories(options)
75
119
  end
@@ -86,7 +130,11 @@ module Mints
86
130
  return @client.update__content__stories(id, data, options)
87
131
  end
88
132
 
89
- ### Stories templates ###
133
+ # === Get story templates.
134
+ # Get a collection of story templates
135
+ #
136
+ # ==== Parameters
137
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
90
138
  def get_story_templates(options = nil)
91
139
  return @client.get__content__story_templates(options)
92
140
  end
@@ -103,7 +151,11 @@ module Mints
103
151
  return @client.update__content__story_templates(id, data, options)
104
152
  end
105
153
 
106
- ### Content instances ###
154
+ # === Get content instances.
155
+ # Get a collection of content instances
156
+ #
157
+ # ==== Parameters
158
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
107
159
  def get_content_instances(options = nil)
108
160
  return @client.get__content__instances(options)
109
161
  end
@@ -120,7 +172,11 @@ module Mints
120
172
  return @client.update__content__instances(id, data, options)
121
173
  end
122
174
 
123
- ### Content pages ###
175
+ # === Get content pages.
176
+ # Get a collection of content pages
177
+ #
178
+ # ==== Parameters
179
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
124
180
  def get_content_pages(options = nil)
125
181
  return @client.get__content__pages(options)
126
182
  end
@@ -137,25 +193,32 @@ module Mints
137
193
  return @client.update__content__pages(id, data, options)
138
194
  end
139
195
 
140
- ### Content templates ###
196
+ # === Get content templates.
197
+ # Get a collection of content templates
198
+ #
199
+ # ==== Parameters
200
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
141
201
  def get_content_templates(options = nil)
142
202
  return @client.get__content__templates(options)
143
203
  end
144
204
 
145
- def get_content_page(id, options = nil)
205
+ def get_content_template(id, options = nil)
146
206
  return @client.get__content__templates(id, options)
147
207
  end
148
208
 
149
- def create_content_page(data, options = nil)
209
+ def create_content_template(data, options = nil)
150
210
  return @client.create__content__templates(data, options)
151
211
  end
152
212
 
153
- def update_content_page(id, data, options = nil)
213
+ def update_content_template(id, data, options = nil)
154
214
  return @client.update__content__templates(id, data, options)
155
215
  end
156
216
 
157
- ######################################### Ecommerce #########################################
158
- ### Products ###
217
+ # === Get products.
218
+ # Get a collection of products
219
+ #
220
+ # ==== Parameters
221
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
159
222
  def get_products(options = nil)
160
223
  return @client.get__ecommerce__products(options)
161
224
  end
@@ -172,7 +235,11 @@ module Mints
172
235
  return @client.update__ecommerce__products(id, data, options)
173
236
  end
174
237
 
175
- ### SKUs ###
238
+ # === Get skus.
239
+ # Get a collection of skus
240
+ #
241
+ # ==== Parameters
242
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
176
243
  def get_skus(options = nil)
177
244
  return @client.get__ecommerce__skus(options)
178
245
  end
@@ -189,7 +256,11 @@ module Mints
189
256
  return @client.update__ecommerce__skus(id, data, options)
190
257
  end
191
258
 
192
- ### Prices ###
259
+ # === Get prices.
260
+ # Get a collection of prices
261
+ #
262
+ # ==== Parameters
263
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
193
264
  def get_prices(options = nil)
194
265
  return @client.get__ecommerce__prices(options)
195
266
  end
@@ -206,7 +277,11 @@ module Mints
206
277
  return @client.update__ecommerce__prices(id, data, options)
207
278
  end
208
279
 
209
- ### Price lists ###
280
+ # === Get prece lists.
281
+ # Get a collection of prece lists
282
+ #
283
+ # ==== Parameters
284
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
210
285
  def get_price_lists(options = nil)
211
286
  return @client.get__ecommerce__price_lists(options)
212
287
  end
@@ -223,7 +298,11 @@ module Mints
223
298
  return @client.update__ecommerce__price_lists(id, data, options)
224
299
  end
225
300
 
226
- ### Product brands ###
301
+ # === Get product brands.
302
+ # Get a collection of product brands
303
+ #
304
+ # ==== Parameters
305
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
227
306
  def get_product_brands(options = nil)
228
307
  return @client.get__ecommerce__product_brands(options)
229
308
  end
@@ -240,7 +319,11 @@ module Mints
240
319
  return @client.update__ecommerce__product_brands(id, data, options)
241
320
  end
242
321
 
243
- ### Product types ###
322
+ # === Get product types.
323
+ # Get a collection of product types
324
+ #
325
+ # ==== Parameters
326
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
244
327
  def get_product_types(options = nil)
245
328
  return @client.get__ecommerce__product_types(options)
246
329
  end
@@ -257,7 +340,11 @@ module Mints
257
340
  return @client.update__ecommerce__product_types(id, data, options)
258
341
  end
259
342
 
260
- ### Product templates ###
343
+ # === Get product templates.
344
+ # Get a collection of product templates
345
+ #
346
+ # ==== Parameters
347
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
261
348
  def get_product_templates(options = nil)
262
349
  return @client.get__ecommerce__product_templates(options)
263
350
  end
@@ -275,7 +362,11 @@ module Mints
275
362
  end
276
363
 
277
364
 
278
- ### Locations ###
365
+ # === Get locations.
366
+ # Get a collection of locations
367
+ #
368
+ # ==== Parameters
369
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
279
370
  def get_locations(options = nil)
280
371
  return @client.get__ecommerce__locations(options)
281
372
  end
@@ -291,5 +382,26 @@ module Mints
291
382
  def update_location(id, data, options = nil)
292
383
  return @client.update__ecommerce__locations(id, data, options)
293
384
  end
294
- end
385
+
386
+ # === Get taxonomies.
387
+ # Get a collection of taxonomies
388
+ #
389
+ # ==== Parameters
390
+ # * +options+ - [Hash] List of {Resource collection Options}[#class-Mints::User-label-Resource+collections+options+] shown above can be used as parameter
391
+ def get_taxonomies(options = nil)
392
+ return @client.get__config__taxonomies(options)
393
+ end
394
+
395
+ def get_taxonomy(id, options = nil)
396
+ return @client.get__config__taxonomies(id, options)
397
+ end
398
+
399
+ def create_taxonomy(data, options = nil)
400
+ return @client.create__config__taxonomies(data, options)
401
+ end
402
+
403
+ def update_taxonomy(id, data, options = nil)
404
+ return @client.update__config__taxonomies(id, data, options)
405
+ end
406
+ end
295
407
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Gomez Garcia, Omar Mora
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -80,7 +80,10 @@ files:
80
80
  - Readme.md
81
81
  - lib/client.rb
82
82
  - lib/contact.rb
83
+ - lib/generators/mints_config.yml
84
+ - lib/generators/mints_files_generator.rb
83
85
  - lib/mints.rb
86
+ - lib/mints/controllers/mints_base_controller.rb
84
87
  - lib/pub.rb
85
88
  - lib/user.rb
86
89
  homepage: https://github.com/rubengomez/mints-ruby-sdk
@@ -89,6 +92,7 @@ metadata: {}
89
92
  post_install_message:
90
93
  rdoc_options: []
91
94
  require_paths:
95
+ - app
92
96
  - lib
93
97
  required_ruby_version: !ruby/object:Gem::Requirement
94
98
  requirements: