Module: MintsHelper

Included in:
Mints::Contact, Mints::Pub, Mints::User
Defined in:
lib/mints/helpers/mints_helper.rb

Instance Method Summary collapse

Instance Method Details

#correct_json(data) ⇒ Object

Correct json.

Receives a json data and convert it to a symbolized object.

Parameters

data

(Hash) – Data to be submitted.

[View source]

42
43
44
45
46
47
48
# File 'lib/mints/helpers/mints_helper.rb', line 42

def correct_json(data)
  if data.is_a? String
    data = JSON.parse(data)
  end

  data.symbolize_keys
end

#data_transform(data) ⇒ Object

Data transform.

Transform a ‘data’ variable to a standardized ‘data’ variable.

Parameters

data

(Hash) – Data to be submitted.

[View source]

26
27
28
29
30
31
32
33
34
# File 'lib/mints/helpers/mints_helper.rb', line 26

def data_transform(data)
  data = correct_json(data)

  unless data[:data]
    data = { data: data }
  end

  data.to_json
end

#get_query_results(url, options = nil, use_post = true) ⇒ Object

Get query results.

Method used to give the options to make a ‘post’ or ‘get’ request.

Parameters

url

(String) – Url to make the request.

options

(Hash) – List of Resource collection Options shown above can be used as parameter.

use_post

(Boolean) – Variable to determine if the request is by ‘post’ or ‘get’ functions.

[View source]

12
13
14
15
16
17
18
# File 'lib/mints/helpers/mints_helper.rb', line 12

def get_query_results(url, options = nil, use_post = true)
  if use_post
    @client.raw('post', "#{url}/query", options)
  else
    @client.raw('get', url, options)
  end
end