Class: Analytico::Client
- Inherits:
-
Object
- Object
- Analytico::Client
- Defined in:
- lib/analytico/client.rb
Constant Summary collapse
- @@connection =
nil
Class Method Summary collapse
- .add_impression(*args) ⇒ Object
- .add_metric(fqdn, name, value) ⇒ Object
- .async ⇒ Object
- .async=(async_flag) ⇒ Object
- .debug ⇒ Object
- .debug=(debug_flag) ⇒ Object
- .post(endpoint, data = nil) ⇒ Object
- .set_credentials(api_key) ⇒ Object
- .transmit(endpoint, data) ⇒ Object
Class Method Details
.add_impression(*args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/analytico/client.rb', line 37 def add_impression(*args) raise NoConnectionEstablished if @@connection.nil? = (args) if [:fqdn].nil? || [:ip].nil? return true end params = Hash.new params[:impression] = params[:impression][:api_key] = @@connection.api_key response = post(Endpoint.impressions, params) HashUtils.recursively_symbolize_keys(response) end |
.add_metric(fqdn, name, value) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/analytico/client.rb', line 52 def add_metric(fqdn, name, value) raise NoConnectionEstablished if @@connection.nil? params = Hash.new params[:metric] = Hash.new params[:metric][:api_key] = @@connection.api_key params[:metric][:fqdn] = fqdn params[:metric][:name] = name params[:metric][:value] = value response = post(Endpoint.metrics, params) HashUtils.recursively_symbolize_keys(response) end |
.async ⇒ Object
33 34 35 |
# File 'lib/analytico/client.rb', line 33 def async @@async end |
.async=(async_flag) ⇒ Object
28 29 30 31 |
# File 'lib/analytico/client.rb', line 28 def async=(async_flag) @@async = async_flag @@connection.async = @@async if @@connection end |
.debug ⇒ Object
24 25 26 |
# File 'lib/analytico/client.rb', line 24 def debug @@debug end |
.debug=(debug_flag) ⇒ Object
19 20 21 22 |
# File 'lib/analytico/client.rb', line 19 def debug=(debug_flag) @@debug = debug_flag @@connection.debug = @@debug if @@connection end |
.post(endpoint, data = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/analytico/client.rb', line 66 def post(endpoint, data=nil) unless production_env? Rails.logger.warn "%%% Analytico %%% Skipping while not in production. Would have sent (async: #{@@async ? 'on' : 'off' }): #{data.inspect}" return nil end if @@async self.send_later :transmit, endpoint, data else transmit endpoint, data end end |
.set_credentials(api_key) ⇒ Object
13 14 15 16 17 |
# File 'lib/analytico/client.rb', line 13 def set_credentials(api_key) @@connection = Connection.new(api_key) self.debug = @@debug true end |
.transmit(endpoint, data) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/analytico/client.rb', line 78 def transmit(endpoint, data) begin @@connection.post(endpoint, data) rescue Rails.logger.warn "%%% Analytico %%% There was an error communicating with Analytico" end end |