Class: Castle::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/castle/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ Client



7
8
9
10
11
12
13
# File 'lib/castle/client.rb', line 7

def initialize(request, response)
  @do_not_track = false
  cookie_id = Extractors::ClientId.new(request).call(response, '__cid')
  ip = Extractors::IP.new(request).call
  headers = Extractors::Headers.new(request).call
  @api = API.new(cookie_id, ip, headers)
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



5
6
7
# File 'lib/castle/client.rb', line 5

def api
  @api
end

Instance Method Details

#authenticate(args) ⇒ Object



23
24
25
# File 'lib/castle/client.rb', line 23

def authenticate(args)
  @api.request('authenticate', args)
end

#do_not_track!Object



31
32
33
# File 'lib/castle/client.rb', line 31

def do_not_track!
  @do_not_track = true
end

#do_not_track?Boolean



39
40
41
# File 'lib/castle/client.rb', line 39

def do_not_track?
  @do_not_track
end

#fetch_review(id) ⇒ Object



15
16
17
# File 'lib/castle/client.rb', line 15

def fetch_review(id)
  @api.request_query("reviews/#{id}")
end

#identify(args) ⇒ Object



19
20
21
# File 'lib/castle/client.rb', line 19

def identify(args)
  @api.request('identify', args) unless do_not_track?
end

#track(args) ⇒ Object



27
28
29
# File 'lib/castle/client.rb', line 27

def track(args)
  @api.request('track', args) unless do_not_track?
end

#track!Object



35
36
37
# File 'lib/castle/client.rb', line 35

def track!
  @do_not_track = false
end