Class: Gosquared::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/gosquared/account.rb

Constant Summary collapse

BASEURL =
'https://api.gosquared.com/account/v1/'.freeze
DIMENSIONS =
%w[blocked feeds reportPreferences sharedUsers sites taggedVisitors triggerTypes webhooks].freeze
DIMENSION_FILTER =
%w[token webhookID visitorID triggerType].freeze
@@filters =
{ presenter: @presenter, ip: @ip, url: @url, email: @email }

Instance Method Summary collapse

Constructor Details

#initialize(api_key, site_token, client = Gosquared::Client.new) ⇒ Account

Returns a new instance of Account.


10
11
12
13
14
15
16
17
18
# File 'lib/gosquared/account.rb', line 10

def initialize(api_key, site_token, client = Gosquared::Client.new)
  @site_token = site_token
  @api_key = api_key
  @client = client
  @bots = ''
  @ips = ''
  @visitor = ''
  @dimension_filter = ''
end

Instance Method Details

#botsObject


60
61
62
# File 'lib/gosquared/account.rb', line 60

def bots
  @bots = '/bots'
end

#build_url(ips = @ips) ⇒ Object


74
75
76
77
78
79
80
81
# File 'lib/gosquared/account.rb', line 74

def build_url(ips = @ips)
  array = ['']
  @url = BASEURL + @dimension + @dimension_filter + @visitor + @bots + ips +
         "?api_key=#{@api_key}" + "&site_token=#{@site_token}"
  @@filters.each { |key, value| array << "#{key}=#{value}" if value }
  parameters = array.join('&')
  @url = @url.concat(parameters)
end

#deleteObject


54
55
56
57
58
# File 'lib/gosquared/account.rb', line 54

def delete
  response = @client.post(build_url, @data)
  @@filters.each { |key, _value| @@filters[key] = nil } if response.code === '200'
  response
end

#fetchObject


42
43
44
45
46
# File 'lib/gosquared/account.rb', line 42

def fetch
  data = @client.get(build_url)
  @@filters.each { |key, _value| @@filters[key] = nil } if data
  data
end

#ipsObject


64
65
66
67
# File 'lib/gosquared/account.rb', line 64

def ips
  @ips = '/ips'
  self
end

#postObject


48
49
50
51
52
# File 'lib/gosquared/account.rb', line 48

def post
  response = @client.post(build_url, @data)
  @@filters.each { |key, _value| @@filters[key] = nil } if response.code === '200'
  response
end

#visitors(id = '') ⇒ Object


69
70
71
72
# File 'lib/gosquared/account.rb', line 69

def visitors(id = '')
  @visitor = "/visitors/#{id}"
  self
end