Class: Piwik::Site
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
Class Method Summary collapse
Instance Method Summary collapse
-
#give_admin_access_to(login) ⇒ Object
Gives read and write access (
'admin'
) for the supplied user login for the current site. -
#give_no_access_to(login) ⇒ Object
(also: #remove_access_for)
Removes all access (gives a
'noaccess'
) for the supplied user login for the current site. -
#give_view_access_to(login) ⇒ Object
Gives read access (
'view'
) to the supplied user login for the current site. -
#seo_info ⇒ Object
Returns search engine information for site home.
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
Methods included from Typecast
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
.collection ⇒ Object
58 59 60 |
# File 'lib/piwik/site.rb', line 58 def collection Piwik::SitesManager end |
.id_attr ⇒ Object
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(login) give_access_to(:admin, login) 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(login) give_access_to(:noaccess, login) 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(login) give_access_to(:view, login) end |