Class: Garsh

Inherits:
Object
  • Object
show all
Defined in:
lib/garsh.rb,
lib/garsh/version.rb

Defined Under Namespace

Classes: Event

Constant Summary collapse

GA_ENDPOINT =
"https://www.google-analytics.com"
VERSION =
"0.1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ Garsh

Returns a new instance of Garsh.



15
16
17
# File 'lib/garsh.rb', line 15

def initialize(code)
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/garsh.rb', line 8

def code
  @code
end

Class Method Details

.client(code = ENV['GA_CODE']) ⇒ Object



11
12
13
# File 'lib/garsh.rb', line 11

def self.client(code = ENV['GA_CODE'])
  return new(code)
end

Instance Method Details

#create_event(action:, category: "", client_id: "555") ⇒ Object



19
20
21
22
# File 'lib/garsh.rb', line 19

def create_event(action:, category: "", client_id: "555")
  event = Event.new(code: code, action: action, category: category, client_id: client_id)
  send_payload(Event::ENDPOINT, event.to_params)
end

#send_payload(endpoint, params) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/garsh.rb', line 24

def send_payload(endpoint, params)
  @http_client ||= Faraday.new(url: GA_ENDPOINT) { |cli|
    cli.adapter :typhoeus
    cli.response :logger
  }
  @http_client.get(endpoint, params)
end