def testToAndFromString(self):
     entry = webmastertools.SitesEntry(
         indexed=webmastertools.Indexed(text='true'),
         crawled=webmastertools.Crawled(text='2008-09-14T08:59:28.000'),
         geolocation=webmastertools.GeoLocation(text='US'),
         preferred_domain=webmastertools.PreferredDomain(text='none'),
         crawl_rate=webmastertools.CrawlRate(text='normal'),
         enhanced_image_search=webmastertools.EnhancedImageSearch(
             text='true'),
         verified=webmastertools.Verified(text='false'),
     )
     self.assert_(entry.indexed.text == 'true')
     self.assert_(entry.crawled.text == '2008-09-14T08:59:28.000')
     self.assert_(entry.geolocation.text == 'US')
     self.assert_(entry.preferred_domain.text == 'none')
     self.assert_(entry.crawl_rate.text == 'normal')
     self.assert_(entry.enhanced_image_search.text == 'true')
     self.assert_(entry.verified.text == 'false')
     new_entry = webmastertools.SitesEntryFromString(entry.ToString())
     self.assert_(new_entry.indexed.text == 'true')
     self.assert_(new_entry.crawled.text == '2008-09-14T08:59:28.000')
     self.assert_(new_entry.geolocation.text == 'US')
     self.assert_(new_entry.preferred_domain.text == 'none')
     self.assert_(new_entry.crawl_rate.text == 'normal')
     self.assert_(new_entry.enhanced_image_search.text == 'true')
     self.assert_(new_entry.verified.text == 'false')
Esempio n. 2
0
    def AddSite(self,
                site_uri,
                uri=SITES_FEED,
                url_params=None,
                escape_params=True,
                converter=None):
        """Adds a site to Google Webmaster Tools.

        Args:
          site_uri: str URI of which site to add.
          uri: str (optional) URI to add a site.
          url_params: dict (optional) Additional URL parameters to be included
                      in the insertion request.
          escape_params: boolean (optional) If true, the url_parameters will be
                         escaped before they are included in the request.
          converter: func (optional) Function which is executed on the server's
              response before it is returned. Usually this is a function like
              SitesEntryFromString which will parse the response and turn it into
              an object.

        Returns:
          If converter is defined, the results of running converter on the server's
          response. Otherwise, it will be a SitesEntry object.
        """

        site_entry = webmastertools.SitesEntry()
        site_entry.content = atom.Content(src=site_uri)
        response = self.Post(site_entry,
                             uri,
                             url_params=url_params,
                             escape_params=escape_params,
                             converter=converter)
        if not converter and isinstance(response, atom.Entry):
            return webmastertools.SitesEntryFromString(response.ToString())
        return response
Esempio n. 3
0
    def UpdatePreferredDomain(self,
                              site_uri,
                              preferred_domain,
                              uri=SITE_TEMPLATE,
                              url_params=None,
                              escape_params=True,
                              converter=None):
        """Updates preferred domain setting of a site.

        Note that if using 'preferwww', will also need www.example.com in account to
        take effect.

        Args:
          site_uri: str URI of which site to add sitemap for.
          preferred_domain: str The preferred domain for a site. Valid values are 'none',
                            'preferwww', and 'prefernowww'.
          uri: str (optional) URI template to update a site.
               Default SITE_TEMPLATE.
          url_params: dict (optional) Additional URL parameters to be included
                      in the insertion request.
          escape_params: boolean (optional) If true, the url_parameters will be
                         escaped before they are included in the request.
          converter: func (optional) Function which is executed on the server's
              response before it is returned. Usually this is a function like
              SitemapsEntryFromString which will parse the response and turn it into
              an object.

        Returns:
          If converter is defined, the results of running converter on the server's
          response. Otherwise, it will be a SitesEntry object.
        """

        site_entry = webmastertools.SitesEntry(
            atom_id=atom.Id(text=site_uri),
            category=atom.Category(
                scheme='http://schemas.google.com/g/2005#kind',
                term=
                'http://schemas.google.com/webmasters/tools/2007#sites-info'),
            preferred_domain=webmastertools.PreferredDomain(
                text=preferred_domain))
        response = self.Put(site_entry,
                            uri % urllib.quote_plus(site_uri),
                            url_params=url_params,
                            escape_params=escape_params,
                            converter=converter)
        if not converter and isinstance(response, atom.Entry):
            return webmastertools.SitesEntryFromString(response.ToString())
        return response
