Ejemplo n.º 1
0
def team_users(api, team_name, request=None, eid=None,
                                                save_xml=None, debug=False):
    """Retrieve details of team members.

    Parameters:

    team_name - Name of team. Should be identical to a team returned by 
                company_teams(api, 'company name')

    request   - List which limits the amount of information returned. Must be
                a subset of:

                   ['last_name', 'first_name', 'status', 'id', 'reference',
                                'is_provider', 'timezone', 'timezone_offset']

                These are the keys in the dict object(s) returned.

    eid       - oDesk user id. This is the same as the 'id' above. If given
                a list of one dict object for a team member matching 'id' is
                returned.

    Return:
    A list of one dict object if 'eid' parameter is given, or a list of N dict
    objects where N equals the number of people on the named team.
    If 'request' is not given the dict object contains all information for each
    team member.  Otherwise each item in 'request' which exactly matchs one of
    the valid identifiers given above is returned in each dict object generated.
    """
    userlist = []
    (team_ref, parent_team_ref, company_ref) = \
                                    team_reference_IDs(api, team_name, save_xml)
    if not team_ref:
        log.warning("No results from team_users(api, '{0:s}')".format(team_name))
        return userlist
    log.info("fetching team {0:s} users".format(team_name))
    url = urls.get_API_URL('team_users', team_ref=team_ref)
    log.debug('URL: {0:s}'.format(url))
    if save_xml: save_xml = 'team_users.xml'
    response = send_GET(api, url, save_xml=save_xml)
    if response is None:
        log.error("request failed: send_GET(api, {0:s}".format(url))
        return userlist
    tmplist = list_from_xml(response, 'user', debug=debug)
    if eid:
        for user in tmplist:
            if user['id'] == eid:
                userlist.append(user)
                break
    else:
        userlist = tmplist[:]
    all_info = ['last_name', 'first_name', 'status', 'id', 'reference',
                            'is_provider', 'timezone', 'timezone_offset']
    if not request:
        requested_info = all_info[:]
    else:
        requested_info = list_intersect(list(request), all_info)
    return dict_subset(userlist, requested_info)
Ejemplo n.º 2
0
def company_users(api, company_name, request=None, save_xml=None, debug=False):
    """Retrieve list of contractors working for 'company_name'

    Parameters:
    company_name - Target company of query. Should be identical to a name returned
                   by odesk.api.query.organization:companies(api, request)

    request - List which limits the amount of information returned for each user.
              Must be a subset of:
                [timezone, reference, status, timezone_offset, id,
                 is_provider, last_name, first_name]

    This ultimately depends on the success of api.query.company_details().
    That GET depends on the permissions granted to the authenticated user of
    this process- the oDesk user and password used to access the API.

    Return:
    List of dictionary objects- one per employee.
    """
    userlist = []
    details = company_details(api, company_name, save_xml=False)
    if not details:
        warn = "No results from company_details(api, '{0:s}')"
        log.warning(warn.format(company_name))
        return userlist
    log.info("fetching company {0:s} users".format(company_name))
    url = urls.get_API_URL('company_users', company_ref=details['reference'])
    log.debug('URL: {0:s}'.format(url))
    if save_xml: save_xml = 'company_users.xml'
    response = send_GET(api, url, save_xml=save_xml)
    if response is None:
        log.error("request failed: send_GET(api, {0:s}".format(url))
        return userlist
    userlist = list_from_xml(response, 'user', debug=debug)
    all_info = ['timezone', 'reference', 'status', 'timezone_offset',
                'id', 'is_provider', 'last_name', 'first_name']
    if not request:
        requested_info = all_info[:]
    else:
        requested_info = list_intersect(request, all_info)
    return dict_subset(userlist, requested_info)
Ejemplo n.º 3
0
 def save_cookies(self):
     """Save cached cookie data which has been managed by our cookie_jar."""
     if self.cookie_jar:
         self.cookie_jar.save(self.cookie_file)
     else:
         log.warning("No cookie jar, unable to save cookies.")