Class: Api::Callrail

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
app/services/api/callrail.rb

Overview

Service object: callrail.

Constant Summary collapse

API_KEY =

Key used for api.

Heatwave::Configuration.fetch(:callrail, :api_key)
ACCOUNT_ID =

Account id.

Heatwave::Configuration.fetch(:callrail, :account_id)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallrail

Returns a new instance of Callrail.



14
15
16
# File 'app/services/api/callrail.rb', line 14

def initialize
  @client = HTTP.auth("Token token=\"#{API_KEY}\"")
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'app/services/api/callrail.rb', line 7

def client
  @client
end

Class Method Details

.calls_summary(date_range) ⇒ Object



26
27
28
# File 'app/services/api/callrail.rb', line 26

def self.calls_summary(date_range)
  client.get("#{hostname}/v3/a/#{ACCOUNT_ID}/calls/summary.json?date_range=#{date_range}").parse
end

.clientObject



18
19
20
# File 'app/services/api/callrail.rb', line 18

def self.client
  instance.client
end

.hostnameObject



22
23
24
# File 'app/services/api/callrail.rb', line 22

def self.hostname
  Heatwave::Configuration.fetch(:callrail, :hostname)
end

.list_all_calls(per_page = 100, page = 1, date_range = 'yesterday') ⇒ Object



30
31
32
33
# File 'app/services/api/callrail.rb', line 30

def self.list_all_calls(per_page = 100, page = 1, date_range = 'yesterday')
  fields = "campaign,prior_calls,keywords,medium,gclid,referring_url,landing_page_url,last_requested_url,referrer_domain"
  client.get("#{hostname}/v3/a/#{ACCOUNT_ID}/calls.json?date_range=#{date_range}&per_page=#{per_page}&page=#{page}&fields=#{fields}").parse
end