Exemplo n.º 1
0
def company_relations_by_id(company_id):
    """
    Get a company relations by ID
    This endpoint returns all relations of a company by a given ID in a list format. Can be filtered.
    ---
    tags:
      - company
    parameters:
      - name: company_id
        in: path
        type: string
        description: id of company
        required: true
    responses:
      200:
        description: Returns a list of relations
        schema:
          type: array
          items:
              properties:
                source_id:
                  type: string
                  description: The source id of the relation
                relation_type:
                  type: string
                  description: The type of the relation (e.g. EMPLOYEE_OF, TWITTER_FRIEND, etc.)
                target_id:
                  type: string
                  description: The target id of the relation
                reltion_properties:
                  type: string
                  description: String with comma-separated key:value properties of this relation
    """
    company = Store.get_company_by_aid(company_id)
    if company is None:
        return 'Company with id %s not found' % company_id, 404

    relations = company.get_relations()
    data = []
    for source_aid, relation_type, target_aid, relation_properties in relations:
        # TODO: move relation_properties from string to array
        data_element = {
            'relation_type': relation_type,
            'relation_properties': relation_properties,
            'source_id': source_aid,
            'target_id': target_aid
        }
        data.append(data_element)
    response = app.response_class(response=json.dumps(data),
                                  status=200,
                                  mimetype='application/json')
    return response
Exemplo n.º 2
0
def company_properties_by_id(company_id):
    """
    Get a company properties by ID
    This endpoint returns all properties of a company by a given ID in a key/value fashion
    ---
    tags:
      - company
    parameters:
      - name: company_id
        in: path
        type: string
        description: id of company
        required: true
    responses:
      200:
        description: A single company item
        schema:
          properties:
            property-1:
              type: string
              description: A property
              default: 'value-1'
            property-2:
              type: string
              description: A property
              default: 'value-2'
            property-N:
              type: string
              description: A property
              default: 'value-N'
      404:
        description: Company not found
    """
    company = Store.get_company_by_aid(company_id)
    if company is None:
        return 'Company with id %s not found' % company_id, 404

    data = company.get_properties()
    response = app.response_class(response=json.dumps(data),
                                  status=200,
                                  mimetype='application/json')
    return response
Exemplo n.º 3
0
def person_to_company():
    """
    Get a paths from source person to target company (by IDs)
    This endpoint returns all paths leading from source person to target company via a referral
    ---
    tags:
      - paths
    parameters:
      - name: source_id
        in: query
        type: string
        description: source id of path
      - name: target_id
        in: query
        type: string
        description: target id of path
      - name: seniority
        in: query
        type: string
        enum:
          - C-Level
          - Senior
          - Not Senior
        description: Level of seniority of people leading to company
      - name: area
        in: query
        type: string
        enum:
          - Board
          - G&A
          - Communications
          - Consulting
          - Customer Service
          - Education
          - Engineering
          - Finance
          - Health Professional
          - Human Resources
          - Information Technology
          - Legal
          - Marketing
          - Operations
          - Product
          - Public Relations
          - Real Estate
          - Recruiting
          - Research
          - Sales
          - Business Development
        description: area of people we want to reach in target company
    responses:
      200:
        description: A list of paths sorted by strength. Each path contains array of segments. Each segment is made of [seg-start, relation-type, seg-end]
        schema:
          type: array
          items:
              properties:
                source_id:
                  type: string
                  description: The source id of the relation
                relation_type:
                  type: string
                  description: The type of the relation (e.g. EMPLOYEE_OF, TWITTER_FRIEND, etc.)
                target_id:
                  type: string
                  description: The target id of the relation
    """
    # Get source/target ids from request
    source_id = request.args.get('source_id', None)
    if source_id is None:
        return 'Missing source id parameter', 400
    target_id = request.args.get('target_id', None)
    if target_id is None:
        return 'Missing target id parameter', 400

    # Check that source/target exist
    if Store.get_person_by_aid(source_id) is None:
        return 'No person matching source id', 400
    if Store.get_company_by_aid(target_id) is None:
        return 'No company matching target id', 400

    # Extract seniority/area filters
    seniority = request.args.get('seniority', None)
    area = request.args.get('area', None)

    try:
        # TODO: instead of 'seniority' & 'area', we may have here a generic k/v property filter
        paths = Store.get_paths_to_company(source_id, target_id, seniority,
                                           area)
    except Exception as e:
        tb = traceback.format_exc()
        return 'Exception %s raised trying to get path. %s' % (e, tb), 500

    # Return the paths as json with code 200
    response = app.response_class(response=json.dumps(paths),
                                  status=200,
                                  mimetype='application/json')
    return response