Exemple #1
0
    def api_list_resource(self, feed):
        data = {}

        creds = build_creds.build_credentials(
            scope=[
                "https://apps-apis.google.com/a/feeds/calendar/resource/"
            ],
            service_account_name=oauth_config['client_email'],
            private_key=oauth_config['private_key'],
            user=oauth_config['default_user']
        )
        auth2token = CreateToken(creds)
        client = CalendarResourceClient(domain=oauth_config['domain'])
        auth2token.authorize(client)

        if feed == 'feed':
            calendar_resources = str(client.GetResourceFeed())
        else:
            calendar_resources = str(client.GetResourceFeed(
                uri="https://apps-apis.google.com/a/feeds/calendar/resource/2.0/%s/?%s" % (
                    oauth_config['domain'], feed)))

        nextpage, res = self.components.calendars.find_resource(calendar_resources)
        data['items'] = res
        data['next'] = nextpage
        data['previous'] = None
        data['page'] = "start=%s" % res[0]['resourceId']

        self.context['data'] = data
Exemple #2
0
    def list_resource_memcache(self):
        params = {}
        result = []
        nextpage = None
        # client = CalendarResourceClient(domain=oauth_config['domain'])
        # client.ClientLogin(email=oauth_config['default_user'], password=oauth_config['password'], source=APP_ID)

        creds = build_creds.build_credentials(
            scope=[
                "https://apps-apis.google.com/a/feeds/calendar/resource/"
            ],
            service_account_name=oauth_config['client_email'],
            private_key=oauth_config['private_key'],
            user=oauth_config['default_user']
        )
        auth2token = CreateToken(creds)
        client = CalendarResourceClient(domain=oauth_config['domain'])
        auth2token.authorize(client)

        while True:
            if nextpage:
                params['uri'] = nextpage

            calendar_resources = str(client.GetResourceFeed(**params))
            nextpage, res = self.find_resource(calendar_resources)

            for resource in res:
                result.append(dict(
                    (k, v) for k, v in resource.iteritems()
                ))

            if not nextpage:
                break

        sortedResource = sorted(result, key=lambda resource: resource['resourceCommonName'])

        memcache.add('resource_list', sortedResource, 600)
        return sortedResource
Exemple #3
0
class CalendarResourceSample(object):
    def __init__(self, domain, email, password):
        """Constructor for the CalendarResourceSample object.

    Construct a CalendarResourceSample with the given args.

    Args:
      domain: The domain name ("domain.com")
      email: The email account of the user or the admin ("*****@*****.**")
      password: The domain admin's password
    """
        self.client = CalendarResourceClient(domain=domain)
        self.client.ClientLogin(email=email,
                                password=password,
                                source='googlecode-calendarresourcesample-v1')

    def create(self, resource_properties):
        """Creates a calendar resource with the given resource_properties
    
    Args:
      resource_properties: A dictionary of calendar resource properties
    """
        print 'Creating a new calendar resource with id %s...' % (
            resource_properties['resource_id'])
        print self.client.CreateResource(
            resource_id=resource_properties['resource_id'],
            resource_common_name=resource_properties['resource_name'],
            resource_description=resource_properties['resource_description'],
            resource_type=resource_properties['resource_type'])

    def get(self, resource_id=None):
        """Retrieves the calendar resource with the given resource_id
    
    Args:
      resource_id: The optional calendar resource identifier
    """
        if resource_id:
            print 'Retrieving the calendar resource with id %s...' % (
                resource_id)
            print self.client.GetResource(resource_id=resource_id)
        else:
            print 'Retrieving all calendar resources...'
            print self.client.GetResourceFeed()

    def update(self, resource_properties):
        """Updates the calendar resource with the given resource_properties
    
    Args:
      resource_properties: A dictionary of calendar resource properties
    """
        print 'Updating the calendar resource with id %s...' % (
            resource_properties['resource_id'])
        print self.client.UpdateResource(
            resource_id=resource_properties['resource_id'],
            resource_common_name=resource_properties['resource_name'],
            resource_description=resource_properties['resource_description'],
            resource_type=resource_properties['resource_type'])

    def delete(self, resource_id):
        """Deletes the calendar resource with the given resource_id
    
    Args:
      resource_id: The unique calendar resource identifier
    """
        print 'Deleting the calendar resource with id %s...' % (resource_id)
        self.client.DeleteResource(resource_id)
        print 'Calendar resource successfully deleted.'