Class: PwnalyticsClient::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/pwnalytics_client/site.rb

Overview

Information about a site on a Pwnalytics server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, uid, name = 'unknown') ⇒ Site

New wrapper for a site on a Pwnalytics server.

This is called automatically by PwnalyticsClient in #sites and #site.

Args:

client:: the PwnalyticsClient connection to be used for queries
uid:: site's Pwnalytics UID
name:: site's user-friendly name (optional)


16
17
18
19
20
# File 'lib/pwnalytics_client/site.rb', line 16

def initialize(client, uid, name = 'unknown')
  @client = client
  @uid = uid
  @name = name
end

Instance Attribute Details

#clientObject (readonly)

PwnalyticsClient connection used for queries.



23
24
25
# File 'lib/pwnalytics_client/site.rb', line 23

def client
  @client
end

#nameObject (readonly)

User-friendly name for the site



27
28
29
# File 'lib/pwnalytics_client/site.rb', line 27

def name
  @name
end

#uidObject (readonly)

Pwnalytics UID for the site.



25
26
27
# File 'lib/pwnalytics_client/site.rb', line 25

def uid
  @uid
end

Instance Method Details

#events(options = {}) ⇒ Object

Queries the Pwnalytics server for events matching some criteria.

Options supports the following keys:

:names:: only get events whose names are contained in this array
:limit:: return the first events matching the criteria

Events will be resturned in the reverse order of their occurrence.



36
37
38
39
40
41
42
43
44
45
# File 'lib/pwnalytics_client/site.rb', line 36

def events(options = {})
  request = "/web_properties/#{@uid}/events.json?"
  request << "limit=#{options[:limit] || 'no'}"
  
  if options[:names]
    request << options[:names].
        map { |name| '&names%5B%5D=' + CGI.escape(name.to_s) }.join('')
  end
  @client.request(request).map { |data| Event.new self, data }
end