Esempio n. 4
0
    def UpdateEnhancedImageSearch(self,
                                  site_uri,
                                  enhanced_image_search,
                                  uri=SITE_TEMPLATE,
                                  url_params=None,
                                  escape_params=True,
                                  converter=None):
        """Updates enhanced image search setting of a site.

        Args:
          site_uri: str URI of which site to add sitemap for.
          enhanced_image_search: str The enhanced image search setting for a site.
                                 Valid values are 'true', and 'false'.
          uri: str (optional) URI template to update a site.
               Default SITE_TEMPLATE.
          url_params: dict (optional) Additional URL parameters to be included
                      in the insertion request.
          escape_params: boolean (optional) If true, the url_parameters will be
                         escaped before they are included in the request.
          converter: func (optional) Function which is executed on the server's
              response before it is returned. Usually this is a function like
              SitemapsEntryFromString which will parse the response and turn it into
              an object.

        Returns:
          If converter is defined, the results of running converter on the server's
          response. Otherwise, it will be a SitesEntry object.
        """

        site_entry = webmastertools.SitesEntry(
            atom_id=atom.Id(text=site_uri),
            category=atom.Category(
                scheme='http://schemas.google.com/g/2005#kind',
                term=
                'http://schemas.google.com/webmasters/tools/2007#sites-info'),
            enhanced_image_search=webmastertools.EnhancedImageSearch(
                text=enhanced_image_search))
        response = self.Put(site_entry,
                            uri % urllib.quote_plus(site_uri),
                            url_params=url_params,
                            escape_params=escape_params,
                            converter=converter)
        if not converter and isinstance(response, atom.Entry):
            return webmastertools.SitesEntryFromString(response.ToString())
        return response
Esempio n. 5
0
    def VerifySite(self,
                   site_uri,
                   verification_method,
                   uri=SITE_TEMPLATE,
                   url_params=None,
                   escape_params=True,
                   converter=None):
        """Requests a verification of a site.

    Args: 
      site_uri: str URI of which site to add sitemap for.
      verification_method: str The method to verify a site. Valid values are
                           'htmlpage', and 'metatag'.
      uri: str (optional) URI template to update a site.
           Default SITE_TEMPLATE.
      url_params: dict (optional) Additional URL parameters to be included
                  in the insertion request. 
      escape_params: boolean (optional) If true, the url_parameters will be
                     escaped before they are included in the request.
      converter: func (optional) Function which is executed on the server's
          response before it is returned. Usually this is a function like
          SitemapsEntryFromString which will parse the response and turn it into
          an object.

    Returns:
      If converter is defined, the results of running converter on the server's
      response. Otherwise, it will be a SitesEntry object.
    """

        site_entry = webmastertools.SitesEntry(
            atom_id=atom.Id(text=site_uri),
            category=atom.Category(
                scheme='http://schemas.google.com/g/2005#kind',
                term=
                'http://schemas.google.com/webmasters/tools/2007#sites-info'),
            verification_method=webmastertools.VerificationMethod(
                type=verification_method, in_use='true'))
        response = self.Put(site_entry,
                            uri % six.moves.urllib.parse.quote_plus(site_uri),
                            url_params=url_params,
                            escape_params=escape_params,
                            converter=converter)
        if not converter and isinstance(response, atom.Entry):
            return webmastertools.SitesEntryFromString(response.ToString())
        return response
Esempio n. 6
0
    def UpdateGeoLocation(self,
                          site_uri,
                          geolocation,
                          uri=SITE_TEMPLATE,
                          url_params=None,
                          escape_params=True,
                          converter=None):
        """Updates geolocation setting of a site.

        Args:
          site_uri: str URI of which site to add sitemap for.
          geolocation: str The geographic location. Valid values are listed in
                       http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
          uri: str (optional) URI template to update a site.
               Default SITE_TEMPLATE.
          url_params: dict (optional) Additional URL parameters to be included
                      in the insertion request.
          escape_params: boolean (optional) If true, the url_parameters will be
                         escaped before they are included in the request.
          converter: func (optional) Function which is executed on the server's
              response before it is returned. Usually this is a function like
              SitemapsEntryFromString which will parse the response and turn it into
              an object.

        Returns:
          If converter is defined, the results of running converter on the server's
          response. Otherwise, it will be a SitesEntry object.
        """

        site_entry = webmastertools.SitesEntry(
            atom_id=atom.Id(text=site_uri),
            category=atom.Category(
                scheme='http://schemas.google.com/g/2005#kind',
                term=
                'http://schemas.google.com/webmasters/tools/2007#sites-info'),
            geolocation=webmastertools.GeoLocation(text=geolocation))
        response = self.Put(site_entry,
                            uri % urllib.parse.quote_plus(site_uri),
                            url_params=url_params,
                            escape_params=escape_params,
                            converter=converter)
        if not converter and isinstance(response, atom.Entry):
            return webmastertools.SitesEntryFromString(response.ToString())
        return response