Class: FathomAnalytics::Api

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

Constant Summary collapse

LIMIT =
50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, email:, password:) ⇒ Api

Returns a new instance of Api.



7
8
9
10
11
12
# File 'lib/fathom_analytics/api.rb', line 7

def initialize(url:, email:, password:)
  @url = url
  @email = email
  @password = password
  @auth_token = nil
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/fathom_analytics/api.rb', line 5

def email
  @email
end

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'lib/fathom_analytics/api.rb', line 5

def password
  @password
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/fathom_analytics/api.rb', line 5

def url
  @url
end

Instance Method Details

#add_site(name:) ⇒ Object



14
15
16
# File 'lib/fathom_analytics/api.rb', line 14

def add_site(name:)
  post_request(path: "/api/sites", params: { name: name })
end

#authenticateObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/fathom_analytics/api.rb', line 60

def authenticate
  params = {
    "Email": email,
    "Password": password
  }
  response = post_request(path: "/api/session", params: params, authenticated: false) do |raw_response|
    set_auth_token(raw_response)
  end
  response
end

#page_agg_page_views_stats(id:, from:, to:, limit: LIMIT, offset: 0) ⇒ Object



45
46
47
48
# File 'lib/fathom_analytics/api.rb', line 45

def page_agg_page_views_stats(id:, from:, to:, limit: LIMIT, offset: 0)
  path = "/api/sites/#{id}/stats/pages/agg/pageviews"
  get_request(path: path, before: to, after: from, limit: limit, offset: offset)
end

#page_agg_stats(id:, from:, to:, limit: LIMIT, offset: 0) ⇒ Object



40
41
42
43
# File 'lib/fathom_analytics/api.rb', line 40

def page_agg_stats(id:, from:, to:, limit: LIMIT, offset: 0)
  path = "/api/sites/#{id}/stats/pages/agg"
  get_request(path: path, before: to, after: from, limit: limit, offset: offset)
end

#referrer_agg_page_views_stats(id:, from:, to:, limit: LIMIT, offset: 0) ⇒ Object



55
56
57
58
# File 'lib/fathom_analytics/api.rb', line 55

def referrer_agg_page_views_stats(id:, from:, to:, limit: LIMIT, offset: 0)
  path = "/api/sites/#{id}/stats/referrers/agg/pageviews"
  get_request(path: path, before: to, after: from, limit: limit, offset: offset)
end

#referrer_agg_stats(id:, from:, to:, limit: LIMIT, offset: 0) ⇒ Object



50
51
52
53
# File 'lib/fathom_analytics/api.rb', line 50

def referrer_agg_stats(id:, from:, to:, limit: LIMIT, offset: 0)
  path = "/api/sites/#{id}/stats/referrers/agg"
  get_request(path: path, before: to, after: from, limit: limit, offset: offset)
end

#remove_site(id:) ⇒ Object



18
19
20
# File 'lib/fathom_analytics/api.rb', line 18

def remove_site(id:)
  delete_request(path: "/api/sites/#{id}")
end

#site_agg_stats(id:, from:, to:, limit: LIMIT, offset: 0) ⇒ Object



35
36
37
38
# File 'lib/fathom_analytics/api.rb', line 35

def site_agg_stats(id:, from:, to:, limit: LIMIT, offset: 0)
  path = "/api/sites/#{id}/stats/site/agg"
  get_request(path: path, before: to, after: from, limit: limit, offset: offset)
end

#site_realtime_stats(id:) ⇒ Object



26
27
28
# File 'lib/fathom_analytics/api.rb', line 26

def site_realtime_stats(id:)
  get_request(path: "/api/sites/#{id}/stats/site/realtime")
end

#site_stats(id:, from:, to:, limit: LIMIT, offset: 0) ⇒ Object



30
31
32
33
# File 'lib/fathom_analytics/api.rb', line 30

def site_stats(id:, from:, to:, limit: LIMIT, offset: 0)
  path = "/api/sites/#{id}/stats/site"
  get_request(path: path, before: to, after: from, limit: limit, offset: offset)
end

#sitesObject



22
23
24
# File 'lib/fathom_analytics/api.rb', line 22

def sites
  get_request(path: "/api/sites")
end