Class: Api::Callrail

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

Constant Summary collapse

API_KEY =
Heatwave::Configuration.fetch(:callrail, :api_key)
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.



9
10
11
# File 'app/services/api/callrail.rb', line 9

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'app/services/api/callrail.rb', line 5

def client
  @client
end

Class Method Details

.calls_summary(date_range) ⇒ Object



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

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

.clientObject



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

def self.client
  instance.client
end

.hostnameObject



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

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

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



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

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"
  response = client.get("#{hostname}/v3/a/#{ACCOUNT_ID}/calls.json?date_range=#{date_range}&per_page=#{per_page}&page=#{page}&fields=#{fields}").parse
end