├── Rakefile ├── spec ├── files │ ├── SitesManager.addSite.xml │ ├── success.xml │ ├── MultiSites.getAll.xml │ ├── failure.xml │ ├── Referrers.getCampaigns.xml │ ├── Referrers.getSocials.xml │ ├── ExampleAPI.getSum.xml │ ├── Referrers.getUrlsForSocial.xml │ ├── .DS_Store │ ├── API.getPiwikVersion.xml │ ├── SitesManager.getSitesIdFromSiteUrl.xml │ ├── SitesManager.getSitesIdWithVisits.xml │ ├── UsersManager.userExists.xml │ ├── VisitsSummary.getActions.xml │ ├── VisitsSummary.getVisits.xml │ ├── ExampleAPI.getAnswerToLife.xml │ ├── ExampleAPI.getPiwikVersion.xml │ ├── SitesManager.getSitesIdWithViewAccess.xml │ ├── SitesManager.getSitesWithViewAccess.xml │ ├── UsersManager.getUsersAccessFromSite.xml │ ├── UsersManager.getUsersSitesFromAccess.xml │ ├── UsersManager.getUsersWithSiteAccess.xml │ ├── VisitsSummary.getBounceCount.xml │ ├── VisitsSummary.getMaxActions.xml │ ├── LanguagesManager.isLanguageAvailable.xml │ ├── SitesManager.getDefaultCurrency.xml │ ├── SitesManager.getExcludedIpsGlobal.xml │ ├── VisitsSummary.getUniqueVisitors.xml │ ├── VisitsSummary.getVisitsConverted.xml │ ├── Referrers.getNumberOfDistinctCampaigns.xml │ ├── Referrers.getNumberOfDistinctKeywords.xml │ ├── Referrers.getNumberOfDistinctWebsites.xml │ ├── UserCountry.getNumberOfDistinctCountries.xml │ ├── VisitsSummary.getSumVisitsLength.xml │ ├── CustomDimensions.configureNewCustomDimension.xml │ ├── ImageGraph.get.xml │ ├── Referrers.getNumberOfDistinctSearchEngines.xml │ ├── Referrers.getNumberOfDistinctWebsitesUrls.xml │ ├── SitesManager.getDefaultTimezone.xml │ ├── SitesManager.getExcludedQueryParametersGlobal.xml │ ├── SitesManager.getSearchCategoryParametersGlobal.xml │ ├── API.getLogoUrl.xml │ ├── SitesManager.getAllSitesId.xml │ ├── SitesManager.getSitesGroups.xml │ ├── ExampleAPI.getNull.xml │ ├── UsersManager.getUsersLogin.xml │ ├── VisitsSummary.getSumVisitsLengthPretty.xml │ ├── SitesManager.getSitesIdWithAdminAccess.xml │ ├── API.getHeaderLogoUrl.xml │ ├── SitesManager.getSitesIdWithAtLeastViewAccess.xml │ ├── SitesManager.getUniqueSiteTimezones.xml │ ├── SitesManager.getSearchKeywordParametersGlobal.xml │ ├── SitesManager.getSiteUrlsFromId.xml │ ├── CustomDimensions.configureExistingCustomDimension.xml │ ├── UsersManager.getSitesAccessFromUser.xml │ ├── ExampleAPI.getObject.xml │ ├── ExampleAPI.getMoreInformationAnswerToLife.xml │ ├── API.getSettings.xml │ ├── Live.getCounters.xml │ ├── API.getRowEvolution.xml │ ├── Goals.get.xml │ ├── ExampleAPI.getDescriptionArray.xml │ ├── API.getDefaultMetrics.xml │ ├── Referrers.getKeywordsForPageUrl.xml │ ├── Annotations.getAnnotationCountForDates.xml │ ├── Annotations.add.xml │ ├── ExampleAPI.getCompetitionDatatable.xml │ ├── UsersManager.getUsers.xml │ ├── Actions.getOutlink.xml │ ├── API.getDefaultProcessedMetrics.xml │ ├── UsersManager.getUser.xml │ ├── CustomDimensions.getAvailableExtractionDimensions.xml │ ├── Actions.get.xml │ ├── MultiSites.getOne.xml │ ├── ExampleAPI.getMultiArray.xml │ ├── VisitsSummary.get.xml │ ├── SegmentEditor.get.xml │ ├── UserCountry.getLocationFromIP.xml │ ├── Actions.getDownloads.xml │ ├── SitesManager.getSiteFromId.xml │ ├── SitesManager.getSitesWithAtLeastViewAccess.xml │ ├── Events.getCategory.xml │ ├── Events.getCategoryFromActionId.xml │ ├── Events.getCategoryFromNameId.xml │ ├── CustomDimensions.getAvailableScopes.xml │ ├── VisitFrequency.get.xml │ ├── Actions.GetPageUrl.xml │ ├── Annotations.getAll.xml │ ├── SitesManager.getJavascriptTag.xml │ ├── UserSettings.getOS.xml │ ├── SEO.getRank.xml │ ├── VisitorInterest.getNumberOfVisitsPerVisitDuration.xml │ ├── VisitorInterest.getNumberOfVisitsPerPage.xml │ ├── LanguagesManager.getAvailableLanguages.xml │ ├── CustomVariables.getCustomVariables.xml │ ├── PDFReports.getReports.xml │ ├── Events.getAction.xml │ ├── Events.getActionFromNameId.xml │ ├── UserSettings.getResolution.xml │ ├── Events.getActionFromCategoryId.xml │ ├── VisitTime.getByDayOfWeek.xml │ ├── API.get.xml │ ├── Goals.getGoals.xml │ ├── UserSettings.getMobileVsDesktop.xml │ ├── CustomDimensions.getCustomDimension.xml │ ├── Goals.getVisitsUntilConversion.xml │ ├── VisitorInterest.getNumberOfVisitsByDaysSinceLast.xml │ ├── Goals.getDaysToConversion.xml │ ├── UserSettings.getBrowserVersion.xml │ ├── API.getDefaultMetricsDocumentation.xml │ ├── UserSettings.getConfiguration.xml │ ├── UserSettings.getWideScreen.xml │ ├── UserSettings.getBrowser.xml │ ├── SitesManager.getAllSites.xml │ ├── SitesManager.getSitesWithAdminAccess.xml │ ├── UserSettings.getBrowserType.xml │ ├── VisitorInterest.getNumberOfVisitsByVisitCount.xml │ ├── Transitions.getTranslations.xml │ ├── UserSettings.getPlugin.xml │ ├── API.getDefaultMetricTranslations.xml │ ├── Referrers.getReferrerType.xml │ ├── VisitTime.getVisitInformationPerServerTime.xml │ ├── VisitTime.getVisitInformationPerLocalTime.xml │ ├── API.getMetadata.xml │ ├── CustomDimensions.getConfiguredCustomDimensions.xml │ ├── Actions.getOutlinks.xml │ ├── SitesManager.getCurrencySymbols.xml │ ├── Actions.getExitPageTitles.xml │ ├── Actions.getEntryPageTitles.xml │ ├── Actions.getEntryPageUrls.xml │ ├── Actions.getExitPageUrls.xml │ ├── UserSettings.getOSFamily.xml │ ├── Provider.getProvider.xml │ ├── Referrers.getSearchEngines.xml │ ├── UserCountry.getCountry.xml │ ├── Referrers.getKeywords.xml │ ├── Events.getName.xml │ └── Actions.getPageUrls.xml ├── mobile_messaging_spec.rb ├── pdf_reports_spec.rb ├── multi_sites_spec.rb ├── visit_frequency_spec.rb ├── custom_variables_spec.rb ├── provider_spec.rb ├── transitions_spec.rb ├── api_spec.rb ├── live_spec.rb ├── image_graph_spec.rb ├── goals_spec.rb ├── languages_manager_spec.rb ├── seo_spec.rb ├── segment_editor_spec.rb ├── users_manager_spec.rb ├── custom_dimensions_spec.rb ├── visit_time_spec.rb ├── actions_spec.rb ├── events_spec.rb ├── segment_spec.rb ├── sites_manager_spec.rb ├── user_country_spec.rb ├── user_spec.rb ├── visitor_interest_spec.rb ├── user_settings_spec.rb ├── visits_summary_spec.rb ├── referrers_spec.rb ├── spec_helper.rb └── site_spec.rb ├── lib ├── piwik │ ├── version.rb │ ├── api_response.rb │ ├── seo.rb │ ├── image_graph.rb │ ├── provider.rb │ ├── visit_frequency.rb │ ├── multi_sites.rb │ ├── live.rb │ ├── custom_variables.rb │ ├── visit_time.rb │ ├── user.rb │ ├── segment.rb │ ├── pdf_reports.rb │ ├── scheduled_reports.rb │ ├── user_country.rb │ ├── visitor_interest.rb │ ├── devices_detection.rb │ ├── custom_dimensions.rb │ ├── example_api.rb │ ├── languages_manager.rb │ ├── events.rb │ ├── user_settings.rb │ ├── custom_reports.rb │ ├── mobile_messaging.rb │ ├── typecast.rb │ ├── api.rb │ ├── metadata_api.rb │ ├── segment_editor.rb │ ├── transitions.rb │ ├── annotations.rb │ ├── api_scope.rb │ ├── goals.rb │ ├── visits_summary.rb │ ├── users_manager.rb │ ├── actions.rb │ ├── data_methods.rb │ ├── referrers.rb │ ├── sites_manager.rb │ ├── site.rb │ └── api_module.rb ├── string.rb └── piwik.rb ├── .gitignore ├── Gemfile ├── ci ├── Gemfile.as32 ├── Gemfile.as42 ├── Gemfile.as50 └── Gemfile.as51 ├── bin └── piwik-console ├── License.txt ├── autometal-piwik.gemspec ├── .travis.yml └── README.md /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /spec/files/SitesManager.addSite.xml: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /lib/piwik/version.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | VERSION = "1.0.5" 3 | end -------------------------------------------------------------------------------- /spec/files/success.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /spec/files/MultiSites.getAll.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/failure.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /spec/files/Referrers.getCampaigns.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/Referrers.getSocials.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/ExampleAPI.getSum.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 -------------------------------------------------------------------------------- /spec/files/Referrers.getUrlsForSocial.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matomo-org/piwik-ruby-api/HEAD/spec/files/.DS_Store -------------------------------------------------------------------------------- /spec/files/API.getPiwikVersion.xml: -------------------------------------------------------------------------------- 1 | 2 | 1.10.1 -------------------------------------------------------------------------------- /spec/files/SitesManager.getSitesIdFromSiteUrl.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/SitesManager.getSitesIdWithVisits.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/UsersManager.userExists.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 -------------------------------------------------------------------------------- /spec/files/VisitsSummary.getActions.xml: -------------------------------------------------------------------------------- 1 | 2 | 55 -------------------------------------------------------------------------------- /spec/files/VisitsSummary.getVisits.xml: -------------------------------------------------------------------------------- 1 | 2 | 200 -------------------------------------------------------------------------------- /spec/files/ExampleAPI.getAnswerToLife.xml: -------------------------------------------------------------------------------- 1 | 2 | 42 -------------------------------------------------------------------------------- /spec/files/ExampleAPI.getPiwikVersion.xml: -------------------------------------------------------------------------------- 1 | 2 | 1.10.1 -------------------------------------------------------------------------------- /spec/files/SitesManager.getSitesIdWithViewAccess.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/SitesManager.getSitesWithViewAccess.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/UsersManager.getUsersAccessFromSite.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/UsersManager.getUsersSitesFromAccess.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/UsersManager.getUsersWithSiteAccess.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /spec/files/VisitsSummary.getBounceCount.xml: -------------------------------------------------------------------------------- 1 | 2 | 51 -------------------------------------------------------------------------------- /spec/files/VisitsSummary.getMaxActions.xml: -------------------------------------------------------------------------------- 1 | 2 | 66 -------------------------------------------------------------------------------- /spec/files/LanguagesManager.isLanguageAvailable.xml: -------------------------------------------------------------------------------- 1 | 2 | 1 -------------------------------------------------------------------------------- /spec/files/SitesManager.getDefaultCurrency.xml: -------------------------------------------------------------------------------- 1 | 2 | USD -------------------------------------------------------------------------------- /spec/files/SitesManager.getExcludedIpsGlobal.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 -------------------------------------------------------------------------------- /spec/files/VisitsSummary.getUniqueVisitors.xml: -------------------------------------------------------------------------------- 1 | 2 | 100 -------------------------------------------------------------------------------- /spec/files/VisitsSummary.getVisitsConverted.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | pkg/* 2 | nbproject 3 | *.tmproj 4 | .rvmrc 5 | .rspec 6 | .elscripto 7 | Gemfile.lock 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /spec/files/Referrers.getNumberOfDistinctCampaigns.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 -------------------------------------------------------------------------------- /spec/files/Referrers.getNumberOfDistinctKeywords.xml: -------------------------------------------------------------------------------- 1 | 2 | 207 -------------------------------------------------------------------------------- /spec/files/Referrers.getNumberOfDistinctWebsites.xml: -------------------------------------------------------------------------------- 1 | 2 | 27 -------------------------------------------------------------------------------- /spec/files/UserCountry.getNumberOfDistinctCountries.xml: -------------------------------------------------------------------------------- 1 | 2 | 88 -------------------------------------------------------------------------------- /spec/files/VisitsSummary.getSumVisitsLength.xml: -------------------------------------------------------------------------------- 1 | 2 | 143952 -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in autometal-piwik.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /spec/files/CustomDimensions.configureNewCustomDimension.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 -------------------------------------------------------------------------------- /spec/files/ImageGraph.get.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matomo-org/piwik-ruby-api/HEAD/spec/files/ImageGraph.get.xml -------------------------------------------------------------------------------- /spec/files/Referrers.getNumberOfDistinctSearchEngines.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 -------------------------------------------------------------------------------- /spec/files/Referrers.getNumberOfDistinctWebsitesUrls.xml: -------------------------------------------------------------------------------- 1 | 2 | 78 -------------------------------------------------------------------------------- /spec/files/SitesManager.getDefaultTimezone.xml: -------------------------------------------------------------------------------- 1 | 2 | Europe/London -------------------------------------------------------------------------------- /spec/files/SitesManager.getExcludedQueryParametersGlobal.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 -------------------------------------------------------------------------------- /spec/files/SitesManager.getSearchCategoryParametersGlobal.xml: -------------------------------------------------------------------------------- 1 | 2 | 0 -------------------------------------------------------------------------------- /lib/piwik/api_response.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class ApiResponse < Base 3 | include Piwik::DataMethods 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/files/API.getLogoUrl.xml: -------------------------------------------------------------------------------- 1 | 2 | http://demo.piwik.org/themes/logo.png -------------------------------------------------------------------------------- /spec/files/SitesManager.getAllSitesId.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | -------------------------------------------------------------------------------- /spec/files/SitesManager.getSitesGroups.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /lib/piwik/seo.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class SEO < ApiModule 3 | available_methods %W{ 4 | getRank 5 | } 6 | end 7 | end -------------------------------------------------------------------------------- /spec/files/ExampleAPI.getNull.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /spec/files/UsersManager.getUsersLogin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | anonymous 4 | -------------------------------------------------------------------------------- /spec/files/VisitsSummary.getSumVisitsLengthPretty.xml: -------------------------------------------------------------------------------- 1 | 2 | 1 days 15 hours -------------------------------------------------------------------------------- /spec/files/SitesManager.getSitesIdWithAdminAccess.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | -------------------------------------------------------------------------------- /lib/piwik/image_graph.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class ImageGraph < ApiModule 3 | available_methods %W{ 4 | get 5 | } 6 | end 7 | end -------------------------------------------------------------------------------- /spec/files/API.getHeaderLogoUrl.xml: -------------------------------------------------------------------------------- 1 | 2 | http://demo.piwik.org/themes/logo-header.png -------------------------------------------------------------------------------- /spec/files/SitesManager.getSitesIdWithAtLeastViewAccess.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | -------------------------------------------------------------------------------- /lib/piwik/provider.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class Provider < ApiModule 3 | available_methods %W{ 4 | getProvider 5 | } 6 | end 7 | end -------------------------------------------------------------------------------- /spec/files/SitesManager.getUniqueSiteTimezones.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Europe/London 4 | -------------------------------------------------------------------------------- /lib/piwik/visit_frequency.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class VisitFrequency < ApiModule 3 | available_methods %W{ 4 | get 5 | } 6 | end 7 | end -------------------------------------------------------------------------------- /spec/files/SitesManager.getSearchKeywordParametersGlobal.xml: -------------------------------------------------------------------------------- 1 | 2 | q,query,s,search,searchword,k,keyword -------------------------------------------------------------------------------- /spec/files/SitesManager.getSiteUrlsFromId.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | http://humbuckercode.co.uk 4 | -------------------------------------------------------------------------------- /lib/piwik/multi_sites.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class MultiSites < ApiModule 3 | available_methods %W{ 4 | getAll 5 | getOne 6 | } 7 | end 8 | end -------------------------------------------------------------------------------- /spec/files/CustomDimensions.configureExistingCustomDimension.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /spec/files/UsersManager.getSitesAccessFromUser.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /lib/piwik/live.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class Live < ApiModule 3 | available_methods %W{ 4 | getCounters 5 | getLastVisitsDetails 6 | } 7 | end 8 | end -------------------------------------------------------------------------------- /spec/files/ExampleAPI.getObject.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ci/Gemfile.as32: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | gem 'activesupport', '~> 3.2.22' 4 | gem 'mime-types', '~> 2.99.3' 5 | gem 'rest-client', '~> 1.8' 6 | 7 | gemspec path: '../' 8 | -------------------------------------------------------------------------------- /ci/Gemfile.as42: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | gem 'activesupport', '~> 4.2.7' 4 | gem 'mime-types', '~> 2.99.3' 5 | gem 'rest-client', '~> 1.8' 6 | 7 | gemspec path: '../' 8 | -------------------------------------------------------------------------------- /ci/Gemfile.as50: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | gem 'activesupport', '~> 5.0.0' 4 | gem 'mime-types', '~> 2.99.3' 5 | gem 'rest-client', '~> 1.8' 6 | 7 | gemspec path: '../' 8 | -------------------------------------------------------------------------------- /ci/Gemfile.as51: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | gem 'activesupport', '~> 5.1.0' 4 | gem 'mime-types', '~> 2.99.3' 5 | gem 'rest-client', '~> 1.8' 6 | 7 | gemspec path: '../' 8 | -------------------------------------------------------------------------------- /spec/files/ExampleAPI.getMoreInformationAnswerToLife.xml: -------------------------------------------------------------------------------- 1 | 2 | Check http://en.wikipedia.org/wiki/The_Answer_to_Life,_the_Universe,_and_Everything -------------------------------------------------------------------------------- /lib/piwik/custom_variables.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class CustomVariables < ApiModule 3 | available_methods %W{ 4 | getCustomVariables 5 | getCustomVariablesValuesFromNameId 6 | } 7 | end 8 | end -------------------------------------------------------------------------------- /spec/files/API.getSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 5 | 30 6 | 7 | -------------------------------------------------------------------------------- /spec/files/Live.getCounters.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 5 | 44 6 | 1 7 | 8 | -------------------------------------------------------------------------------- /spec/files/API.getRowEvolution.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /lib/piwik/visit_time.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class VisitTime < ApiModule 3 | available_methods %W{ 4 | getVisitInformationPerLocalTime 5 | getVisitInformationPerServerTime 6 | getByDayOfWeek 7 | } 8 | end 9 | end -------------------------------------------------------------------------------- /spec/mobile_messaging_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::MobileMessaging' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | subject { Piwik::MobileMessaging } 8 | 9 | xit { "nothing to see here - yet" } 10 | end -------------------------------------------------------------------------------- /spec/files/Goals.get.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 82 4 | 56 5 | 5,86 6 | 150 7 | -------------------------------------------------------------------------------- /lib/piwik/user.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class User < Base 3 | class << self 4 | def collection 5 | Piwik::UsersManager 6 | end 7 | 8 | def id_attr 9 | :userLogin 10 | end 11 | end 12 | end 13 | end -------------------------------------------------------------------------------- /spec/files/ExampleAPI.getDescriptionArray.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | piwik 4 | open source 5 | web analytics 6 | free 7 | Strong message: Свободный Тибет 8 | -------------------------------------------------------------------------------- /lib/piwik/segment.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class Segment < Base 3 | class << self 4 | def collection 5 | Piwik::SegmentEditor 6 | end 7 | def id_attr 8 | :idSegment 9 | end 10 | end 11 | 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/files/API.getDefaultMetrics.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Besuche 5 | Eindeutige Besucher 6 | Aktionen 7 | 8 | -------------------------------------------------------------------------------- /lib/string.rb: -------------------------------------------------------------------------------- 1 | class String 2 | def is_binary_data? 3 | self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) 4 | end 5 | 6 | if RUBY_VERSION.to_f < 1.9 7 | def force_encoding(enc) 8 | self 9 | end 10 | end 11 | end -------------------------------------------------------------------------------- /lib/piwik/pdf_reports.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class PdfReports < ApiModule 3 | available_methods %W{ 4 | addReport 5 | updateReport 6 | deleteReport 7 | getReports 8 | generateReport 9 | sendReport 10 | } 11 | end 12 | end -------------------------------------------------------------------------------- /lib/piwik/scheduled_reports.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class ScheduledReports < ApiModule 3 | available_methods %W{ 4 | addReport 5 | updateReport 6 | deleteReport 7 | getReports 8 | generateReport 9 | sendReport 10 | } 11 | end 12 | end -------------------------------------------------------------------------------- /lib/piwik/user_country.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class UserCountry < ApiModule 3 | available_methods %W{ 4 | getCountry 5 | getContinent 6 | getRegion 7 | getCity 8 | getLocationFromIP 9 | getNumberOfDistinctCountries 10 | } 11 | end 12 | end -------------------------------------------------------------------------------- /spec/files/Referrers.getKeywordsForPageUrl.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | piwik forum 4 | "powered by phorum" inurl:forum 5 | forum piwik 6 | piwik forums 7 | piwik custome report 8 | -------------------------------------------------------------------------------- /spec/files/Annotations.getAnnotationCountForDates.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 2013-01-02 6 | 7 | 3 8 | 0 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /spec/files/Annotations.add.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | yesterday 5 | test 6 | 0 7 | admin 8 | 0 9 | 1 10 | 11 | -------------------------------------------------------------------------------- /lib/piwik/visitor_interest.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class VisitorInterest < ApiModule 3 | available_methods %W{ 4 | getNumberOfVisitsPerVisitDuration 5 | getNumberOfVisitsPerPage 6 | getNumberOfVisitsByDaysSinceLast 7 | getNumberOfVisitsByVisitCount 8 | } 9 | end 10 | end -------------------------------------------------------------------------------- /spec/pdf_reports_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::PdfReports' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::PdfReports } 9 | 10 | assert_data_integrity(:getReports) 11 | end -------------------------------------------------------------------------------- /spec/files/ExampleAPI.getCompetitionDatatable.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | piwik 5 | GPL 6 | logo.png 7 | 8 | 9 | google analytics 10 | commercial 11 | 12 | -------------------------------------------------------------------------------- /spec/multi_sites_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::MultiSites' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::MultiSites } 9 | 10 | assert_data_integrity(:get_one, :size => 8) 11 | end -------------------------------------------------------------------------------- /spec/visit_frequency_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::VisitFrequency' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::VisitFrequency } 9 | 10 | assert_data_integrity(:get, :size => 10) 11 | end -------------------------------------------------------------------------------- /spec/custom_variables_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::CustomVariables' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::CustomVariables } 9 | 10 | assert_data_integrity(:get_custom_variables) 11 | end -------------------------------------------------------------------------------- /lib/piwik/devices_detection.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class DevicesDetection < ApiModule 3 | available_methods %W{ 4 | getType 5 | getBrand 6 | getModel 7 | getOsFamilies 8 | getOsVersions 9 | getBrowsers 10 | getBrowserVersions 11 | getBrowserEngines 12 | } 13 | end 14 | end 15 | 16 | -------------------------------------------------------------------------------- /spec/files/UsersManager.getUsers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | anonymous 5 | 6 | anonymous 7 | anonymous@example.org 8 | anonymous 9 | 2013-01-02 13:56:27 10 | 11 | -------------------------------------------------------------------------------- /spec/provider_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::Provider' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::Provider } 10 | 11 | assert_data_integrity(:get_provider, :size => 10) 12 | end -------------------------------------------------------------------------------- /spec/files/Actions.getOutlink.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 5 | 6 6 | 6 7 | 124 8 | 5 9 | 5 10 | http://piwik.org/ 11 | 12 | -------------------------------------------------------------------------------- /lib/piwik/custom_dimensions.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class CustomDimensions < ApiModule 3 | available_methods %W{ 4 | getCustomDimension 5 | configureNewCustomDimension 6 | configureExistingCustomDimension 7 | getConfiguredCustomDimensions 8 | getAvailableScopes 9 | getAvailableExtractionDimensions 10 | } 11 | end 12 | end -------------------------------------------------------------------------------- /lib/piwik/example_api.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class ExampleApi < ApiModule 3 | available_methods %W{ 4 | getPiwikVersion 5 | getAnswerToLife 6 | getObject 7 | getSum 8 | getNull 9 | getDescriptionArray 10 | getCompetitionDatatable 11 | getMoreInformationAnswerToLife 12 | getMultiArray 13 | } 14 | end 15 | end -------------------------------------------------------------------------------- /lib/piwik/languages_manager.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class LanguagesManager < ApiModule 3 | available_methods %W{ 4 | isLanguageAvailable 5 | getAvailableLanguages 6 | getAvailableLanguagesInfo 7 | getAvailableLanguageNames 8 | getTranslationsForLanguage 9 | getLanguageForUser 10 | setLanguageForUser 11 | } 12 | end 13 | end -------------------------------------------------------------------------------- /lib/piwik/events.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class Events < ApiModule 3 | available_methods %W{ 4 | getCategory 5 | getAction 6 | getName 7 | getActionFromCategoryId 8 | getNameFromCategoryId 9 | getCategoryFromActionId 10 | getNameFromActionId 11 | getActionFromNameId 12 | getCategoryFromNameId 13 | } 14 | end 15 | end -------------------------------------------------------------------------------- /lib/piwik/user_settings.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class UserSettings < ApiModule 3 | available_methods %W{ 4 | getResolution 5 | getConfiguration 6 | getOS 7 | getOSFamily 8 | getMobileVsDesktop 9 | getBrowserVersion 10 | getBrowser 11 | getBrowserType 12 | getWideScreen 13 | getPlugin 14 | } 15 | end 16 | end -------------------------------------------------------------------------------- /spec/files/API.getDefaultProcessedMetrics.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Aktionen pro Besuch 5 | Durchschnittszeit auf der Webseite 6 | Absprungsrate 7 | Konversionsrate 8 | 9 | -------------------------------------------------------------------------------- /spec/files/UsersManager.getUser.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | test_user 4 | 4cb9c8a8048fd02294477fcb1a41191a 5 | test_user 6 | user@test.local 7 | 07bf7e82aa205c84c6aa308431f53c56 8 | 2013-01-03 16:02:57 9 | 10 | -------------------------------------------------------------------------------- /spec/transitions_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::Transitions' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::Transitions } 9 | 10 | describe "#get_translations" do 11 | assert_data_integrity(:get_translations, :size => 32) 12 | end 13 | end -------------------------------------------------------------------------------- /spec/api_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::API' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::API } 9 | 10 | assert_value_integrity(:get_piwik_version, :value => '1.10.1') 11 | assert_value_integrity(:get_logo_url, :value => 'http://demo.piwik.org/themes/logo.png') 12 | end -------------------------------------------------------------------------------- /spec/files/CustomDimensions.getAvailableExtractionDimensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | url 5 | Site URL 6 | 7 | 8 | urlparam 9 | Page URL Parameter 10 | 11 | 12 | action_name 13 | Site Title 14 | 15 | -------------------------------------------------------------------------------- /spec/live_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::Live' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::Live } 10 | 11 | assert_data_integrity(:get_counters, :size => 3) 12 | assert_data_integrity(:get_last_visits_details, :size => 8) 13 | end -------------------------------------------------------------------------------- /spec/files/Actions.get.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2270 4 | 1730 5 | 3 6 | 3 7 | 100 8 | 93 9 | 0 10 | 0 11 | -------------------------------------------------------------------------------- /spec/files/MultiSites.getOne.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0% 8 | 0% 9 | 0% 10 | 0% 11 | -------------------------------------------------------------------------------- /spec/image_graph_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::ImageGraph' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday', :apiModule => 'UserCountry', :apiAction => 'getCountry'} } 9 | subject { Piwik::ImageGraph } 10 | 11 | assert_value_integrity(:get) # for array responses 12 | end -------------------------------------------------------------------------------- /lib/piwik/custom_reports.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class CustomReports < ApiModule 3 | available_methods %W{ 4 | addCustomReport 5 | updateCustomReport 6 | getConfiguredReports 7 | getConfiguredReport 8 | deleteCustomReport 9 | getAvailableCategories 10 | getAvailableReportTypes 11 | getAvailableDimensions 12 | getAvailableMetrics 13 | getCustomReport 14 | } 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/piwik/mobile_messaging.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class MobileMessaging < ApiModule 3 | available_methods %W{ 4 | areSMSAPICredentialProvided 5 | getSMSProvider 6 | setSMSAPICredential 7 | addPhoneNumber 8 | getCreditLeft 9 | removePhoneNumber 10 | validatePhoneNumber 11 | deleteSMSAPICredential 12 | setDelegatedManagement 13 | getDelegatedManagement 14 | } 15 | end 16 | end -------------------------------------------------------------------------------- /spec/goals_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::Goals' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::Goals } 10 | 11 | assert_data_integrity(:get, :size => 4) 12 | assert_data_integrity(:get_goals, :size => 3) 13 | assert_data_integrity(:get_visits_until_conversion, :size => 13) 14 | end -------------------------------------------------------------------------------- /spec/languages_manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::LanguagesManager' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { { :languageCode => 'en' } } 8 | subject { Piwik::LanguagesManager } 9 | 10 | assert_data_integrity(:get_available_language_names, :size => 46) 11 | assert_data_integrity(:get_available_languages, :size => 46) 12 | assert_value_integrity(:is_language_available, :value => 1) 13 | end -------------------------------------------------------------------------------- /spec/seo_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::SEO' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:url => 'http://site.test'} } 8 | subject { Piwik::SEO } 9 | 10 | describe "#get_rank" do 11 | assert_data_integrity(:get_rank, :size => 5) 12 | it { subject.get_rank(params).data.first['label'].should eq('Google PageRank') } 13 | it { subject.get_rank(params).data.first['rank'].should eq('7') } 14 | end 15 | end -------------------------------------------------------------------------------- /spec/segment_editor_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::SegmentEditor' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::SegmentEditor } 9 | 10 | describe "#get" do 11 | it { subject.get(params).should be_a Piwik::Segment } 12 | end 13 | 14 | it "#getAll" 15 | it "#add" 16 | it "#update" 17 | it "#delete" 18 | it "#isUserCanAddNewSegment" 19 | end 20 | -------------------------------------------------------------------------------- /lib/piwik/typecast.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | # used to do basic typecasting to API response values 3 | module Typecast 4 | def self.included(base) 5 | base.send(:include, InstanceMethods) 6 | end 7 | 8 | module InstanceMethods 9 | private 10 | def typecast(thing) 11 | if thing.is_a?(String) and thing =~ /^[0-9]+$/ 12 | thing.to_i 13 | else 14 | thing 15 | end 16 | end 17 | end 18 | end 19 | end -------------------------------------------------------------------------------- /spec/files/ExampleAPI.getMultiArray.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Multi dimensional arrays is only supported by format=JSON 5 | Known limitation 6 | 7 | 8 | 9 | 1 10 | 0 11 | 1 12 | 0 13 | 152 14 | test 15 | 16 | end 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /spec/files/VisitsSummary.get.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 914 4 | 995 5 | 2161 6 | 44 7 | 704 8 | 143952 9 | 47 10 | 71% 11 | 2.2 12 | 145 13 | -------------------------------------------------------------------------------- /spec/files/SegmentEditor.get.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 4 | Custom Segment Five 5 | referrerType==website 6 | john.doe 7 | 0 8 | 1 9 | 0 10 | 2020-06-17 18:16:26 11 | 2020-06-18 19:08:26 12 | 0 13 | 14 | 15 | -------------------------------------------------------------------------------- /lib/piwik/api.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class API < ApiModule 3 | available_methods %W{ 4 | getPiwikVersion 5 | getSettings 6 | getDefaultMetricTranslations 7 | getDefaultMetrics 8 | getDefaultProcessedMetrics 9 | getDefaultMetricsDocumentation 10 | getSegmentsMetadata 11 | getLogoUrl 12 | getHeaderLogoUrl 13 | getMetadata 14 | getReportMetadata 15 | getProcessedReport 16 | get 17 | getRowEvolution 18 | getBulkRequest 19 | } 20 | end 21 | end -------------------------------------------------------------------------------- /lib/piwik/metadata_api.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class API < ApiModule 3 | available_methods %W{ 4 | getPiwikVersion 5 | getSettings 6 | getDefaultMetricTranslations 7 | getDefaultMetrics 8 | getDefaultProcessedMetrics 9 | getDefaultMetricsDocumentation 10 | getSegmentsMetadata 11 | getLogoUrl 12 | getHeaderLogoUrl 13 | getMetadata 14 | getReportMetadata 15 | getProcessedReport 16 | get 17 | getRowEvolution 18 | getBulkRequest 19 | } 20 | end 21 | end -------------------------------------------------------------------------------- /spec/files/UserCountry.getLocationFromIP.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | FR 5 | A6 6 | Besançon 7 | 8 | 47.249 9 | 6.018 10 | 11 | eur 12 | Europe 13 | France 14 | Franche-Comte 15 | 194.57.91.215 16 | 17 | -------------------------------------------------------------------------------- /spec/files/Actions.getDownloads.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 2 6 | 2 7 | 26 8 | 1 9 | 68 10 | 11 | 12 | 13 | 1 14 | 1 15 | 0 16 | 1 17 | 70 18 | 19 | -------------------------------------------------------------------------------- /spec/files/SitesManager.getSiteFromId.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 65 5 | Test Site 6 | http://test.local 7 | 2013-01-03 16:17:00 8 | 0 9 | 1 10 | 11 | 12 | Europe/London 13 | USD 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /spec/files/SitesManager.getSitesWithAtLeastViewAccess.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1 5 | Humbucker 6 | http://humbuckercode.co.uk 7 | 2013-01-02 13:57:20 8 | 0 9 | 1 10 | 11 | 12 | Europe/London 13 | USD 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /spec/files/Events.getCategory.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 101 6 | 298 7 | 0 8 | 0 9 | 0 10 | 0 11 | 101 12 | 0 13 | eventCategory==Event 14 | 1 15 | 16 | -------------------------------------------------------------------------------- /spec/files/Events.getCategoryFromActionId.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 101 6 | 298 7 | 0 8 | 0 9 | 0 10 | 0 11 | 101 12 | 0 13 | eventCategory==Event 14 | 1 15 | 16 | -------------------------------------------------------------------------------- /spec/files/Events.getCategoryFromNameId.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 101 6 | 298 7 | 0 8 | 0 9 | 0 10 | 0 11 | 101 12 | 0 13 | eventCategory==Event 14 | 1 15 | 16 | -------------------------------------------------------------------------------- /spec/files/CustomDimensions.getAvailableScopes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | visit 5 | Visit 6 | 5 7 | 4 8 | 1 9 | 0 10 | 11 | 12 | action 13 | Action 14 | 5 15 | 4 16 | 1 17 | 1 18 | 19 | -------------------------------------------------------------------------------- /spec/files/VisitFrequency.get.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0 8 | 0 9 | 0 10 | 0% 11 | 0 12 | 0 13 | -------------------------------------------------------------------------------- /spec/users_manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::UsersManager' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::UsersManager } 10 | 11 | describe "#get" do 12 | it { subject.get(params).should be_a(Piwik::User) } 13 | end 14 | 15 | describe "#get_users" do 16 | assert_data_integrity(:get_users) 17 | end 18 | 19 | describe "#get_users_login" do 20 | assert_data_integrity(:get_users) 21 | end 22 | 23 | describe "#user_exists" do 24 | assert_value_integrity(:user_exists, :value => 0) 25 | end 26 | end -------------------------------------------------------------------------------- /spec/custom_dimensions_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::CustomDimensions' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::CustomDimensions } 9 | 10 | assert_data_integrity(:get_custom_dimension, :size => 2) 11 | assert_data_integrity(:configure_new_custom_dimension, :size => 0) 12 | assert_data_integrity(:configure_existing_custom_dimension, :size => 1) 13 | assert_data_integrity(:get_configured_custom_dimensions, :size => 8) 14 | assert_data_integrity(:get_available_scopes, :size => 2) 15 | assert_data_integrity(:get_available_extraction_dimensions, :size => 3) 16 | end -------------------------------------------------------------------------------- /spec/visit_time_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::VisitTime' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::VisitTime } 10 | 11 | describe "#get_visit_information_per_local_time" do 12 | assert_data_integrity(:get_visit_information_per_local_time, :size => 8) 13 | end 14 | 15 | describe "#get_visit_information_per_server_time" do 16 | assert_data_integrity(:get_visit_information_per_server_time, :size => 5) 17 | end 18 | 19 | describe "#get_by_day_of_week" do 20 | assert_data_integrity(:get_by_day_of_week, :size => 7) 21 | end 22 | end -------------------------------------------------------------------------------- /spec/actions_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::Actions' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::Actions } 10 | 11 | assert_data_integrity(:get, :size => 8) 12 | assert_data_integrity(:getDownloads, :size => 2) 13 | assert_data_integrity(:getPageTitles, :size => 8) 14 | assert_data_integrity(:getPageUrls, :size => 7) 15 | assert_data_integrity(:getEntryPageTitles, :size => 5) 16 | assert_data_integrity(:getEntryPageUrls, :size => 5) 17 | assert_data_integrity(:getExitPageTitles, :size => 5) 18 | assert_data_integrity(:getExitPageUrls, :size => 5) 19 | end -------------------------------------------------------------------------------- /spec/files/Actions.GetPageUrl.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 48 5 | 30 6 | 80 7 | 14203 8 | 7 9 | 22 10 | 63 11 | 15123 12 | 8 13 | 11 14 | 27 15 | 296 16 | 36% 17 | 56% 18 | http://forum.piwik.org/index.html 19 | 20 | -------------------------------------------------------------------------------- /spec/files/Annotations.getAll.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | today 6 | another test 7 | 0 8 | admin 9 | 2 10 | 1 11 | 12 | 13 | 14 | yesterday 15 | test 16 | 0 17 | admin 18 | 0 19 | 1 20 | 21 | 22 | 23 | yesterday 24 | another test 25 | 0 26 | admin 27 | 1 28 | 1 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /spec/events_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::Events' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::Events } 9 | 10 | assert_data_integrity(:get_category, :size => 11) 11 | assert_data_integrity(:get_action, :size => 2) 12 | assert_data_integrity(:get_name, :size => 10) 13 | assert_data_integrity(:get_action_from_category_id, :size => 2) 14 | assert_data_integrity(:get_name_from_category_id, :size => 10) 15 | assert_data_integrity(:get_category_from_action_id, :size => 11) 16 | assert_data_integrity(:get_name_from_action_id, :size => 10) 17 | assert_data_integrity(:get_action_from_name_id, :size => 2) 18 | assert_data_integrity(:get_category_from_name_id, :size => 11) 19 | end -------------------------------------------------------------------------------- /lib/piwik/segment_editor.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class SegmentEditor < ApiModule 3 | available_methods %W{ 4 | get 5 | getAll 6 | add 7 | update 8 | delete 9 | isUserCanAddNewSegment 10 | } 11 | 12 | def self.get params 13 | response = self.api_call('get', params) 14 | raise Piwik::UnknownSegment if response.== '0' 15 | Piwik::Segment.new response 16 | end 17 | 18 | def self.add params 19 | segment = Piwik::Segment.new(params) 20 | response = self.api_call('add', params) 21 | segment.attributes.idSegment = response 22 | segment 23 | end 24 | 25 | def self.save params 26 | self.api_call('update',params) 27 | end 28 | 29 | def self.delete params 30 | self.api_call('delete', params) 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/piwik.rb: -------------------------------------------------------------------------------- 1 | $:.unshift(File.dirname(__FILE__)) unless 2 | $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) 3 | 4 | require 'active_support' 5 | require 'active_support/core_ext' 6 | require 'string' 7 | 8 | %W{ 9 | typecast api_scope base data_methods api_module api_response version 10 | seo referrers transitions user_country visit_time visitor_interest visits_summary 11 | user_settings annotations sites_manager users_manager 12 | actions live pdf_reports scheduled_reports image_graph 13 | provider visit_frequency multi_sites mobile_messaging 14 | custom_variables languages_manager goals example_api api 15 | site user events custom_dimensions devices_detection 16 | segment segment_editor custom_reports 17 | }.each { |r| require "piwik/#{r}" } 18 | 19 | module Piwik 20 | end 21 | -------------------------------------------------------------------------------- /spec/segment_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe Piwik::Segment do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | subject { build(:segment) } 8 | 9 | its(:idsegment) { should eq 5 } 10 | its(:name) { should eq 'Custom Segment Five' } 11 | its(:definition) { should eq 'referrerType==website' } 12 | its(:login) { should eq 'john.doe' } 13 | its(:enable_all_users) { should eq 0 } 14 | its(:enable_only_idsite) { should eq 1 } 15 | its(:auto_archive) { should eq 0 } 16 | its(:ts_created) { should eq '2020-06-17 18:16:26' } 17 | its(:ts_last_edit) { should eq '2020-06-18 19:08:26' } 18 | its(:deleted) { should eq 0 } 19 | 20 | it { 21 | subject.save.should eq true 22 | subject.definition = 'referrerType=search' 23 | subject.update.should eq true 24 | subject.destroy.should eq true 25 | } 26 | end 27 | -------------------------------------------------------------------------------- /spec/sites_manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::SitesManager' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::SitesManager } 10 | 11 | describe "#get" do 12 | it { subject.get(params).should be_a(Piwik::Site) } 13 | end 14 | 15 | describe "#get_sites_with_admin_access" do 16 | assert_data_integrity(:get_sites_with_admin_access, :size => 4) 17 | end 18 | 19 | describe "#get_all_sites" do 20 | assert_data_integrity(:get_all_sites, :size => 4) 21 | end 22 | 23 | describe "#get_unique_site_timezones" do 24 | assert_value_integrity(:get_unique_site_timezones) 25 | end 26 | 27 | describe "#get_javascript_tag" do 28 | assert_value_integrity(:get_javascript_tag) 29 | end 30 | end -------------------------------------------------------------------------------- /lib/piwik/transitions.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class Transitions < ApiModule 3 | available_methods %W{ 4 | getTransitionsForPageTitle 5 | getTransitionsForPageUrl 6 | getTransitionsForAction 7 | getTranslations 8 | } 9 | 10 | scoped_methods do 11 | def for_title title, params = {} 12 | getTransitionsForPageTitle(defaults.merge(params).merge(:pageTitle => title)) 13 | end 14 | 15 | def for_url url, params = {} 16 | getTransitionsForPageUrl(defaults.merge(params).merge(:pageUrl => url)) 17 | end 18 | 19 | def for_action name, type, params = {} 20 | getTransitionsForAction(defaults.merge(params).merge(:actionName => name, :actionType => type, :parts => 'all', :returnNormalizedUrls => '')) 21 | end 22 | 23 | def translations 24 | getTranslations 25 | end 26 | end 27 | end 28 | end -------------------------------------------------------------------------------- /bin/piwik-console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # Example usage: ./script/terminal -u http://demo.piwik.org -t anonymous 3 | require 'optparse' 4 | options = {} 5 | OptionParser.new do |opts| 6 | opts.on("-u", "--url [URL]", "Piwik URL") do |url| 7 | options[:piwik_url] = url 8 | end 9 | 10 | opts.on("-t", "--token [TOKEN]", "Piwik Auth Token") do |token| 11 | options[:token_auth] = token 12 | end 13 | 14 | end.parse! 15 | 16 | unless options.empty? 17 | code = %{ 18 | IRB.conf[:AT_EXIT].push proc { exec("rm -f .piwik.rc.rb") } 19 | Piwik::PIWIK_URL = '#{options[:piwik_url]}' 20 | Piwik::PIWIK_TOKEN = '#{options[:token_auth]}' 21 | include Piwik 22 | } 23 | 24 | File.open('./.piwik.rc.rb','w') { |f| f.puts(code) } 25 | 26 | end 27 | 28 | libs = '-rubygems' 29 | libs << ' -r irb/completion' 30 | libs << ' -r piwik' 31 | libs << ' -r ./.piwik.rc.rb' if File.exists?('./.piwik.rc.rb') 32 | exec "irb #{libs}" -------------------------------------------------------------------------------- /spec/files/SitesManager.getJavascriptTag.xml: -------------------------------------------------------------------------------- 1 | 2 | <!-- Piwik --> 3 | <script type="text/javascript"> 4 | var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.local/" : "http://piwik.local/"); 5 | document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E")); 6 | </script><script type="text/javascript"> 7 | try { 8 | var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1); 9 | piwikTracker.trackPageView(); 10 | piwikTracker.enableLinkTracking(); 11 | } catch( err ) {} 12 | </script><noscript><p><img src="http://piwik.local/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript> 13 | <!-- End Piwik Tracking Code --> 14 | -------------------------------------------------------------------------------- /spec/user_country_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::UserCountry' do 3 | before { 4 | stub_api_calls 5 | } 6 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 7 | subject { Piwik::UserCountry } 8 | 9 | describe '#get_country' do 10 | assert_data_integrity(:get_country) 11 | end 12 | 13 | describe '#get_continent' do 14 | assert_data_integrity(:get_continent) 15 | end 16 | 17 | describe '#get_region' do 18 | assert_data_integrity(:get_region) 19 | end 20 | 21 | describe '#get_city' do 22 | assert_data_integrity(:get_city) 23 | end 24 | 25 | describe '#get_number_of_distinct_countries' do 26 | assert_value_integrity(:get_number_of_distinct_countries) 27 | end 28 | 29 | describe "#get_location_from_ip" do 30 | let(:params) { { :ip => '194.57.91.215' } } 31 | assert_data_integrity(:get_location_from_ip, :size => 12) 32 | end 33 | end -------------------------------------------------------------------------------- /spec/files/UserSettings.getOS.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 437 6 | 480 7 | 1004 8 | 47 9 | 74083 10 | 338 11 | 17 12 | plugins/UserSettings/images/os/WI7.gif 13 | Win 7 14 | 15 | 16 | 17 | 139 18 | 152 19 | 294 20 | 31 21 | 21920 22 | 106 23 | 2 24 | plugins/UserSettings/images/os/MAC.gif 25 | Mac OS 26 | 27 | -------------------------------------------------------------------------------- /spec/files/SEO.getRank.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 6 | plugins/Referers/images/searchEngines/google.com.png 7 | pagerank 8 | 9 | 10 | 11 | 22400 12 | plugins/Referers/images/searchEngines/google.com.png 13 | google-index 14 | 15 | 16 | 17 | 9820 18 | plugins/Referers/images/searchEngines/bing.com.png 19 | bing-index 20 | 21 | 22 | 23 | 6422 24 | plugins/Referers/images/searchEngines/alexa.com.png 25 | alexa 26 | 27 | 28 | 29 | 5 years 169 days 30 | plugins/SEO/images/whois.png 31 | domain-age 32 | 33 | -------------------------------------------------------------------------------- /spec/files/VisitorInterest.getNumberOfVisitsPerVisitDuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 735 6 | 7 | 8 | 9 | 32 10 | 11 | 12 | 13 | 34 14 | 15 | 16 | 17 | 37 18 | 19 | 20 | 21 | 36 22 | 23 | 24 | 25 | 33 26 | 27 | 28 | 29 | 12 30 | 31 | 32 | 33 | 17 34 | 35 | 36 | 37 | 40 38 | 39 | 40 | 41 | 19 42 | 43 | -------------------------------------------------------------------------------- /spec/files/VisitorInterest.getNumberOfVisitsPerPage.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 704 6 | 7 | 8 | 9 | 131 10 | 11 | 12 | 13 | 58 14 | 15 | 16 | 17 | 21 18 | 19 | 20 | 21 | 14 22 | 23 | 24 | 25 | 20 26 | 27 | 28 | 29 | 14 30 | 31 | 32 | 33 | 13 34 | 35 | 36 | 37 | 9 38 | 39 | 40 | 41 | 11 42 | 43 | -------------------------------------------------------------------------------- /spec/files/LanguagesManager.getAvailableLanguages.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | am 4 | ar 5 | be 6 | bg 7 | ca 8 | cs 9 | da 10 | de 11 | el 12 | en 13 | es 14 | et 15 | eu 16 | fa 17 | fi 18 | fr 19 | gl 20 | he 21 | hu 22 | id 23 | is 24 | it 25 | ja 26 | ka 27 | ko 28 | lt 29 | lv 30 | nb 31 | nl 32 | nn 33 | pl 34 | pt-br 35 | pt 36 | ro 37 | ru 38 | sk 39 | sl 40 | sq 41 | sr 42 | sv 43 | te 44 | th 45 | tr 46 | uk 47 | zh-cn 48 | zh-tw 49 | -------------------------------------------------------------------------------- /spec/user_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::User' do 3 | before do 4 | stub_api_calls 5 | # add a few specific stubs 6 | Piwik::Base.stub(:call).with('UsersManager.getUser',{:userLogin => 'mike_ness'},/.*/,/.*/) { raise Piwik::ApiError, 'mock api error' } 7 | end 8 | 9 | 10 | subject { build(:user) } 11 | 12 | its(:login) { should eq('test_user') } 13 | its(:password) { should eq('changeme') } 14 | its(:email) { should eq('user@test.local') } 15 | its(:user_alias) { should eq('Test User') } 16 | 17 | it { 18 | subject.save.should eq(true) 19 | subject.email = 'user2@test.local' 20 | subject.update.should eq(true) 21 | subject.destroy.should eq(true) 22 | } 23 | 24 | it { expect {Piwik::User.load('mike_ness')}.to raise_error(Piwik::ApiError) } 25 | describe "#load existing" do 26 | before { 27 | @user = build(:user) 28 | @user.save 29 | } 30 | it { expect {Piwik::User.load(@user.login)}.to_not raise_error } 31 | end 32 | end -------------------------------------------------------------------------------- /spec/files/CustomVariables.getCustomVariables.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 857 6 | 955 7 | 2375 8 | 102 9 | 143407 10 | 648 11 | 12 | 13 | 34 14 | 34 15 | 102 16 | 17 | 18 | 44 19 | 44 20 | 44 21 | 22 | 23 | 4 24 | 4 25 | 4 26 | 27 | 28 | 82 29 | 150 30 | 358 31 | 32 | -------------------------------------------------------------------------------- /spec/files/PDFReports.getReports.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1 5 | 1 6 | admin 7 | test 8 | day 9 | email 10 | pdf 11 | 12 | MultiSites_getAll 13 | 14 | 15 | 1 16 | 1 17 | 0 18 | 19 | 2012-12-26 10:10:15 20 | 2013-01-25 15:35:37 21 | 0 22 | Humbucker 23 | http://humbuckercode.co.uk 24 | 1 25 | 1 26 | 27 | 28 | Europe/London 29 | USD 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /spec/files/Events.getAction.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 56 6 | 77 7 | 0 8 | 0 9 | 0 10 | 0 11 | 56 12 | 0 13 | eventAction==Action1 14 | 2 15 | 16 | 17 | 18 | 45 19 | 221 20 | 0 21 | 0 22 | 0 23 | 0 24 | 45 25 | 0 26 | eventAction==Action2 27 | 1 28 | 29 | -------------------------------------------------------------------------------- /lib/piwik/annotations.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class Annotations < ApiModule 3 | available_methods %W{ 4 | get 5 | add 6 | save 7 | delete 8 | getAll 9 | getAnnotationCountForDates 10 | } 11 | 12 | scoped_methods do 13 | def load note_id 14 | get(defaults.merge(:idNote => note_id)) 15 | end 16 | 17 | def all params = {} 18 | getAll(defaults.merge(params)) 19 | end 20 | 21 | # params: ( date, note, starred = '0') 22 | def add params = {} 23 | super(defaults.merge(params)) 24 | end 25 | 26 | # params: (date = '', note = '', starred = '') 27 | def update note_id, params = {} 28 | save(defaults.merge(params).merge(:idNote => note_id)) 29 | end 30 | 31 | def delete note_id 32 | super(defaults.merge(:idNote => note_id)) 33 | end 34 | 35 | # params: (date, period, lastN = '', getAnnotationText = '') 36 | def count_for_dates params = {} 37 | getAnnotationCountForDates(defaults.merge(params)) 38 | end 39 | end 40 | end 41 | end -------------------------------------------------------------------------------- /spec/files/Events.getActionFromNameId.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 56 6 | 77 7 | 0 8 | 0 9 | 0 10 | 0 11 | 56 12 | 0 13 | eventAction==Action1 14 | 2 15 | 16 | 17 | 18 | 45 19 | 221 20 | 0 21 | 0 22 | 0 23 | 0 24 | 45 25 | 0 26 | eventAction==Action2 27 | 1 28 | 29 | -------------------------------------------------------------------------------- /spec/files/UserSettings.getResolution.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 178 6 | 191 7 | 381 8 | 31 9 | 21610 10 | 133 11 | 2 12 | 13 | 14 | 15 | 142 16 | 158 17 | 322 18 | 30 19 | 25686 20 | 115 21 | 13 22 | 23 | 24 | 25 | 97 26 | 105 27 | 185 28 | 15 29 | 12463 30 | 75 31 | 1 32 | 33 | -------------------------------------------------------------------------------- /spec/files/Events.getActionFromCategoryId.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 56 6 | 77 7 | 0 8 | 0 9 | 0 10 | 0 11 | 56 12 | 0 13 | eventAction==Action1 14 | 2 15 | 16 | 17 | 18 | 45 19 | 221 20 | 0 21 | 0 22 | 0 23 | 0 24 | 45 25 | 0 26 | eventAction==Action2 27 | 1 28 | 29 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Achilles Charmpilas 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /spec/files/VisitTime.getByDayOfWeek.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 0 6 | 1 7 | 8 | 9 | 10 | 0 11 | 2 12 | 13 | 14 | 15 | 0 16 | 3 17 | 18 | 19 | 20 | 995 21 | 704 22 | 2161 23 | 914 24 | 44 25 | 143952 26 | 4 27 | 28 | 29 | 30 | 0 31 | 5 32 | 33 | 34 | 35 | 0 36 | 6 37 | 38 | 39 | 40 | 0 41 | 7 42 | 43 | -------------------------------------------------------------------------------- /autometal-piwik.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'piwik/version' 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "autometal-piwik" 8 | s.version = Piwik::VERSION 9 | s.authors = ["Achilles Charmpilas"] 10 | s.email = ["ac@humbuckercode.co.uk"] 11 | s.description = %q{A complete Ruby client for the Piwik API} 12 | s.summary = %q{A complete Ruby client for the Piwik API} 13 | s.homepage = "http://humbuckercode.co.uk/licks/gems/piwik/" 14 | s.license = 'MIT' 15 | s.files = `git ls-files`.split($/) 16 | s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 17 | s.test_files = s.files.grep(%r{^(test|spec|features)/}) 18 | s.require_paths = ["lib"] 19 | 20 | s.add_dependency('xml-simple') 21 | s.add_dependency('rest-client') 22 | s.add_dependency('activesupport', '>= 3.0', '< 9') 23 | s.add_development_dependency('rspec', '< 4.0') 24 | s.add_development_dependency('rspec-mocks', '< 4.0') 25 | s.add_development_dependency('rspec-its', '< 4.0') 26 | end 27 | -------------------------------------------------------------------------------- /lib/piwik/api_scope.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | # Used to extend a wrapper class with class-aware api calls, allowing users to use a more DRY api interface. 3 | # Example: 4 | # 5 | # site = Piwik::Site.load(7) 6 | # p = site.actions # returns an extended version of the Piwik::Actions api module 7 | # => Piwik::Actions 8 | # p.outlinks # equivalent to Piwik::Actions.getOutlinks(:idSite => 7) 9 | # => # 10 | module ApiScope 11 | def self.included(base) 12 | base.extend ClassMethods 13 | end 14 | 15 | module ClassMethods 16 | def api_scope name, scope_options = {}, &block 17 | name = name.to_sym 18 | class_name = "Piwik::#{scope_options[:class_name] ? scope_options[:class_name] : name.to_s.camelize}" 19 | extension = Module.new(&Proc.new) if block_given? 20 | instance_eval do 21 | define_method name do 22 | klass = class_name.constantize 23 | klass.extend(extension) if block_given? 24 | klass.instance_variable_set(:@obj, self) 25 | klass 26 | end 27 | end 28 | self 29 | end 30 | end 31 | end 32 | end -------------------------------------------------------------------------------- /spec/files/API.get.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 854 4 | 955 5 | 2375 6 | 102 7 | 68% 8 | 2,5 9 | 150 10 | 216 11 | 764 12 | 165 13 | 54% 14 | 3,5 15 | 253 16 | 82 17 | 56 18 | 5,86 19 | 150 20 | 2270 21 | 1730 22 | 3 23 | 3 24 | 100 25 | 93 26 | 0 27 | 0 28 | -------------------------------------------------------------------------------- /lib/piwik/goals.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class Goals < ApiModule 3 | available_methods %W{ 4 | getGoals 5 | addGoal 6 | updateGoal 7 | deleteGoal 8 | getItemsSku 9 | getItemsName 10 | getItemsCategory 11 | get 12 | getDaysToConversion 13 | getVisitsUntilConversion 14 | } 15 | 16 | scoped_methods do 17 | def load goal_id, params = {} 18 | get(defaults.merge(params).merge(:idGoal => goal_id)) 19 | end 20 | 21 | def all 22 | getGoals(defaults) 23 | end 24 | 25 | # params: (name, matchAttribute, pattern, patternType, caseSensitive = '', revenue = '', allowMultipleConversionsPerVisit = '') 26 | def add params = {} 27 | addGoal(defaults.merge(params)) 28 | end 29 | 30 | # params: (name, matchAttribute, pattern, patternType, caseSensitive = '', revenue = '', allowMultipleConversionsPerVisit = '') 31 | def update goal_id, params = {} 32 | updateGoal(defaults.merge(params).merge(:idGoal => goal_id)) 33 | end 34 | 35 | def delete goal_id 36 | deleteGoal(defaults.merge(:idGoal => goal_id)) 37 | end 38 | end 39 | end 40 | end -------------------------------------------------------------------------------- /spec/visitor_interest_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::VisitorInterest' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::VisitorInterest } 10 | 11 | describe "#get_number_of_visits_per_visit_duration" do 12 | assert_data_integrity(:get_number_of_visits_per_visit_duration) 13 | it { subject.get_number_of_visits_per_visit_duration(params).size.should eq(10) } 14 | end 15 | 16 | describe "#get_number_of_visits_per_page" do 17 | assert_data_integrity(:get_number_of_visits_per_page) 18 | it { subject.get_number_of_visits_per_page(params).size.should eq(10) } 19 | end 20 | 21 | describe "#get_number_of_visits_by_days_since_last" do 22 | assert_data_integrity(:get_number_of_visits_by_days_since_last) 23 | it { subject.get_number_of_visits_by_days_since_last(params).size.should eq(15) } 24 | end 25 | 26 | describe "#get_number_of_visits_by_visit_count" do 27 | assert_data_integrity(:get_number_of_visits_by_visit_count) 28 | it { subject.get_number_of_visits_by_visit_count(params).size.should eq(14) } 29 | end 30 | end -------------------------------------------------------------------------------- /spec/files/Goals.getGoals.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 5 | 1 6 | New user registration 7 | url 8 | register.php 9 | contains 10 | 0 11 | 0 12 | 3 13 | 0 14 | 15 | 16 | 7 17 | 2 18 | User login 19 | url 20 | login.php 21 | contains 22 | 0 23 | 0 24 | 1 25 | 0 26 | 27 | 28 | 7 29 | 3 30 | Read the "Please read" post 31 | url 32 | http://forum.piwik.org/read.php?2,71214 33 | contains 34 | 0 35 | 0 36 | 1 37 | 0 38 | 39 | -------------------------------------------------------------------------------- /spec/files/UserSettings.getMobileVsDesktop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 879 6 | 957 7 | 2094 8 | 47 9 | 141993 10 | 670 11 | 42 12 | plugins/UserSettings/images/screens/normal.gif 13 | 14 | 15 | 16 | 34 17 | 36 18 | 65 19 | 21 20 | 1959 21 | 32 22 | 2 23 | plugins/UserSettings/images/screens/mobile.gif 24 | 25 | 26 | 27 | 2 28 | 2 29 | 2 30 | 1 31 | 0 32 | 2 33 | 0 34 | plugins/UserSettings/images/os/UNK.gif 35 | 36 | -------------------------------------------------------------------------------- /spec/user_settings_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::UserSettings' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::UserSettings } 10 | 11 | describe "#get_resolution" do 12 | assert_data_integrity(:get_resolution) 13 | end 14 | 15 | describe "#get_configuration" do 16 | assert_data_integrity(:get_configuration) 17 | end 18 | 19 | describe "#get_os" do 20 | assert_data_integrity(:get_os) 21 | end 22 | 23 | describe "#get_os_family" do 24 | assert_data_integrity(:get_os_family) 25 | end 26 | 27 | describe "#get_mobile_vs_desktop" do 28 | assert_data_integrity(:get_mobile_vs_desktop) 29 | end 30 | 31 | describe "#get_configuration" do 32 | assert_data_integrity(:get_browser_version) 33 | end 34 | 35 | describe "#get_configuration" do 36 | assert_data_integrity(:get_browser) 37 | end 38 | 39 | describe "#get_configuration" do 40 | assert_data_integrity(:get_browser_type) 41 | end 42 | 43 | describe "#get_configuration" do 44 | assert_data_integrity(:get_wide_screen) 45 | end 46 | 47 | describe "#get_plugin" do 48 | assert_data_integrity(:get_plugin) 49 | end 50 | end -------------------------------------------------------------------------------- /spec/files/CustomDimensions.getCustomDimension.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 45 6 | 1663 7 | 345 8 | 68204 9 | 10 10 | 0 11 | 36 12 | 0 13 | 1516 14 | 22% 15 | 37 16 | dimension1==Sample+Custom+Dimension 17 | 18 | 19 | 20 | 2 21 | 2 22 | 1 23 | 0 24 | 2 25 | 0 26 | 2 27 | 0 28 | 0 29 | 100% 30 | 1 31 | dimension1==unknown 32 | 33 | -------------------------------------------------------------------------------- /spec/files/Goals.getVisitsUntilConversion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 66 6 | 7 | 8 | 9 | 6 10 | 11 | 12 | 13 | 3 14 | 15 | 16 | 17 | 1 18 | 19 | 20 | 21 | 2 22 | 23 | 24 | 25 | 0 26 | 27 | 28 | 29 | 0 30 | 31 | 32 | 33 | 0 34 | 35 | 36 | 37 | 0 38 | 39 | 40 | 41 | 3 42 | 43 | 44 | 45 | 0 46 | 47 | 48 | 49 | 0 50 | 51 | 52 | 53 | 1 54 | 55 | -------------------------------------------------------------------------------- /lib/piwik/visits_summary.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class VisitsSummary < ApiModule 3 | available_methods %W{ 4 | get 5 | getVisits 6 | getUniqueVisitors 7 | getActions 8 | getMaxActions 9 | getBounceCount 10 | getVisitsConverted 11 | getSumVisitsLength 12 | getSumVisitsLengthPretty 13 | } 14 | 15 | scoped_methods do 16 | def converted params = {} 17 | getVisitsConverted(defaults.merge(params)).value 18 | end 19 | 20 | def summary params = {} 21 | get(defaults.merge(params)) 22 | end 23 | 24 | def count params = {} 25 | getVisits(defaults.merge(params)).value 26 | end 27 | 28 | def uniques params = {} 29 | getUniqueVisitors(defaults.merge(params)).value 30 | end 31 | 32 | def actions params = {} 33 | getActions(defaults.merge(params)).value 34 | end 35 | 36 | def max_actions params = {} 37 | getMaxActions(defaults.merge(params)).value 38 | end 39 | 40 | def bounces params = {} 41 | getBounceCount(defaults.merge(params)).value 42 | end 43 | 44 | def length params = {} 45 | getSumVisitsLength(defaults.merge(params)).value 46 | end 47 | 48 | def pretty_length params = {} 49 | getSumVisitsLengthPretty(defaults.merge(params)).value 50 | end 51 | end 52 | end 53 | end -------------------------------------------------------------------------------- /spec/files/VisitorInterest.getNumberOfVisitsByDaysSinceLast.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 777 6 | 7 | 8 | 9 | 78 10 | 11 | 12 | 13 | 48 14 | 15 | 16 | 17 | 4 18 | 19 | 20 | 21 | 6 22 | 23 | 24 | 25 | 2 26 | 27 | 28 | 29 | 0 30 | 31 | 32 | 33 | 6 34 | 35 | 36 | 37 | 4 38 | 39 | 40 | 41 | 24 42 | 43 | 44 | 45 | 25 46 | 47 | 48 | 49 | 14 50 | 51 | 52 | 53 | 5 54 | 55 | 56 | 57 | 1 58 | 59 | 60 | 61 | 1 62 | 63 | -------------------------------------------------------------------------------- /spec/files/Goals.getDaysToConversion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 74 6 | 7 | 8 | 9 | 0 10 | 11 | 12 | 13 | 0 14 | 15 | 16 | 17 | 0 18 | 19 | 20 | 21 | 0 22 | 23 | 24 | 25 | 1 26 | 27 | 28 | 29 | 0 30 | 31 | 32 | 33 | 0 34 | 35 | 36 | 37 | 0 38 | 39 | 40 | 41 | 2 42 | 43 | 44 | 45 | 4 46 | 47 | 48 | 49 | 0 50 | 51 | 52 | 53 | 1 54 | 55 | 56 | 57 | 0 58 | 59 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | cache: bundler 3 | rvm: 4 | - 1.9.3 5 | - 2.0 6 | - 2.1 7 | - 2.2 8 | - 2.3 9 | - 2.4 10 | - 2.5 11 | - jruby 12 | - jruby-9.1.5.0 13 | # - rbx-19mode 14 | script: bundle exec rspec spec 15 | sudo: false 16 | 17 | gemfile: 18 | - ci/Gemfile.as32 19 | - ci/Gemfile.as42 20 | - ci/Gemfile.as50 21 | - ci/Gemfile.as51 22 | 23 | # Exclude incompatible combinations (See http://logfile.swobspace.net/blog/2015/01/01/Ruby-and-Rails.html) 24 | matrix: 25 | exclude: 26 | # ActiveSupport 5.1 27 | - rvm: 1.9.3 28 | gemfile: ci/Gemfile.as51 29 | - rvm: 2.0 30 | gemfile: ci/Gemfile.as51 31 | - rvm: 2.1 32 | gemfile: ci/Gemfile.as51 33 | - rvm: 2.2 34 | gemfile: ci/Gemfile.as51 35 | - rvm: jruby 36 | gemfile: ci/Gemfile.as51 37 | # ActiveSupport 5.0 38 | - rvm: 1.9.3 39 | gemfile: ci/Gemfile.as50 40 | - rvm: 2.0 41 | gemfile: ci/Gemfile.as50 42 | - rvm: 2.1 43 | gemfile: ci/Gemfile.as50 44 | - rvm: 2.2 45 | gemfile: ci/Gemfile.as50 46 | - rvm: jruby 47 | gemfile: ci/Gemfile.as50 48 | # ActiveSupport 4.2 49 | - rvm: 2.2 50 | gemfile: ci/Gemfile.as40 51 | - rvm: 2.3 52 | gemfile: ci/Gemfile.as40 53 | # ActiveSupport 3.2 54 | - rvm: 2.1 55 | gemfile: ci/Gemfile.as32 56 | - rvm: 2.2 57 | gemfile: ci/Gemfile.as32 58 | - rvm: 2.3 59 | gemfile: ci/Gemfile.as32 60 | -------------------------------------------------------------------------------- /spec/files/UserSettings.getBrowserVersion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 337 6 | 363 7 | 771 8 | 36 9 | 47700 10 | 250 11 | 13 12 | plugins/UserSettings/images/browsers/CH.gif 13 | Chrome 23.0 14 | 15 | 16 | 17 | 259 18 | 289 19 | 613 20 | 47 21 | 45944 22 | 209 23 | 13 24 | plugins/UserSettings/images/browsers/FF.gif 25 | Firefox 17.0 26 | 27 | 28 | 29 | 45 30 | 48 31 | 91 32 | 18 33 | 7887 34 | 32 35 | 2 36 | plugins/UserSettings/images/browsers/IE.gif 37 | IE 9.0 38 | 39 | -------------------------------------------------------------------------------- /spec/visits_summary_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::VisitsSummary' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | # TODO: Specify required params 8 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 9 | subject { Piwik::VisitsSummary } 10 | 11 | describe '#get' do 12 | assert_data_integrity(:get, :size => 10) 13 | it { subject.get(params).data['nb_uniq_visitors'].to_i.should eq(914) } 14 | end 15 | 16 | describe "#get_visits" do 17 | assert_value_integrity(:get_visits, :value => 200) 18 | end 19 | 20 | describe "#get_unique_visitors" do 21 | assert_value_integrity(:get_unique_visitors, :value => 100) 22 | end 23 | 24 | describe "#get_actions" do 25 | assert_value_integrity(:get_actions, :value => 55) 26 | end 27 | 28 | describe "#get_max_actions" do 29 | assert_value_integrity(:get_max_actions, :value => 66) 30 | end 31 | 32 | describe "#get_bounce_count" do 33 | assert_value_integrity(:get_bounce_count, :value => 51) 34 | end 35 | 36 | describe "#get_visits_converted" do 37 | assert_value_integrity(:get_visits_converted, :value => 0) 38 | end 39 | 40 | describe "#get_sum_visits_length" do 41 | assert_value_integrity(:get_sum_visits_length, :value => 143952) 42 | end 43 | 44 | describe "#get_sum_visits_length_pretty" do 45 | assert_value_integrity(:get_sum_visits_length_pretty, :value => '1 days 15 hours') 46 | end 47 | end -------------------------------------------------------------------------------- /spec/referrers_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::Referrers' do 3 | before { 4 | stub_api_calls 5 | } 6 | 7 | let(:params) { {:idSite => 1, :period => 'day', :date => 'yesterday'} } 8 | subject { Piwik::Referrers } 9 | 10 | describe "#get_keywords" do 11 | assert_data_integrity(:get_keywords, :size => 10) 12 | end 13 | 14 | describe "#get_campaigns" do 15 | it { subject.get_campaigns(params).size.should eq(0) } 16 | it { subject.get_campaigns(params).empty?.should eq(true) } 17 | end 18 | 19 | describe "#get_referrer_type" do 20 | assert_data_integrity(:get_referrer_type, :size => 3) 21 | end 22 | 23 | describe "#get_number_of_distinct_keywords" do 24 | assert_value_integrity(:get_number_of_distinct_keywords, :value => 207) 25 | end 26 | 27 | describe "#get_number_of_distinct_search_engines" do 28 | assert_value_integrity(:get_number_of_distinct_search_engines, :value => 7) 29 | end 30 | 31 | describe "#get_number_of_distinct_websites" do 32 | assert_value_integrity(:get_number_of_distinct_websites, :value => 27) 33 | end 34 | 35 | describe "#get_search_engines" do 36 | assert_data_integrity(:get_search_engines, :size => 7) 37 | end 38 | 39 | describe "#get_socials" do 40 | it { subject.get_socials(params).size.should eq(0) } 41 | end 42 | 43 | describe "#get_urls_for_social" do 44 | it { subject.get_urls_for_social(params).size.should eq(0) } 45 | end 46 | end -------------------------------------------------------------------------------- /spec/files/API.getDefaultMetricsDocumentation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Wenn ein Besucher zum ersten Mal die Webseite besucht oder seit dem letzen Seitenaufruf mehr als 30 Minuten vergangen sind, wird dies als neuer Besuch gewertet. 5 | Die Anzahl der eindeutigen Besucher auf der Webseite. Jeder Benutzer wird nur einmal gezählt, auch wenn er die Webseite mehrmals täglich besucht hat. 6 | Die Anzahl der Aktionen, die ein Besucher durchgeführt hat. Aktionen sind Seitenansichten, Downloads und der Aufruf von externen Links. 7 | Die durchschnittliche Anzahl der Aktionen (Seitenaufrufe, Downloads oder Outlinks), die während der Besuche durchgeführt wurden. 8 | Durchschnittslänge eines Besuches. 9 | Der Anteil der Besuche, bei denen nur eine Seite aufgerufen wurde. Dies bedeutet, dass der Besucher die Website auf der Eingangsseite sofort wieder verlassen hat. 10 | Prozentsatz der Besucher, die ein Zeil erreicht haben. 11 | Die durchschnittliche Besuchdauer einer Seite (nur die einzelne Seite, nicht die gesamte Webseite) 12 | Die Anzahl, wie häufig diese Seite besucht wurde. 13 | Der Anteil der Besuche, welche die Webseite nach dieser Seite verlassen haben. 14 | 15 | -------------------------------------------------------------------------------- /spec/files/UserSettings.getConfiguration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 52 6 | 57 7 | 96 8 | 8 9 | 8194 10 | 42 11 | 2 12 | 13 | 14 | 15 | 11 16 | 13 17 | 15 18 | 2 19 | 144 20 | 11 21 | 0 22 | 23 | 24 | 25 | 12 26 | 13 27 | 54 28 | 25 29 | 2118 30 | 9 31 | 3 32 | 33 | 34 | 35 | 12 36 | 12 37 | 22 38 | 6 39 | 608 40 | 7 41 | 0 42 | 43 | -------------------------------------------------------------------------------- /lib/piwik/users_manager.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class UsersManager < ApiModule 3 | available_methods %W{ 4 | setUserPreference 5 | getUserPreference 6 | getUsers 7 | getUsersLogin 8 | getUsersSitesFromAccess 9 | getUsersAccessFromSite 10 | getUsersWithSiteAccess 11 | getSitesAccessFromUser 12 | getUser 13 | getUserByEmail 14 | addUser 15 | updateUser 16 | deleteUser 17 | userExists 18 | userEmailExists 19 | setUserAccess 20 | getTokenAuth 21 | createAppSpecificTokenAuth 22 | } 23 | 24 | def self.get params 25 | resp = self.get_user(params) 26 | raise Piwik::UnknownUser if resp.blank? 27 | Piwik::User.new resp 28 | end 29 | 30 | # monkeypatching, as the Piwik API is inconsistent. 31 | # not all add methods return the same response type. Boo. 32 | def self.add params 33 | obj = Piwik::User.new(params) 34 | resp = self.api_call('addUser',params) 35 | obj 36 | end 37 | 38 | def self.save params 39 | self.api_call('updateUser',params) 40 | end 41 | 42 | def self.delete params 43 | self.api_call('deleteDelete',params) 44 | end 45 | 46 | # TODO: this one is not working. 47 | # I assume there are other metacoded methods that might throw errors, 48 | # so a bit or hunting down is in ortder sometime 49 | def self.user_exists(params) 50 | Piwik::UsersManager::UserExists.new(:value => self.api_call('userExists',params)) 51 | end 52 | end 53 | end -------------------------------------------------------------------------------- /lib/piwik/actions.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class Actions < ApiModule 3 | available_methods %W{ 4 | get 5 | getPageUrls 6 | getPageUrlsFollowingSiteSearch 7 | getPageTitlesFollowingSiteSearch 8 | getEntryPageUrls 9 | getExitPageUrls 10 | getPageUrl 11 | getPageTitles 12 | getEntryPageTitles 13 | getExitPageTitles 14 | getPageTitle 15 | getDownloads 16 | getDownload 17 | getOutlinks 18 | getOutlink 19 | getSiteSearchKeywords 20 | addPagesPerSearchColumn 21 | getSiteSearchNoResultKeywords 22 | getSiteSearchCategories 23 | } 24 | 25 | scoped_methods do 26 | def summary params = {} 27 | get(defaults.merge(params)) 28 | end 29 | 30 | def urls params = {} 31 | getPageUrls(defaults.merge(params)) 32 | end 33 | 34 | def url(page_url, params = {}) 35 | getPageUrl(defaults.merge(params).merge(:pageUrl => page_url)) 36 | end 37 | 38 | def entry_urls params = {} 39 | getEntryPageUrls(defaults.merge(params)) 40 | end 41 | 42 | def exit_urls params = {} 43 | getExitPageUrls(defaults.merge(params)) 44 | end 45 | 46 | def downloads params = {} 47 | getDownloads(defaults.merge(params)) 48 | end 49 | 50 | def outlinks params = {} 51 | getOutlinks(defaults.merge(params)) 52 | end 53 | 54 | def outlink(outlink_url, params = {}) 55 | getOutlink(defaults.merge(params).merge(:outlinkUrl => outlink_url)) 56 | end 57 | end 58 | end 59 | end -------------------------------------------------------------------------------- /spec/files/UserSettings.getWideScreen.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 739 6 | 808 7 | 1701 8 | 47 9 | 113426 10 | 570 11 | 29 12 | plugins/UserSettings/images/screens/wide.gif 13 | 14 | 15 | 16 | 169 17 | 179 18 | 452 19 | 27 20 | 30526 21 | 126 22 | 15 23 | plugins/UserSettings/images/screens/normal.gif 24 | 25 | 26 | 27 | 5 28 | 5 29 | 5 30 | 1 31 | 0 32 | 5 33 | 0 34 | plugins/UserSettings/images/screens/mobile.gif 35 | 36 | 37 | 38 | 1 39 | 1 40 | 1 41 | 1 42 | 0 43 | 1 44 | 0 45 | plugins/UserSettings/images/screens/dual.gif 46 | 47 | -------------------------------------------------------------------------------- /spec/files/UserSettings.getBrowser.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 386 6 | 416 7 | 849 8 | 36 9 | 52616 10 | 292 11 | 14 12 | plugins/UserSettings/images/browsers/CH.gif 13 | 14 | 15 | 16 | 339 17 | 372 18 | 898 19 | 47 20 | 65164 21 | 266 22 | 21 23 | plugins/UserSettings/images/browsers/FF.gif 24 | 25 | 26 | 27 | 105 28 | 109 29 | 213 30 | 21 31 | 13804 32 | 74 33 | 6 34 | plugins/UserSettings/images/browsers/IE.gif 35 | 36 | 37 | 38 | 55 39 | 65 40 | 141 41 | 21 42 | 8465 43 | 47 44 | 3 45 | plugins/UserSettings/images/browsers/SF.gif 46 | 47 | -------------------------------------------------------------------------------- /lib/piwik/data_methods.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | # Provides a more intuitive interface to API responses. 3 | # Responses may return a value or structured data, and objects will figure out what kind or response they are getting, 4 | # and stick them in the appropriate instance variable. 5 | # Value responses are accessed directly: 6 | # Example: 7 | # 8 | # Piwik::VisitsSummary.getVisits(:idSite => 7, :period => :day, :date => Date.today).value 9 | # => 467 10 | # 11 | # Data Responses can be accessed either as a Hash or an object. 12 | # Example: 13 | # 14 | # s = Piwik::API.getSettings 15 | # => #"10", "SDK_interval_value"=>"30"}> 16 | # s.SDK_batch_size 17 | # => 10 18 | # s['SDK_batch_size'] 19 | # => 10 20 | # s.data['SDK_batch_size'] 21 | # => 10 22 | module DataMethods 23 | def self.included(base) 24 | include Piwik::Typecast 25 | base.send(:include, InstanceMethods) 26 | attr_accessor :data,:value 27 | end 28 | 29 | module InstanceMethods 30 | def empty? 31 | data.blank? and value.blank? 32 | end 33 | 34 | def value 35 | typecast(@value) 36 | end 37 | 38 | def initialize opts = {} 39 | opts.map {|k,v| self.send(:"#{k}=",v) } 40 | end 41 | 42 | # try to pass method to the data variable 43 | def method_missing(method, *args, &block) 44 | if self.data.respond_to?(method) 45 | typecast(self.data.send(method,*args,&block)) 46 | elsif self.data.is_a?(Hash) && self.data.key?(method.to_s) 47 | typecast(self.data[method.to_s]) 48 | else 49 | super 50 | end 51 | end 52 | end 53 | end 54 | end -------------------------------------------------------------------------------- /spec/files/SitesManager.getAllSites.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1 5 | Humbucker 6 | http://humbuckercode.co.uk 7 | 2012-12-26 10:10:15 8 | 0 9 | 1 10 | 11 | 12 | Europe/London 13 | USD 14 | 15 | 16 | 17 | 18 | 19 | 67 20 | Test Site 21 | http://test.local 22 | 2013-01-03 16:18:40 23 | 0 24 | 1 25 | 26 | 27 | Europe/London 28 | USD 29 | 30 | 31 | 32 | 33 | 34 | 68 35 | Karate Site 36 | http://test.local 37 | 2013-01-03 16:19:30 38 | 0 39 | 1 40 | 41 | 42 | Europe/London 43 | USD 44 | 45 | 46 | 47 | 48 | 49 | 64 50 | Test Site 51 | http://test.local 52 | 2013-01-03 16:16:48 53 | 0 54 | 1 55 | 56 | 57 | Europe/London 58 | USD 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /spec/files/SitesManager.getSitesWithAdminAccess.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1 5 | Humbucker 6 | http://humbuckercode.co.uk 7 | 2012-12-26 10:10:15 8 | 0 9 | 1 10 | 11 | 12 | Europe/London 13 | USD 14 | 15 | 16 | 17 | 18 | 19 | 64 20 | Test Site 21 | http://test.local 22 | 2013-01-03 16:16:48 23 | 0 24 | 1 25 | 26 | 27 | Europe/London 28 | USD 29 | 30 | 31 | 32 | 33 | 34 | 67 35 | Test Site 36 | http://test.local 37 | 2013-01-03 16:18:40 38 | 0 39 | 1 40 | 41 | 42 | Europe/London 43 | USD 44 | 45 | 46 | 47 | 48 | 49 | 68 50 | Karate Site 51 | http://test.local 52 | 2013-01-03 16:19:30 53 | 0 54 | 1 55 | 56 | 57 | Europe/London 58 | USD 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /spec/files/UserSettings.getBrowserType.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 443 6 | 483 7 | 999 8 | 36 9 | 63255 10 | 339 11 | 17 12 | Webkit 13 | 14 | 15 | 16 | 342 17 | 375 18 | 909 19 | 47 20 | 65193 21 | 268 22 | 21 23 | Gecko 24 | 25 | 26 | 27 | 105 28 | 109 29 | 213 30 | 21 31 | 13804 32 | 74 33 | 6 34 | Ie 35 | 36 | 37 | 38 | 24 39 | 27 40 | 39 41 | 5 42 | 1700 43 | 22 44 | 0 45 | Opera 46 | 47 | 48 | 49 | 1 50 | 1 51 | 1 52 | 1 53 | 0 54 | 1 55 | 0 56 | Unknown 57 | 58 | -------------------------------------------------------------------------------- /lib/piwik/referrers.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class Referrers < ApiModule 3 | available_methods %W{ 4 | getReferrerType 5 | getKeywords 6 | getKeywordsForPageUrl 7 | getKeywordsForPageTitle 8 | getSearchEnginesFromKeywordId 9 | getSearchEngines 10 | getKeywordsFromSearchEngineId 11 | getCampaigns 12 | getKeywordsFromCampaignId 13 | getWebsites 14 | getSocials 15 | getUrlsForSocial 16 | getUrlsFromWebsiteId 17 | getNumberOfDistinctSearchEngines 18 | getNumberOfDistinctKeywords 19 | getNumberOfDistinctCampaigns 20 | getNumberOfDistinctWebsites 21 | getNumberOfDistinctWebsitesUrls 22 | } 23 | 24 | scoped_methods do 25 | def websites params = {} 26 | getWebsites(defaults.merge(params)) 27 | end 28 | 29 | def websites_count params = {} 30 | getNumberOfDistinctWebsites(defaults.merge(params)).value 31 | end 32 | 33 | def keywords params = {} 34 | getKeywords(defaults.merge(params)) 35 | end 36 | 37 | def keywords_for_title(title, params = {}) 38 | getKeywordsForPageTitle(defaults.merge(params).merge(:pageTitle => title)) 39 | end 40 | 41 | def keywords_for_url(url, params = {}) 42 | getKeywordsForPageUrl(defaults.merge(params).merge(:pageUrl => url)) 43 | end 44 | 45 | def keywords_count params = {} 46 | getNumberOfDistinctKeywords(defaults.merge(params)).value 47 | end 48 | 49 | def search_engines params = {} 50 | getSearchEngines(defaults.merge(params)) 51 | end 52 | 53 | def search_engines_count params = {} 54 | getNumberOfDistinctSearchEngines(defaults.merge(params)).value 55 | end 56 | 57 | def socials params = {} 58 | getSocials(defaults.merge(params)) 59 | end 60 | end 61 | end 62 | end 63 | 64 | # alias new class name to old one for backwards-compatible API 65 | Piwik::Referers = Piwik::Referrers -------------------------------------------------------------------------------- /spec/files/VisitorInterest.getNumberOfVisitsByVisitCount.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 779 6 | 78% 7 | 8 | 9 | 10 | 96 11 | 10% 12 | 13 | 14 | 15 | 36 16 | 4% 17 | 18 | 19 | 20 | 13 21 | 1% 22 | 23 | 24 | 25 | 5 26 | 1% 27 | 28 | 29 | 30 | 6 31 | 1% 32 | 33 | 34 | 35 | 11 36 | 1% 37 | 38 | 39 | 40 | 2 41 | 0% 42 | 43 | 44 | 45 | 5 46 | 1% 47 | 48 | 49 | 50 | 7 51 | 1% 52 | 53 | 54 | 55 | 15 56 | 2% 57 | 58 | 59 | 60 | 2 61 | 0% 62 | 63 | 64 | 65 | 4 66 | 0% 67 | 68 | 69 | 70 | 14 71 | 1% 72 | 73 | -------------------------------------------------------------------------------- /spec/files/Transitions.getTranslations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %s pageviews 5 | %s page reloads 6 | From Internal Pages 7 | %s from internal pages 8 | From Internal Search 9 | %s from internal searches 10 | From Search Engines 11 | %s from search engines 12 | From Websites 13 | %s from websites 14 | From Campaigns 15 | %s from campaigns 16 | Direct Entries 17 | %s direct entries 18 | To Internal Pages 19 | %s to internal pages 20 | Internal Searches 21 | %s internal searches 22 | Downloads 23 | %s downloads 24 | Outlinks 25 | %s outlinks 26 | Exits 27 | %s exits 28 | %s bounces 29 | %s (out of %s) 30 | %s of all views of this page 31 | There's no data for %s 32 | Either the action had no pageviews during the period %s or it is invalid. 33 | Go back to the previous action 34 | This page had %s pageviews (%s of all pageviews) 35 | Date range: 36 | 37 | -------------------------------------------------------------------------------- /lib/piwik/sites_manager.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class SitesManager < ApiModule 3 | available_methods %W{ 4 | getJavascriptTag 5 | getSitesFromGroup 6 | getSitesGroups 7 | getSiteFromId 8 | getSiteUrlsFromId 9 | getAllSites 10 | getAllSitesId 11 | getSitesIdWithVisits 12 | getSitesWithAdminAccess 13 | getSitesWithViewAccess 14 | getSitesWithAtLeastViewAccess 15 | getSitesIdWithAdminAccess 16 | getSitesIdWithViewAccess 17 | getSitesIdWithAtLeastViewAccess 18 | getSitesIdFromSiteUrl 19 | addSite 20 | deleteSite 21 | addSiteAliasUrls 22 | getIpsForRange 23 | setGlobalExcludedIps 24 | setGlobalSearchParameters 25 | getSearchKeywordParametersGlobal 26 | getSearchCategoryParametersGlobal 27 | getExcludedQueryParametersGlobal 28 | getExcludedUserAgentsGlobal 29 | setGlobalExcludedUserAgents 30 | isSiteSpecificUserAgentExcludeEnabled 31 | setSiteSpecificUserAgentExcludeEnabled 32 | setGlobalExcludedQueryParameters 33 | getExcludedIpsGlobal 34 | getDefaultCurrency 35 | setDefaultCurrency 36 | getDefaultTimezone 37 | setDefaultTimezone 38 | updateSite 39 | getCurrencyList 40 | getCurrencySymbols 41 | getTimezonesList 42 | getUniqueSiteTimezones 43 | getPatternMatchSites 44 | } 45 | 46 | def self.get params 47 | resp = self.get_site_from_id(params) 48 | # Hack. The Piwik API get really weird sometimes 49 | raise Piwik::UnknownSite if resp.value == '0' 50 | Piwik::Site.new resp 51 | end 52 | 53 | # monkeypatching, as the Piwik API is inconsistent. 54 | # not all add methods return the same response type. Boo. 55 | def self.add params 56 | obj = Piwik::Site.new(params) 57 | resp = self.api_call('addSite',params) 58 | obj.attributes.idSite = resp 59 | obj 60 | end 61 | 62 | def self.save params 63 | self.api_call('updateSite',params) 64 | end 65 | 66 | def self.delete params 67 | self.api_call('deleteSite',params) 68 | end 69 | end 70 | end -------------------------------------------------------------------------------- /spec/files/UserSettings.getPlugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 879 6 | 99.2% 7 | plugins/UserSettings/images/plugins/cookie.gif 8 | 9 | 10 | 11 | 827 12 | 93.3% 13 | plugins/UserSettings/images/plugins/flash.gif 14 | 15 | 16 | 17 | 724 18 | 81.7% 19 | plugins/UserSettings/images/plugins/pdf.gif 20 | 21 | 22 | 23 | 673 24 | 76% 25 | plugins/UserSettings/images/plugins/java.gif 26 | 27 | 28 | 29 | 473 30 | 53.4% 31 | plugins/UserSettings/images/plugins/silverlight.gif 32 | 33 | 34 | 35 | 447 36 | 50.5% 37 | plugins/UserSettings/images/plugins/windowsmedia.gif 38 | 39 | 40 | 41 | 445 42 | 50.2% 43 | plugins/UserSettings/images/plugins/quicktime.gif 44 | 45 | 46 | 47 | 97 48 | 10.9% 49 | plugins/UserSettings/images/plugins/director.gif 50 | 51 | 52 | 53 | 56 54 | 6.3% 55 | plugins/UserSettings/images/plugins/realplayer.gif 56 | 57 | 58 | 59 | 1 60 | 0.1% 61 | plugins/UserSettings/images/plugins/gears.gif 62 | 63 | -------------------------------------------------------------------------------- /spec/files/API.getDefaultMetricTranslations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Besuche 5 | Eindeutige Besucher 6 | Aktionen 7 | Aktionen pro Besuch 8 | Durchschnittszeit auf der Webseite 9 | Absprungsrate 10 | Konversionsrate 11 | 12 | Datum 13 | Durchschnittszeit pro Seite 14 | Von Besuchern verbrachte Gesamtzeit (in Sekunden) 15 | Von Besuchern verbrachte Gesamtzeit (in Sekunden) 16 | Absprünge 17 | Absprünge von wiederkehrenden Besuchen 18 | Maximale Aktionen pro Besuch 19 | Maximale Aktionen pro wiederkehrender Besuch 20 | Anzahl wiederkehrende Besuche mit Konversion 21 | Gesamte Aufenthaltszeit bei wiederkehrenden Besuchen (in Sekunden) 22 | Besuche mit Konversionen 23 | Konversionen 24 | Umsatz 25 | Seitenansichten 26 | Eingänge 27 | Einmalige Eingänge 28 | Ausstiege 29 | Einmalige Ausstiege 30 | Absprünge 31 | Absprünge 32 | Ausstiegsrate 33 | Eindeutige Besucher (Tagessumme) 34 | Einmalige Eingänge (Tagessumme) 35 | Einmalige Ausstiege (Tagessumme) 36 | Aktionen nach Eingang hier 37 | Von Besuchern verbrachte Gesamtzeit (in Sekunden) nach Eingang hier 38 | 39 | -------------------------------------------------------------------------------- /spec/files/Referrers.getReferrerType.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 649 6 | 665 7 | 1146 8 | 102 9 | 72361 10 | 510 11 | 12 | 13 | 8 14 | 8 15 | 24 16 | 17 | 18 | 10 19 | 10 20 | 10 21 | 22 | 23 | 3 24 | 3 25 | 3 26 | 27 | 28 | 21 29 | 37 30 | 31 | 32 | 33 | 127 34 | 151 35 | 636 36 | 50 37 | 35549 38 | 79 39 | 40 | 41 | 16 42 | 16 43 | 48 44 | 45 | 46 | 16 47 | 16 48 | 16 49 | 50 | 51 | 32 52 | 64 53 | 54 | 55 | 56 | 138 57 | 139 58 | 593 59 | 89 60 | 35497 61 | 59 62 | 63 | 64 | 10 65 | 10 66 | 30 67 | 68 | 69 | 18 70 | 18 71 | 18 72 | 73 | 74 | 1 75 | 1 76 | 1 77 | 78 | 79 | 29 80 | 49 81 | 82 | -------------------------------------------------------------------------------- /spec/files/VisitTime.getVisitInformationPerServerTime.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 6 | 19 7 | 34 8 | 7 9 | 443 10 | 15 11 | 0 12 | 13 | 14 | 15 | 16 16 | 17 17 | 39 18 | 16 19 | 1492 20 | 13 21 | 22 | 23 | 1 24 | 1 25 | 3 26 | 27 | 28 | 1 29 | 3 30 | 31 | 32 | 33 | 17 34 | 17 35 | 28 36 | 4 37 | 703 38 | 11 39 | 0 40 | 41 | 42 | 43 | 17 44 | 19 45 | 31 46 | 11 47 | 525 48 | 16 49 | 50 | 51 | 3 52 | 3 53 | 9 54 | 55 | 56 | 1 57 | 1 58 | 1 59 | 60 | 61 | 4 62 | 10 63 | 64 | 65 | 66 | 25 67 | 25 68 | 92 69 | 23 70 | 5515 71 | 14 72 | 73 | 74 | 5 75 | 5 76 | 15 77 | 78 | 79 | 5 80 | 5 81 | 5 82 | 83 | 84 | 10 85 | 20 86 | 87 | -------------------------------------------------------------------------------- /spec/files/VisitTime.getVisitInformationPerLocalTime.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 23 6 | 23 7 | 45 8 | 9 9 | 2496 10 | 16 11 | 1 12 | 13 | 14 | 15 | 16 16 | 16 17 | 20 18 | 2 19 | 935 20 | 12 21 | 0 22 | 23 | 24 | 25 | 13 26 | 13 27 | 35 28 | 21 29 | 2428 30 | 11 31 | 1 32 | 33 | 34 | 35 | 9 36 | 9 37 | 10 38 | 2 39 | 34 40 | 8 41 | 0 42 | 43 | 44 | 45 | 4 46 | 4 47 | 6 48 | 2 49 | 55 50 | 2 51 | 0 52 | 53 | 54 | 55 | 9 56 | 9 57 | 12 58 | 3 59 | 1477 60 | 7 61 | 0 62 | 63 | 64 | 65 | 4 66 | 4 67 | 4 68 | 1 69 | 0 70 | 4 71 | 0 72 | 73 | 74 | 75 | 8 76 | 8 77 | 15 78 | 7 79 | 417 80 | 6 81 | 0 82 | 83 | -------------------------------------------------------------------------------- /spec/files/API.getMetadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Besucher 5 | Land 6 | UserCountry 7 | getCountry 8 | Land 9 | 10 | Besuche 11 | Eindeutige Besucher 12 | Aktionen 13 | 14 | 15 | Aktionen pro Besuch 16 | Durchschnittszeit auf der Webseite 17 | Absprungsrate 18 | 19 | 20 | Wenn ein Besucher zum ersten Mal die Webseite besucht oder seit dem letzen Seitenaufruf mehr als 30 Minuten vergangen sind, wird dies als neuer Besuch gewertet. 21 | Die Anzahl der eindeutigen Besucher auf der Webseite. Jeder Benutzer wird nur einmal gezählt, auch wenn er die Webseite mehrmals täglich besucht hat. 22 | Die Anzahl der Aktionen, die ein Besucher durchgeführt hat. Aktionen sind Seitenansichten, Downloads und der Aufruf von externen Links. 23 | Die durchschnittliche Anzahl der Aktionen (Seitenaufrufe, Downloads oder Outlinks), die während der Besuche durchgeführt wurden. 24 | Durchschnittslänge eines Besuches. 25 | Der Anteil der Besuche, bei denen nur eine Seite aufgerufen wurde. Dies bedeutet, dass der Besucher die Website auf der Eingangsseite sofort wieder verlassen hat. 26 | Prozentsatz der Besucher, die ein Zeil erreicht haben. 27 | Die durchschnittliche Besuchdauer einer Seite (nur die einzelne Seite, nicht die gesamte Webseite) 28 | Die Anzahl, wie häufig diese Seite besucht wurde. 29 | Der Anteil der Besuche, welche die Webseite nach dieser Seite verlassen haben. 30 | 31 | 32 | Konversionen 33 | Umsatz 34 | 35 | 36 | Umsatz pro Besuch 37 | 38 | index.php?module=API&method=ImageGraph.get&idSite=7&apiModule=UserCountry&apiAction=getCountry&token_auth=anonymous&period=day&date=yesterday 39 | index.php?module=API&method=ImageGraph.get&idSite=7&apiModule=UserCountry&apiAction=getCountry&token_auth=anonymous&period=day&date=2012-12-04,2013-01-02 40 | UserCountry_getCountry 41 | 42 | -------------------------------------------------------------------------------- /spec/files/CustomDimensions.getConfiguredCustomDimensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1 5 | 1 6 | Custom Dimension 1 7 | 1 8 | visit 9 | 1 10 | 11 | 12 | 1 13 | 14 | 15 | 2 16 | 1 17 | Custom Dimension 2 18 | 2 19 | visit 20 | 1 21 | 22 | 23 | 1 24 | 25 | 26 | 3 27 | 1 28 | Custom Dimension 3 29 | 3 30 | visit 31 | 1 32 | 33 | 34 | 1 35 | 36 | 37 | 4 38 | 1 39 | Custom Dimension 4 40 | 4 41 | visit 42 | 1 43 | 44 | 45 | 1 46 | 47 | 48 | 5 49 | 1 50 | Custom Dimension 5 51 | 1 52 | action 53 | 1 54 | 55 | 56 | url 57 | 58 | 59 | 60 | 1 61 | 62 | 63 | 6 64 | 1 65 | Custom Dimension 6 66 | 2 67 | action 68 | 1 69 | 70 | 71 | url 72 | 73 | 74 | 75 | 1 76 | 77 | 78 | 7 79 | 1 80 | Custom Dimension 7 81 | 3 82 | action 83 | 1 84 | 85 | 86 | url 87 | 88 | 89 | 90 | 1 91 | 92 | 93 | 8 94 | 1 95 | Custom Dimension 8 96 | 4 97 | action 98 | 1 99 | 100 | 101 | url 102 | 103 | 104 | 105 | 1 106 | 107 | -------------------------------------------------------------------------------- /lib/piwik/site.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | # Piwik::Site is a wrapper class used to expose a more ruby-friendly (and sane) interface to the Piwik API. 3 | # The Piwik API is under development, and there are quite a few incosistencies that are ironed out 4 | # when it is used through the Piwik::Site metaclass. 5 | # 6 | # Example usage using the bundled terminal script. Uses the official Piwik demo server as a sandbox 7 | # 8 | # $ ./script/terminal -u http://demo.piwik.org -t anonymous 9 | # > site = Piwik::Site.load(7) 10 | # => # 11 | # > summary = site.visits.summary 12 | # => # 13 | # > summary.bounce_rate 14 | # => "68%" 15 | # > site.visits.count 16 | # => 467 17 | # > site.annotations.all 18 | # => # 19 | # > site.annotations.add(:date => 'today', :note => 'twitter account online', :starred => '1') 20 | # => Piwik::ApiError: The current user is not allowed to add notes for site #7 21 | # > site.referers.website_count 22 | # => 12 23 | # 24 | # This class creates site-aware proxies (called api_scopes) to the various client classes. 25 | # This lets you call api methods for a selected site without having to resubmit the site id all the time. 26 | # Furthermore, API methods are redefined as proxy_methods, 27 | # allowing for ruby-friendlier names, default parameters and other nice things. 28 | class Site < Base 29 | api_scope :actions 30 | api_scope :annotations 31 | api_scope :devices_detection 32 | api_scope :events 33 | api_scope :goals 34 | api_scope :referrers 35 | api_scope :scheduled_reports 36 | api_scope :transitions 37 | api_scope :visits, :class_name => 'VisitsSummary' 38 | 39 | # Returns search engine information for site home 40 | def seo_info 41 | Piwik::SEO.getRank(:url => self.main_url) 42 | end 43 | 44 | # Gives read access ('view') to the supplied user login for the current site. 45 | def give_view_access_to(login) 46 | give_access_to(:view, login) 47 | end 48 | 49 | # Gives read and write access ('admin') for the supplied user login for the current site. 50 | def give_admin_access_to(login) 51 | give_access_to(:admin, login) 52 | end 53 | 54 | # Removes all access (gives a 'noaccess') for the supplied user login for the current site. 55 | def give_no_access_to(login) 56 | give_access_to(:noaccess, login) 57 | end 58 | alias_method :remove_access_for, :give_no_access_to 59 | 60 | class << self 61 | def collection 62 | Piwik::SitesManager 63 | end 64 | 65 | def id_attr 66 | :idSite 67 | end 68 | end 69 | 70 | private 71 | # Gives the supplied access for the supplied user, for the current site. 72 | # 73 | # * access can be one of :view, :admin or :noaccess 74 | # * login is the user login on Piwik 75 | def give_access_to(access, login) 76 | Piwik::UsersManager.setUserAccess(:idSites => id, :access => access.to_s, :userLogin => login.to_s).data 77 | end 78 | end 79 | end 80 | -------------------------------------------------------------------------------- /spec/files/Actions.getOutlinks.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 50 6 | 53 7 | 2880 8 | 2 9 | 2 10 | 0 11 | 2 12 | 38 13 | 67 14 | 15 | 16 | 17 | 22 18 | 25 19 | 1439 20 | 16 21 | 1 22 | 1 23 | 0 24 | 1 25 | 71 26 | 27 | 28 | 29 | 11 30 | 12 31 | 290 32 | 9 33 | 2 34 | 3 35 | 189 36 | 1 37 | 69 38 | 39 | 40 | 41 | 3 42 | 3 43 | 148 44 | 1 45 | 72 46 | 47 | 48 | 49 | 1 50 | 1 51 | 0 52 | 1 53 | 73 54 | 55 | 56 | 57 | 1 58 | 1 59 | 0 60 | 1 61 | 74 62 | 63 | 64 | 65 | 1 66 | 1 67 | 328 68 | 75 69 | 70 | 71 | 72 | 1 73 | 1 74 | 52 75 | 76 76 | 77 | 78 | 79 | 1 80 | 1 81 | 0 82 | 1 83 | 77 84 | 85 | 86 | 87 | 1 88 | 1 89 | 930 90 | 79 91 | 92 | 93 | 94 | 1 95 | 1 96 | 0 97 | 1 98 | 78 99 | 100 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rspec/its' 2 | require 'piwik' 3 | 4 | RSpec.configure do |config| 5 | Dir[File.join(File.dirname(__FILE__),'spec','support''**','*.rb')].each {|f| require f} 6 | config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] } 7 | config.order = "random" 8 | 9 | config.mock_with(:rspec) { |mocks| mocks.syntax = [:expect, :should] } 10 | end 11 | 12 | def stub_rails_env &block 13 | Object.const_set("RAILS_ROOT", File.join(File.dirname(__FILE__),"files")) 14 | yield 15 | Object.const_set("RAILS_ROOT",nil) 16 | end 17 | 18 | def success_response 19 | File.join(File.dirname(__FILE__),'files',"success.xml") 20 | end 21 | 22 | def failure_response 23 | File.join(File.dirname(__FILE__),'files',"failure.xml") 24 | end 25 | 26 | def stub_api_calls 27 | # Stubbing the main API call method. Methods without a specific stub 28 | # will always return a success response 29 | Piwik::Base.stub(:call) do |method,params,piwik_url,auth_token| 30 | resp_file = File.join(File.dirname(__FILE__),'files',"#{method}.xml") 31 | xml = if File.exist?(resp_file) 32 | File.binread resp_file 33 | else 34 | File.binread File.join(success_response) 35 | end 36 | if xml.is_a?(String) && xml.force_encoding('BINARY').is_binary_data? 37 | xml.force_encoding('BINARY') 38 | elsif xml =~ /error message=/ 39 | result = XmlSimple.xml_in(xml, {'ForceArray' => false}) 40 | raise Piwik::ApiError, result['error']['message'] if result['error'] 41 | else 42 | xml 43 | end 44 | end 45 | end 46 | 47 | def assert_data_integrity method, options = {} 48 | it { puts subject.inspect } if options[:debug] 49 | it { expect { subject.send(method,params) }.not_to raise_error } 50 | enum_class = defined?(Enumerator) ? 'Enumerator' : 'Enumerable::Enumerator' 51 | it { subject.send(method,params).each.should be_a(enum_class.constantize) } 52 | it { subject.send(method,params).empty?.should eq(false) } 53 | if options[:size].present? 54 | it { subject.send(method,params).size.should eq(options[:size]) } 55 | end 56 | end 57 | 58 | def assert_value_integrity method, options = {} 59 | it { puts subject.inspect } if options[:debug] 60 | it { expect { subject.send(method,params) }.not_to raise_error } 61 | it { subject.send(method,params).empty?.should eq(false) } 62 | if options[:value].present? 63 | it { subject.send(method,params).value.should eq(options[:value]) } 64 | end 65 | end 66 | 67 | def build(object, attrs = {}) 68 | case object 69 | when :user 70 | def_attrs = { :login => "test_user", :password => "changeme", :email => "user@test.local", :user_alias => "Test User" } 71 | Piwik::User.new(def_attrs.merge(attrs)) 72 | when :site 73 | def_attrs = { :idsite => 1, :main_url => "http://test.local", :name => "Test Site" } 74 | Piwik::Site.new(def_attrs.merge(attrs)) 75 | when :segment 76 | def_attrs = { idsegment: 5, name: "Custom Segment Five", 77 | definition: "referrerType==website", login: "john.doe", 78 | enable_all_users: 0, enable_only_idsite: 1, auto_archive: 0, 79 | ts_created: "2020-06-17 18:16:26", 80 | ts_last_edit: "2020-06-18 19:08:26", deleted: 0 } 81 | Piwik::Segment.new(def_attrs.merge(attrs)) 82 | end 83 | end 84 | 85 | PIWIK_URL = 'http://piwik.local' 86 | PIWIK_TOKEN = '90871c8584ddf2265f54553a305b6ae1' 87 | -------------------------------------------------------------------------------- /spec/files/SitesManager.getCurrencySymbols.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $ 5 | 6 | ¥ 7 | £ 8 | Fr 9 | ؋ 10 | L 11 | د.ج 12 | Kz 13 | $ 14 | դր. 15 | ƒ 16 | $ 17 | m 18 | $ 19 | .د.ب 20 | 21 | $ 22 | Br 23 | $ 24 | $ 25 | Nu. 26 | Bs. 27 | KM 28 | P 29 | R$ 30 | $ 31 | лв 32 | Fr 33 | 34 | $ 35 | $ 36 | $ 37 | Fr 38 | $ 39 | 40 | $ 41 | Fr 42 | Fr 43 | 44 | kn 45 | F 46 | $ 47 | $ 48 | ƒ 49 | 50 | kr 51 | Fr 52 | $ 53 | $ 54 | ج.م 55 | Nfk 56 | kr 57 | Br 58 | £ 59 | $ 60 | D 61 | 62 | 63 | £ 64 | Q 65 | Fr 66 | $ 67 | G 68 | L 69 | $ 70 | Ft 71 | kr 72 | ‎₹ 73 | Rp 74 | 75 | ع.د 76 | 77 | $ 78 | د.ا 79 | 80 | Sh 81 | د.ك 82 | лв 83 | 84 | Ls 85 | ل.ل 86 | L 87 | $ 88 | ل.د 89 | Lt 90 | P 91 | ден 92 | Ar 93 | MK 94 | RM 95 | ރ. 96 | UM 97 | 98 | $ 99 | L 100 | 101 | د.م. 102 | MTn 103 | K 104 | $ 105 | 106 | ƒ 107 | $ 108 | $ 109 | C$ 110 | 111 | 112 | kr 113 | ر.ع. 114 | 115 | B/. 116 | K 117 | 118 | S/. 119 | 120 | 121 | ر.ق 122 | L 123 | руб. 124 | Fr 125 | £ 126 | 127 | T 128 | Db 129 | ر.س 130 | дин. or din. 131 | 132 | Le 133 | $ 134 | $ 135 | Sh 136 | R 137 | 138 | Rs 139 | جنيه سوداني 140 | $ 141 | L 142 | kr 143 | ل.س 144 | ЅМ 145 | Sh 146 | ฿ 147 | T$ 148 | $ 149 | د.ت 150 | TL 151 | m 152 | Sh 153 | 154 | د.إ 155 | $ 156 | лв 157 | Vt 158 | Bs F 159 | 160 | Fr 161 | 162 | ZK 163 | $ 164 | 165 | -------------------------------------------------------------------------------- /spec/files/Actions.getExitPageTitles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 138 6 | 128 7 | 275 8 | 12619 9 | 111 10 | 115 11 | 749 12 | 37877 13 | 39 14 | 57 15 | 58 16 | 91 17 | 34% 18 | 42% 19 | 20 | 21 | 22 | 93 23 | 81 24 | 389 25 | 19655 26 | 28 27 | 37 28 | 230 29 | 17946 30 | 9 31 | 43 32 | 46 33 | 211 34 | 24% 35 | 49% 36 | 37 | 38 | 39 | 49 40 | 46 41 | 53 42 | 1133 43 | 41 44 | 44 45 | 47 46 | 372 47 | 42 48 | 45 49 | 48 50 | 23 51 | 95% 52 | 98% 53 | 54 | 55 | 56 | 22 57 | 22 58 | 23 59 | 918 60 | 22 61 | 22 62 | 25 63 | 921 64 | 19 65 | 22 66 | 22 67 | 42 68 | 86% 69 | 100% 70 | 71 | 72 | 73 | 22 74 | 15 75 | 82 76 | 4696 77 | 4 78 | 5 79 | 22 80 | 368 81 | 3 82 | 5 83 | 7 84 | 213 85 | 60% 86 | 32% 87 | 88 | -------------------------------------------------------------------------------- /spec/files/Actions.getEntryPageTitles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 138 6 | 128 7 | 275 8 | 12619 9 | 111 10 | 115 11 | 749 12 | 37877 13 | 39 14 | 57 15 | 58 16 | 91 17 | 34% 18 | 42% 19 | 20 | 21 | 22 | 93 23 | 81 24 | 389 25 | 19655 26 | 28 27 | 37 28 | 230 29 | 17946 30 | 9 31 | 43 32 | 46 33 | 211 34 | 24% 35 | 49% 36 | 37 | 38 | 39 | 49 40 | 46 41 | 53 42 | 1133 43 | 41 44 | 44 45 | 47 46 | 372 47 | 42 48 | 45 49 | 48 50 | 23 51 | 95% 52 | 98% 53 | 54 | 55 | 56 | 22 57 | 22 58 | 23 59 | 918 60 | 22 61 | 22 62 | 25 63 | 921 64 | 19 65 | 22 66 | 22 67 | 42 68 | 86% 69 | 100% 70 | 71 | 72 | 73 | 22 74 | 15 75 | 82 76 | 4696 77 | 4 78 | 5 79 | 22 80 | 368 81 | 3 82 | 5 83 | 7 84 | 213 85 | 60% 86 | 32% 87 | 88 | -------------------------------------------------------------------------------- /spec/files/Actions.getEntryPageUrls.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 108 6 | 105 7 | 133 8 | 5083 9 | 95 10 | 97 11 | 687 12 | 34808 13 | 30 14 | 35 15 | 36 16 | 47 17 | 31% 18 | 33% 19 | http://forum.piwik.org/ 20 | 21 | 22 | 23 | 77 24 | 68 25 | 175 26 | 8727 27 | 11 28 | 18 29 | 168 30 | 14012 31 | 3 32 | 28 33 | 29 34 | 113 35 | 17% 36 | 38% 37 | http://forum.piwik.org/list.php?2 38 | 39 | 40 | 41 | 44 42 | 41 43 | 47 44 | 370 45 | 41 46 | 44 47 | 47 48 | 372 49 | 42 50 | 41 51 | 44 52 | 8 53 | 95% 54 | 100% 55 | http://forum.piwik.org/read.php?6,17251,17251 56 | 57 | 58 | 59 | 31 60 | 26 61 | 49 62 | 1526 63 | 6 64 | 7 65 | 29 66 | 315 67 | 3 68 | 6 69 | 6 70 | 49 71 | 43% 72 | 19% 73 | http://forum.piwik.org/index.php 74 | 75 | 76 | 77 | 26 78 | 26 79 | 61 80 | 3025 81 | 3 82 | 3 83 | 4 84 | 9 85 | 2 86 | 6 87 | 6 88 | 116 89 | 67% 90 | 23% 91 | http://forum.piwik.org/login.php 92 | 93 | -------------------------------------------------------------------------------- /spec/files/Actions.getExitPageUrls.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 108 6 | 105 7 | 133 8 | 5083 9 | 95 10 | 97 11 | 687 12 | 34808 13 | 30 14 | 35 15 | 36 16 | 47 17 | 31% 18 | 33% 19 | http://forum.piwik.org/ 20 | 21 | 22 | 23 | 77 24 | 68 25 | 175 26 | 8727 27 | 11 28 | 18 29 | 168 30 | 14012 31 | 3 32 | 28 33 | 29 34 | 113 35 | 17% 36 | 38% 37 | http://forum.piwik.org/list.php?2 38 | 39 | 40 | 41 | 44 42 | 41 43 | 47 44 | 370 45 | 41 46 | 44 47 | 47 48 | 372 49 | 42 50 | 41 51 | 44 52 | 8 53 | 95% 54 | 100% 55 | http://forum.piwik.org/read.php?6,17251,17251 56 | 57 | 58 | 59 | 31 60 | 26 61 | 49 62 | 1526 63 | 6 64 | 7 65 | 29 66 | 315 67 | 3 68 | 6 69 | 6 70 | 49 71 | 43% 72 | 19% 73 | http://forum.piwik.org/index.php 74 | 75 | 76 | 77 | 26 78 | 26 79 | 61 80 | 3025 81 | 3 82 | 3 83 | 4 84 | 9 85 | 2 86 | 6 87 | 6 88 | 116 89 | 67% 90 | 23% 91 | http://forum.piwik.org/login.php 92 | 93 | -------------------------------------------------------------------------------- /spec/files/UserSettings.getOSFamily.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 653 6 | 713 7 | 1643 8 | 47 9 | 110373 10 | 497 11 | 40 12 | plugins/UserSettings/images/os/WXP.gif 13 | 14 | 15 | 16 | 139 17 | 152 18 | 294 19 | 31 20 | 21920 21 | 106 22 | 2 23 | plugins/UserSettings/images/os/MAC.gif 24 | 25 | 26 | 27 | 86 28 | 91 29 | 152 30 | 9 31 | 9600 32 | 67 33 | 0 34 | plugins/UserSettings/images/os/LIN.gif 35 | 36 | 37 | 38 | 12 39 | 13 40 | 21 41 | 8 42 | 283 43 | 11 44 | 0 45 | plugins/UserSettings/images/os/AND.gif 46 | 47 | 48 | 49 | 19 50 | 20 51 | 41 52 | 21 53 | 1676 54 | 18 55 | 2 56 | plugins/UserSettings/images/os/IPH.gif 57 | 58 | 59 | 60 | 2 61 | 2 62 | 2 63 | 1 64 | 0 65 | 2 66 | 0 67 | plugins/UserSettings/images/os/UNK.gif 68 | 69 | 70 | 71 | 1 72 | 1 73 | 5 74 | 5 75 | 100 76 | 0 77 | 0 78 | plugins/UserSettings/images/os/BSD.gif 79 | 80 | 81 | 82 | 1 83 | 1 84 | 1 85 | 1 86 | 0 87 | 1 88 | 0 89 | plugins/UserSettings/images/os/SYM.gif 90 | 91 | 92 | 93 | 2 94 | 2 95 | 2 96 | 1 97 | 0 98 | 2 99 | 0 100 | plugins/UserSettings/images/os/WPH.gif 101 | 102 | -------------------------------------------------------------------------------- /lib/piwik/api_module.rb: -------------------------------------------------------------------------------- 1 | module Piwik 2 | class ApiModule < Base 3 | include Piwik::DataMethods 4 | 5 | # returns default API params, used all over the place, especially in scoped_methods 6 | def self.defaults 7 | {:period => :day, :date => Date.today, @obj.id_attr => @obj.id} 8 | end 9 | 10 | # Catch incoming method calls and try to format them and send them over to the api 11 | def self.method_missing(method, *args, &block) 12 | formatted_method = method.to_s.camelize(:lower) 13 | formatted_method = formatted_method.gsub(/ip$/i,'IP').gsub(/os/i,'OS') # Lame 14 | # connect to API if this is a valid-looking method in the current class context 15 | if @available_methods.include?(formatted_method) 16 | handle_api_call(formatted_method, args.first) 17 | else 18 | super 19 | end 20 | end 21 | 22 | # allows the addition of scoped methods. It's basically a class << self wrapper 23 | # mostly added to make ApiModule code more self-explanatory 24 | # the @obj instance variable is set in the api_scope call. This is not very clean or anything, 25 | # and I am still researching a better way to do it, 26 | # but the Piwik::Site API is certainly much better to work with due to this 27 | def self.scoped_methods(&block) 28 | if block_given? 29 | extension = Module.new(&block) 30 | self.extend(extension) 31 | end 32 | end 33 | 34 | def self.available_methods method_array 35 | @available_methods = method_array 36 | @available_methods.each do |method| 37 | class_eval %{ 38 | class #{self.api_call_to_const(method)} < Piwik::ApiResponse 39 | end 40 | }, __FILE__, __LINE__ 41 | end 42 | end 43 | 44 | def self.api_call_to_const string, full = false 45 | # We can get rid of the get prefix 46 | string = case string 47 | when /[A-Z]{1}[a-z]*\.[get|add|delete|save]$/,'get','add','delete','save' 48 | string.camelize 49 | else 50 | string.gsub(/get|save|add|delete/, '') 51 | end 52 | string = string.split('.').map {|s| s.camelize }.join('::') 53 | full ? "Piwik::#{string}" : string 54 | end 55 | protected 56 | # Attempt an API call request 57 | def self.handle_api_call method, params 58 | method_name = "#{self.to_s.gsub('Piwik::','')}.#{method}" 59 | config = load_config_from_file 60 | xml = self.call(method_name, params, config[:piwik_url], config[:auth_token]) 61 | data = (xml.is_a?(String) && xml.is_binary_data?) ? xml : XmlSimple.xml_in(xml, {'ForceArray' => false}) 62 | if data.is_a?(String) && data.is_binary_data? 63 | api_call_to_const(method_name,true).constantize.new(:data => [], :value => data) 64 | elsif data.is_a?(String) 65 | api_call_to_const(method_name,true).constantize.new(:data => [], :value => data) 66 | elsif data['row'].present? 67 | api_call_to_const(method_name,true).constantize.new(:data => data['row']) 68 | elsif data.is_a?(Hash) 69 | api_call_to_const(method_name,true).constantize.new(:data => data) 70 | else 71 | api_call_to_const(method_name,true).constantize.new(:data => []) 72 | end 73 | end 74 | 75 | # Attempt an API call request 76 | def self.api_call method, params 77 | method_name = "#{self.to_s.gsub('Piwik::','')}.#{method}" 78 | config = load_config_from_file 79 | if params.is_a?(OpenStruct) 80 | params = params.marshal_dump 81 | end 82 | xml = self.call(method_name, params, config[:piwik_url], config[:auth_token]) 83 | data = XmlSimple.xml_in(xml, {'ForceArray' => false}) 84 | if data.is_a?(String) 85 | data 86 | elsif data['row'].present? 87 | data['row'] 88 | elsif data.is_a?(Hash) and data['success'].is_a?(Hash) 89 | true 90 | elsif data.is_a?(Hash) 91 | data 92 | else 93 | [] 94 | end 95 | end 96 | end 97 | end -------------------------------------------------------------------------------- /spec/files/Provider.getProvider.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 187 6 | 213 7 | 492 8 | 50 9 | 31414 10 | 150 11 | 14 12 | http://matomo.org/faq/general/faq_52 13 | 14 | 15 | 16 | 44 17 | 46 18 | 100 19 | 14 20 | 5705 21 | 30 22 | 3 23 | https://startpage.com/do/search?q=t-dialin.net 24 | 25 | 26 | 27 | 22 28 | 23 29 | 83 30 | 12 31 | 7760 32 | 13 33 | 8 34 | http://www.airtelbroadband.in/ 35 | 36 | 37 | 38 | 17 39 | 20 40 | 34 41 | 4 42 | 1765 43 | 12 44 | 1 45 | http://www.comcast.net/ 46 | 47 | 48 | 49 | 14 50 | 15 51 | 38 52 | 14 53 | 2380 54 | 9 55 | 0 56 | https://startpage.com/do/search?q=arcor-ip.net 57 | 58 | 59 | 60 | 15 61 | 15 62 | 26 63 | 6 64 | 1820 65 | 9 66 | 0 67 | https://startpage.com/do/search?q=t-ipconnect.de 68 | 69 | 70 | 71 | 12 72 | 14 73 | 57 74 | 11 75 | 4895 76 | 5 77 | 1 78 | http://matomo.org/faq/general/faq_52 79 | 80 | 81 | 82 | 11 83 | 14 84 | 50 85 | 31 86 | 4162 87 | 10 88 | 3 89 | http://www.btcentralplus.com/ 90 | 91 | 92 | 93 | 10 94 | 14 95 | 23 96 | 4 97 | 418 98 | 9 99 | 0 100 | http://www.mediaways.net/ 101 | 102 | 103 | 104 | 13 105 | 13 106 | 23 107 | 5 108 | 1326 109 | 8 110 | 0 111 | http://www.superkabel.de/ 112 | 113 | -------------------------------------------------------------------------------- /spec/files/Referrers.getSearchEngines.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 638 6 | 654 7 | 1131 8 | 102 9 | 71888 10 | 502 11 | 12 | 13 | 8 14 | 8 15 | 24 16 | 17 | 18 | 10 19 | 10 20 | 10 21 | 22 | 23 | 3 24 | 3 25 | 3 26 | 27 | 28 | 21 29 | 37 30 | http://google.com 31 | plugins/Referers/images/searchEngines/google.com.png 32 | 116 33 | 34 | 35 | 36 | 3 37 | 3 38 | 5 39 | 3 40 | 111 41 | 2 42 | 0 43 | http://search.conduit.com 44 | plugins/Referers/images/searchEngines/search.conduit.com.png 45 | 114 46 | 47 | 48 | 49 | 2 50 | 2 51 | 2 52 | 1 53 | 0 54 | 2 55 | 0 56 | http://images.google.com 57 | plugins/Referers/images/searchEngines/images.google.com.png 58 | 117 59 | 60 | 61 | 62 | 2 63 | 2 64 | 3 65 | 2 66 | 355 67 | 1 68 | 0 69 | http://search.yahoo.com 70 | plugins/Referers/images/searchEngines/search.yahoo.com.png 71 | 118 72 | 73 | 74 | 75 | 2 76 | 2 77 | 3 78 | 2 79 | 7 80 | 1 81 | 0 82 | http://images.yandex.ru 83 | plugins/Referers/images/searchEngines/images.yandex.ru.png 84 | 119 85 | 86 | 87 | 88 | 1 89 | 1 90 | 1 91 | 1 92 | 0 93 | 1 94 | 0 95 | http://bing.com 96 | plugins/Referers/images/searchEngines/bing.com.png 97 | 113 98 | 99 | 100 | 101 | 1 102 | 1 103 | 1 104 | 1 105 | 0 106 | 1 107 | 0 108 | http://search.daum.net 109 | plugins/Referers/images/searchEngines/search.daum.net.png 110 | 115 111 | 112 | -------------------------------------------------------------------------------- /spec/site_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'Piwik::Site' do 3 | before do 4 | stub_api_calls 5 | end 6 | 7 | subject { build(:site) } 8 | its(:main_url) { should eq('http://test.local') } 9 | its(:name) { should eq('Test Site') } 10 | its(:config) { should eq({:piwik_url => PIWIK_URL, :auth_token => PIWIK_TOKEN}) } 11 | 12 | it { 13 | subject.save.should eq(true) 14 | subject.name = 'Karate Site' 15 | subject.update.should eq(true) 16 | subject.destroy.should eq(true) 17 | } 18 | 19 | describe 'with wrong id' do 20 | before {Piwik::SitesManager.stub(:call).with('SitesManager.getSiteFromId',{:idSite => 666}, /.*/, /.*/).and_return('0')} 21 | 22 | xit { expect {Piwik::Site.load(666)}.to raise_error } 23 | end 24 | 25 | it { subject.seo_info.first['rank'].to_i.should eq(7) } 26 | 27 | describe '#annotations' do 28 | subject { build(:site).annotations } 29 | 30 | it { subject.all.size.should eq(2) } 31 | it { expect { subject.update(1,{:pattern => 2}) }.not_to raise_error } 32 | it { expect { subject.delete(1) }.not_to raise_error } 33 | it { subject.add(:name => 'test', :note => 'meah', :starred => 1).size.should eq(6) } 34 | it { expect { subject.count_for_dates }.not_to raise_error } 35 | 36 | end 37 | 38 | describe '#visits' do 39 | subject { build(:site).visits } 40 | 41 | it { subject.summary.should be_a(Piwik::VisitsSummary) } 42 | it { subject.count.should eq(200) } 43 | it { subject.actions.should eq(55) } 44 | it { subject.uniques.should eq(100) } 45 | it { subject.bounces.should eq(51) } 46 | it { subject.converted.should eq(0) } 47 | it { subject.max_actions.should eq(66) } 48 | it { subject.length.should eq(143952) } 49 | it { subject.pretty_length.should eq("1 days 15 hours") } 50 | end 51 | 52 | describe '#actions' do 53 | subject { build(:site).actions } 54 | 55 | it { subject.summary.should be_a(Piwik::Actions) } 56 | it { subject.urls.size.should eq(7) } 57 | it { subject.entry_urls.size.should eq(5) } 58 | it { subject.exit_urls.size.should eq(5) } 59 | it { subject.downloads.size.should eq(2) } 60 | it { subject.outlinks.size.should eq(11) } 61 | it { subject.outlink('http://mysite.com').exit_nb_visits.should eq(5) } 62 | end 63 | 64 | describe '#referrers' do 65 | subject { build(:site).referrers } 66 | 67 | it { subject.websites.size.should eq(27) } 68 | it { subject.websites_count.should eq(27) } 69 | it { subject.keywords.size.should eq(10) } 70 | it { subject.keywords_for_title('A page title').size.should eq(1) } 71 | it { subject.keywords_for_url('http://mysite.com/page.html').size.should eq(5) } 72 | it { subject.keywords_count.should eq(207) } 73 | it { subject.search_engines.size.should eq(7) } 74 | it { subject.search_engines_count.should eq(7) } 75 | it { subject.socials.size.should eq(0) } 76 | end 77 | 78 | describe '#goals' do 79 | subject { build(:site).goals } 80 | 81 | it { subject.all.size.should eq(3) } 82 | it { subject.load(1).nb_conversions.should eq(82) } 83 | it { expect { subject.update(1,{:pattern => 2}) }.not_to raise_error } 84 | it { expect { subject.delete(1) }.not_to raise_error } 85 | it { expect { subject.add(:name => 'test', 'matchAttribute' => '/', :pattern => '/', :patternType => 1) }.not_to raise_error } 86 | end 87 | 88 | describe '#transitions' do 89 | subject { build(:site).transitions } 90 | 91 | it { subject.for_action('name','type').should be_a(Piwik::Transitions::TransitionsForAction) } 92 | it { subject.for_title('My page title').should be_a(Piwik::Transitions::TransitionsForPageTitle) } 93 | it { subject.for_url('http://mysite.com').should be_a(Piwik::Transitions::TransitionsForPageUrl) } 94 | it { subject.translations.size.should eq(32) } 95 | end 96 | 97 | describe "that exists" do 98 | before { 99 | @site = build(:site) 100 | @site.save 101 | } 102 | it { expect {Piwik::Site.load(@site.id)}.to_not raise_error } 103 | end 104 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Autometal-Piwik [![Build Status](https://travis-ci.org/piwik/piwik-ruby-api.png?branch=master)](https://travis-ci.org/piwik/piwik-ruby-api) [![Gem Version](https://badge.fury.io/rb/autometal-piwik.png)](http://badge.fury.io/rb/autometal-piwik) 2 | 3 | This is now the official Ruby client for Piwik. It completely covers the Piwik API and should be easily extendable by users. We made no assumptions on how you want to use your data, so we closely mirrored Piwik's API structure even if it looks kinda weird to a modern rubyist. 4 | 5 | We will also implement an extended `Piwik::Site` wrapper class that will give you ruby-friendly access to a lot of the data in a way we think is sane, but it will be up to you which interface you want to use. 6 | 7 | **Please note that this release is not backward compatible. People using an older version of this gem should stick with version 0.6.1** 8 | 9 | ## Features 10 | * Simple ruby-friendly api 11 | * Full API implementation 12 | * `piwik-terminal` binary, allowing shell access. 13 | * Works on MRI Jruby and RBX 1.8.* and 1.9.* 14 | * Tested 15 | 16 | ## Installation 17 | 18 | Add this line to your application's Gemfile: 19 | 20 | gem 'autometal-piwik', :require => 'piwik' 21 | 22 | And then execute: 23 | 24 | $ bundle 25 | 26 | Or install it yourself as: 27 | 28 | $ gem install autometal-piwik 29 | 30 | ## Usage 31 | ### Use the binary 32 | Open an extended irb session to a Piwik installation: 33 | 34 | $ piwik-console -u http://demo.piwik.org -t anonymous 35 | :001 > Site.load 7 36 | #=> # 37 | 38 | ### Initialize it 39 | Unless you are using the binary, or if you are using the binary without credentials, you need to specify a url and a security token. 40 | 41 | Piwik::PIWIK_URL = 'http://demo.piwik.org' 42 | Piwik::PIWIK_TOKEN = 'anonymous' 43 | 44 | This can take place in your script or a rails initializer or whatever. 45 | 46 | ### Use the wrapper class 47 | Fastest way to get to know the client is by using the Piwik::Site wrapper class: 48 | 49 | site = Piwik::Site.load(7) 50 | #=> # 51 | 52 | site.annotations.all 53 | #=> # 54 | site.annotations.add(:date => 'today', :starred => 1) 55 | #=> Piwik::ApiError: Please specify a value for 'note'. 56 | site.annotations.add(:note => 'meep', :date => 'today', :starred => 1) 57 | #=> # 58 | 59 | summary = site.actions.summary 60 | #=> # 61 | summary.nb_pageviews 62 | #=> 236 63 | summary.nb_uniq_pageviews 64 | #=> 170 65 | 66 | Not all methods are implemented on the wrapper class, although if you find yourself adding methods, please submit a pull request. 67 | You can have a look at [site_spec.rb](https://github.com/piwik/piwik-ruby-api/blob/master/spec/site_spec.rb) for an up-to-date list of available methods. 68 | 69 | ### Use the 'native' API 70 | This client also allows you to interact with the API the way its designers wanted it. Any method in the [api reference](http://piwik.org/docs/analytics-api/reference/) is made available almost verbatim: 71 | 72 | # http://piwik.org/docs/analytics-api/reference/#Actions 73 | # Actions.getPageUrls (idSite, period, date, segment = '', expanded = '', idSubtable = '') 74 | require 'rubygems' 75 | require 'piwik' 76 | Piwik::PIWIK_URL = 'http://demo.piwik.org' 77 | Piwik::PIWIK_TOKEN = 'anonymous' 78 | Piwik::Actions.getPageUrls(:idSite => 7, :period => :day, :date => 'yesterday') 79 | #=> # 80 | 81 | That last call is exactly the same as calling `site.actions.page_urls(:period => :day, :date => 'yesterday')` 82 | 83 | It is probably apparent, but the second way gives you full access to everything, all you need is the API reference and you're off. If you are simply after displaying the basic analytics values for a site, the wrapper is probably the way to go. 84 | 85 | For more information on Piwik and it’s API, see the [Piwik website](http://piwik.org) and the [Piwik API reference](http://piwik.org/docs/analytics-api/reference/). 86 | 87 | ## Contributing 88 | 89 | 1. Fork it 90 | 2. Create your feature branch (`git checkout -b my-new-feature`) 91 | 3. Commit your changes (`git commit -am 'Add some feature'`) 92 | 4. Push to the branch (`git push origin my-new-feature`) 93 | 5. Create new Pull Request 94 | -------------------------------------------------------------------------------- /spec/files/UserCountry.getCountry.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 167 6 | 179 7 | 414 8 | 47 9 | 28379 10 | 116 11 | 12 | 13 | 2 14 | 2 15 | 6 16 | 17 | 18 | 4 19 | 4 20 | 4 21 | 22 | 23 | 6 24 | 10 25 | de 26 | plugins/UserCountry/flags/de.png 27 | 16 28 | 11 29 | 30 | 31 | 32 | 147 33 | 154 34 | 325 35 | 31 36 | 25297 37 | 116 38 | 39 | 40 | 3 41 | 3 42 | 9 43 | 44 | 45 | 2 46 | 2 47 | 2 48 | 49 | 50 | 1 51 | 1 52 | 1 53 | 54 | 55 | 6 56 | 12 57 | us 58 | plugins/UserCountry/flags/us.png 59 | 16 60 | 11 61 | 62 | 63 | 64 | 84 65 | 86 66 | 231 67 | 25 68 | 9029 69 | 64 70 | 71 | 72 | 11 73 | 11 74 | 33 75 | 76 | 77 | 10 78 | 10 79 | 10 80 | 81 | 82 | 1 83 | 1 84 | 1 85 | 86 | 87 | 22 88 | 44 89 | in 90 | plugins/UserCountry/flags/in.png 91 | 16 92 | 11 93 | 94 | 95 | 96 | 44 97 | 52 98 | 84 99 | 7 100 | 6622 101 | 38 102 | 0 103 | fr 104 | plugins/UserCountry/flags/fr.png 105 | 16 106 | 11 107 | 108 | 109 | 110 | 36 111 | 50 112 | 182 113 | 27 114 | 15351 115 | 28 116 | 117 | 118 | 3 119 | 3 120 | 9 121 | 122 | 123 | 5 124 | 5 125 | 5 126 | 127 | 128 | 2 129 | 2 130 | 2 131 | 132 | 133 | 10 134 | 16 135 | ca 136 | plugins/UserCountry/flags/ca.png 137 | 16 138 | 11 139 | 140 | 141 | 142 | 40 143 | 46 144 | 60 145 | 3 146 | 5776 147 | 35 148 | 0 149 | gb 150 | plugins/UserCountry/flags/gb.png 151 | 16 152 | 11 153 | 154 | -------------------------------------------------------------------------------- /spec/files/Referrers.getKeywords.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 436 6 | 450 7 | 687 8 | 31 9 | 44731 10 | 350 11 | 12 | 13 | 4 14 | 4 15 | 12 16 | 17 | 18 | 5 19 | 5 20 | 5 21 | 22 | 23 | 3 24 | 3 25 | 3 26 | 27 | 28 | 12 29 | 20 30 | 126 31 | 32 | 33 | 34 | 6 35 | 6 36 | 6 37 | 1 38 | 0 39 | 6 40 | 0 41 | 123 42 | 43 | 44 | 45 | 1 46 | 2 47 | 2 48 | 1 49 | 0 50 | 2 51 | 0 52 | 131 53 | 54 | 55 | 56 | 2 57 | 2 58 | 2 59 | 1 60 | 0 61 | 2 62 | 0 63 | 153 64 | 65 | 66 | 67 | 2 68 | 2 69 | 25 70 | 21 71 | 3798 72 | 0 73 | 0 74 | 254 75 | 76 | 77 | 78 | 1 79 | 2 80 | 2 81 | 1 82 | 0 83 | 2 84 | 0 85 | 323 86 | 87 | 88 | 89 | 1 90 | 1 91 | 1 92 | 1 93 | 0 94 | 1 95 | 0 96 | 127 97 | 98 | 99 | 100 | 1 101 | 1 102 | 1 103 | 1 104 | 0 105 | 1 106 | 0 107 | 128 108 | 109 | 110 | 111 | 1 112 | 1 113 | 7 114 | 7 115 | 647 116 | 0 117 | 118 | 119 | 1 120 | 1 121 | 3 122 | 123 | 124 | 1 125 | 1 126 | 1 127 | 128 | 129 | 2 130 | 4 131 | 129 132 | 133 | 134 | 135 | 1 136 | 1 137 | 1 138 | 1 139 | 0 140 | 1 141 | 0 142 | 130 143 | 144 | 145 | -------------------------------------------------------------------------------- /spec/files/Events.getName.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 5 6 | 142 7 | 0 8 | 0 9 | 0 10 | 0 11 | 5 12 | 0 13 | eventName==Name1 14 | 2 15 | 16 | 17 | 18 | 5 19 | 25 20 | 0 21 | 0 22 | 0 23 | 0 24 | 5 25 | 0 26 | eventName==Name2 27 | 1 28 | 29 | 30 | 31 | 4 32 | 8 33 | 0 34 | 0 35 | 0 36 | 0 37 | 4 38 | 0 39 | eventName==Name3 40 | 10 41 | 42 | 43 | 44 | 4 45 | 8 46 | 0 47 | 0 48 | 0 49 | 0 50 | 4 51 | 0 52 | eventName==Name4 53 | 11 54 | 55 | 56 | 57 | 3 58 | 3 59 | 0 60 | 0 61 | 0 62 | 0 63 | 3 64 | 0 65 | eventName==Name5 66 | 7 67 | 68 | 69 | 70 | 3 71 | 3 72 | 0 73 | 0 74 | 0 75 | 0 76 | 3 77 | 0 78 | eventName==Name6 79 | 13 80 | 81 | 82 | 83 | 3 84 | 3 85 | 0 86 | 0 87 | 0 88 | 0 89 | 3 90 | 0 91 | eventName==Name7 92 | 6 93 | 94 | 95 | 96 | 3 97 | 3 98 | 0 99 | 0 100 | 0 101 | 0 102 | 3 103 | 0 104 | eventName==Name8 105 | 12 106 | 107 | 108 | 109 | 3 110 | 9 111 | 0 112 | 0 113 | 0 114 | 0 115 | 3 116 | 0 117 | eventName==Name9 118 | 16 119 | 120 | 121 | 122 | 3 123 | 4 124 | 0 125 | 0 126 | 0 127 | 0 128 | 3 129 | 0 130 | eventName==Name10 131 | 14 132 | 133 | -------------------------------------------------------------------------------- /spec/files/Actions.getPageUrls.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 108 6 | 105 7 | 133 8 | 5083 9 | 95 10 | 97 11 | 687 12 | 34808 13 | 30 14 | 35 15 | 36 16 | 47 17 | 31% 18 | 33% 19 | http://forum.piwik.org/ 20 | 21 | 22 | 23 | 77 24 | 68 25 | 175 26 | 8727 27 | 11 28 | 18 29 | 168 30 | 14012 31 | 3 32 | 28 33 | 29 34 | 113 35 | 17% 36 | 38% 37 | http://forum.piwik.org/list.php?2 38 | 39 | 40 | 41 | 44 42 | 41 43 | 47 44 | 370 45 | 41 46 | 44 47 | 47 48 | 372 49 | 42 50 | 41 51 | 44 52 | 8 53 | 95% 54 | 100% 55 | http://forum.piwik.org/read.php?6,17251,17251 56 | 57 | 58 | 59 | 31 60 | 26 61 | 49 62 | 1526 63 | 6 64 | 7 65 | 29 66 | 315 67 | 3 68 | 6 69 | 6 70 | 49 71 | 43% 72 | 19% 73 | http://forum.piwik.org/index.php 74 | 75 | 76 | 77 | 26 78 | 26 79 | 61 80 | 3025 81 | 3 82 | 3 83 | 4 84 | 9 85 | 2 86 | 6 87 | 6 88 | 116 89 | 67% 90 | 23% 91 | http://forum.piwik.org/login.php 92 | 93 | 94 | 95 | 25 96 | 24 97 | 48 98 | 3064 99 | 4 100 | 4 101 | 19 102 | 1059 103 | 2 104 | 4 105 | 4 106 | 123 107 | 50% 108 | 16% 109 | http://forum.piwik.org/register.php 110 | 111 | 112 | 113 | 22 114 | 22 115 | 23 116 | 918 117 | 22 118 | 22 119 | 25 120 | 921 121 | 19 122 | 20 123 | 20 124 | 42 125 | 86% 126 | 91% 127 | http://forum.piwik.org/read.php?2,74422 128 | 129 | --------------------------------------------------------------------------------