Class: Emarsys::DataObject

Inherits:
Object
  • Object
show all
Defined in:
lib/emarsys/data_object.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete(account, method_name, params) ⇒ Hash

Make a HTTP DELETE request

Parameters:

  • account (Symbol)

    Configuration account to use

  • method_name (String)

    The path, relative to Emarsys.api_endpoint

  • params (Hash)

    custom params hash

Returns:



48
49
50
# File 'lib/emarsys/data_object.rb', line 48

def delete(, method_name, params)
  self.new.request , 'delete', method_name, params
end

.get(account, method_name, params) ⇒ Hash

Make a HTTP GET request

Parameters:

  • account (Symbol)

    Configuration account to use

  • method_name (String)

    The path, relative to Emarsys.api_endpoint

  • params (Hash)

    custom params hash

Returns:



14
15
16
17
18
19
20
# File 'lib/emarsys/data_object.rb', line 14

def get(, method_name, params)
  if params.empty?
    self.new.request , 'get', method_name, params
  else
    self.new.request , 'get', [method_name, parameterize_params(params)].join("/"), {}
  end
end

.parameterize_params(params) ⇒ String

Custom Parameterizer for Emarsys

Parameters:

  • params (Hash)

    custom params hash

Returns:

  • (String)

    {key1 => value1, key2 => value2 is returned as ?key1=value1&key2=value2



56
57
58
# File 'lib/emarsys/data_object.rb', line 56

def parameterize_params(params)
  '?' + params.map{|k, v| "#{url_encode(k)}=#{url_encode(v)}"}.join('&')
end

.post(account, method_name, params) ⇒ Hash

Make a HTTP POST request

Parameters:

  • account (Symbol)

    Configuration account to use

  • method_name (String)

    The path, relative to Emarsys.api_endpoint

  • params (Hash)

    custom params hash

Returns:



28
29
30
# File 'lib/emarsys/data_object.rb', line 28

def post(, method_name, params)
  self.new.request , 'post', method_name, params
end

.put(account, method_name, params) ⇒ Hash

Make a HTTP PUT request

Parameters:

  • account (Symbol)

    Configuration account to use

  • method_name (String)

    The path, relative to Emarsys.api_endpoint

  • params (Hash)

    custom params hash

Returns:



38
39
40
# File 'lib/emarsys/data_object.rb', line 38

def put(, method_name, params)
  self.new.request , 'put', method_name, params
end

Instance Method Details

#request(account, http_verb, method_name, params) ⇒ Hash

Make a HTTP request

Parameters:

  • account (Symbol)

    Configuration account to use

  • http_verb (String)

    Http method

  • method_name (String)

    The path, relative to Emarsys.api_endpoint

  • params (Hash)

    custom params hash

Returns:



76
77
78
# File 'lib/emarsys/data_object.rb', line 76

def request(, http_verb, method_name, params)
  response = Emarsys::Request.new(, http_verb, method_name, params).send_request
end