Class: Piwik::Site

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

Overview

Piwik::Site is a wrapper class used to expose a more ruby-friendly (and sane) interface to the Piwik API. The Piwik API is under development, and there are quite a few incosistencies that are ironed out when it is used through the Piwik::Site metaclass.

Example usage using the bundled terminal script. Uses the official Piwik demo server as a sandbox

$ ./script/terminal -u http://demo.piwik.org -t anonymous
> site = Piwik::Site.load(7)
=> #<Piwik::Site[snip]> 
> summary = site.visits.summary
=> #<Piwik::VisitsSummary[snip]>
> summary.bounce_rate
=> "68%"
> site.visits.count
=> 467
> site.annotations.all
=> #<Piwik::Annotations::All[snip]>
> site.annotations.add(:date => 'today', :note => 'twitter account online', :starred => '1')
=> Piwik::ApiError: The current user is not allowed to add notes for site #7
> site.referers.website_count
=> 12

This class creates site-aware proxies (called api_scopes) to the various client classes. This lets you call api methods for a selected site without having to resubmit the site id all the time. Furthermore, API methods are redefined as proxy_methods, allowing for ruby-friendlier names, default parameters and other nice things.

Instance Attribute Summary

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#call, call, #collection, #config, #created_at, #delete, #id, #id_attr, #initialize, load, load_config_from_file, #method_missing, #new?, parse_xml, #parse_xml, #save

Methods included from ApiScope

included

Methods included from Typecast

included

Constructor Details

This class inherits a constructor from Piwik::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Piwik::Base

Class Method Details

.collectionObject


58
59
60
# File 'lib/piwik/site.rb', line 58

def collection
  Piwik::SitesManager
end

.id_attrObject


62
63
64
# File 'lib/piwik/site.rb', line 62

def id_attr
  :idSite
end

Instance Method Details

#give_admin_access_to(login) ⇒ Object

Gives read and write access ('admin') for the supplied user login for the current site.


47
48
49
# File 'lib/piwik/site.rb', line 47

def give_admin_access_to()
  give_access_to(:admin, )
end

#give_no_access_to(login) ⇒ Object Also known as: remove_access_for

Removes all access (gives a 'noaccess') for the supplied user login for the current site.


52
53
54
# File 'lib/piwik/site.rb', line 52

def give_no_access_to()
  give_access_to(:noaccess, )
end

#give_view_access_to(login) ⇒ Object

Gives read access ('view') to the supplied user login for the current site.


42
43
44
# File 'lib/piwik/site.rb', line 42

def give_view_access_to()
  give_access_to(:view, )
end

#seo_infoObject

Returns search engine information for site home


37
38
39
# File 'lib/piwik/site.rb', line 37

def seo_info
  Piwik::SEO.getRank(:url => self.main_url)
end