Sha256: 380d4a01484e6abea898bcf35df7a1f2603b979c4524feb3c75ff05c86085309

Contents?: true

Size: 889 Bytes

Versions: 4

Compression:

Stored size: 889 Bytes

Contents

module WoopraRails
  class << self
    def identify(name=nil, email=nil, session=nil)
      @session = Digest::MD5.hexdigest(session.nil? ? email : session)
      set_base
      @base_params += "&cv_name=#{URI::encode name}&cv_email=#{URI::encode email}"
      issue_request
    end

    def log_pageview(title, url)
      issue_request("&ce_name=pv&ce_title=#{URI::encode title}&ce_url=#{url}")
    end

    def log_event(event_name, args={})
      action = "&ce_name=#{URI::encode event_name.to_s}"
      args.each do |k,v|
        action += "&ce_#{k}=#{URI::encode v.to_s}"
      end
      issue_request(action)
    end

    def issue_request(action=nil)
      action = action.nil? ? @base_params : @base_params + action
      uri = URI.parse(action)
      resp = WoopraRails::Response.new(Net::HTTP.get(uri))
      return resp if resp.success?
      raise WoopraError
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
woopra_rails-1.0.7 lib/woopra_rails/api.rb
woopra_rails-1.0.6 lib/woopra_rails/api.rb
woopra_rails-1.0.5 lib/woopra_rails/api.rb
woopra_rails-1.0.4 lib/woopra_rails/api.rb