Class: Attune::Api::Anonymous

Inherits:
Object
  • Object
show all
Defined in:
lib/attune/api/anonymous.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Anonymous

Returns a new instance of Anonymous.



9
10
11
# File 'lib/attune/api/anonymous.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#createAttune::Model::AnonymousResult

Create anonymous visitor

Returns:

Raises:

  • (ArgumentError)

    for invalid inputs

  • (Faraday::Error::ClientError)

    if the request fails or exceeds the timeout

  • (AuthenticationException)

    if authorization header not accepted



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/attune/api/anonymous.rb', line 19

def create ()
  query_param_keys = []

  # set default values and merge with input
  options = {
  }

  #resource path
  path = "/anonymous".sub('{format}','json')

  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  headers = nil
  post_body = nil
  response = @client.request(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body })
  if response
    Attune::Model::AnonymousResult.new(JSON.parse(response.body))
  else
    mockProc = MOCKS['Anonymous.create']
    if mockProc
      mockResponse = mockProc.call()
      Attune::Model::AnonymousResult.new(mockResponse)
    else
      nil
    end
  end
  
end

#get(anonymous) ⇒ Attune::Model::Customer

Returns an anonymous visitor, containing any assigned customer ID.

Parameters:

  • anonymous (String)

Returns:

Raises:

  • (ArgumentError)

    for invalid inputs

  • (Faraday::Error::ClientError)

    if the request fails or exceeds the timeout

  • (AuthenticationException)

    if authorization header not accepted



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/attune/api/anonymous.rb', line 111

def get (anonymous)
  query_param_keys = []

  # verify existence of params
  raise ArgumentError, "anonymous is required" if anonymous.nil?
  # set default values and merge with input
  options = {
  :anonymous => anonymous}

  #resource path
  path = "/anonymous/{anonymous}".sub('{format}','json').sub('{' + 'anonymous' + '}', escapeString(anonymous))
  

  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  headers = nil
  post_body = nil
  response = @client.request(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body })
  if response
    Attune::Model::Customer.new(JSON.parse(response.body))
  else
    mockProc = MOCKS['Anonymous.get']
    if mockProc
      mockResponse = mockProc.call(anonymous)
      Attune::Model::Customer.new(mockResponse)
    else
      nil
    end
  end
  
end

#update(anonymous, body) ⇒ Object

Binds one actor to another, allowing activities of those actors to be shared between the two.

Parameters:

Raises:

  • (ArgumentError)

    for invalid inputs

  • (Faraday::Error::ClientError)

    if the request fails or exceeds the timeout

  • (AuthenticationException)

    if authorization header not accepted



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/attune/api/anonymous.rb', line 58

def update (anonymous,body)
  query_param_keys = []

  # verify existence of params
  raise ArgumentError, "anonymous is required" if anonymous.nil?
  raise ArgumentError, "body is required" if body.nil?
  # set default values and merge with input
  options = {
  :anonymous => anonymous,
    :body => body}

  #resource path
  path = "/anonymous/{anonymous}".sub('{format}','json').sub('{' + 'anonymous' + '}', escapeString(anonymous))
  

  # pull querystring keys from options
  queryopts = options.select do |key,value|
    query_param_keys.include? key
  end

  headers = nil
  post_body = nil
  if body != nil
    if body.is_a?(Array)
      array = Array.new
      body.each do |item|
        if item.respond_to?("to_body".to_sym)
          array.push item.to_body
        else
          array.push item
        end
      end
      post_body = array

    else
      if body.respond_to?("to_body".to_sym)
        post_body = body.to_body
      else
        post_body = body
      end
    end
  end
  @client.request(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body})
  
end