CommunitiesMixin

class squirro_client.topic.CommunitiesMixin

Bases: object

Methods Summary

create_community(project_id, …)

Create a new community.

create_or_update_communities(project_id, …)

Create or update batch of communities.

delete_community(project_id, …)

Delete a specific community from the given project.

get_communities(project_id, community_type_id)

Return all communities for the given community_type_id.

get_community(project_id, community_type_id, …)

Return a specific community from the given community_type_id.

get_community_followers(project_id, …)

Return the user details of users subscribed to the community with given community_id.

modify_community(project_id, …[, name, …])

Modify a community.

Methods Documentation

create_community(project_id, community_type_id, name, photo, facet_value)

Create a new community.

Parameters
  • project_id – Project identifier

  • community_type_id – Community type identifier

  • name – Name of the community

  • photo – Address to the photo of the community

  • facet_value – Value of the facet the community belongs to

Returns

A dictionary of the created community.

Example:

>>> client.create_community(project_id='BFXfzPHKQP2xRxAP86Kfig',
...                      community_type_id='G0Tm2SQcTqu2d4GvfyrsMg',
...                      name='Rashford',
...                      photo='https://twitter.com/MarcusRashford/photo',
...                      facet_value='Manchester United')
{u'id': u'yX-D0_oqRgSrCFoTjhmbJg',
 u'name': u'Rashford',
 u'created_at': u'2020-09-05T11:21:42',
 u'modified_at': u'2020-09-05T11:21:42',
 u'photo': u'https://twitter.com/MarcusRashford/photo',
 u'facet_value': u'Manchester United',
 }
create_or_update_communities(project_id, community_type_id, data, from_facet)

Create or update batch of communities.

Either data or from_facet must be filled in the request. Both can’t contain values at the same time. It returns the batch ID which can be used to poll for the status of the task.

Parameters
  • project_id (str) – Project identifier

  • community_type_id (str) – Community type identifier

  • data (Optional[List[Dict[str, Any]]]) – Communities data

  • from_facet (Optional[str]) – Facet name to create communities based on

Returns

A dictionary containing batch ID and message about the start of creating and updating communities.

Example:

>>> client.create_or_update_communities(
...                      project_id='BFXfzPHKQP2xRxAP86Kfig',
...                      community_type_id='G0Tm2SQcTqu2d4GvfyrsMg',
...                      data=[
...                             {"name": "Robert Lewandowski", "facet_value": "Robert Lewandowski"},
...                             {"name": "Cristiano Ronaldo", "facet_value": "Cristiano Ronaldo"},
...                         ]
...                      )
{
    'message': 'Started creating or updating batch of communities for the community type with id "G0Tm2SQcTqu2d4GvfyrsMg"',
    'batch_id': 'a4iqj_ZBTQiRhux_8XnITw',
}
delete_community(project_id, community_type_id, community_id)

Delete a specific community from the given project.

Parameters
  • project_id – Project identifier

  • community_type_id – Community type identifier

  • community_id – Community identifier

Returns

No return value.

Example:

>>> client.delete_community('BFXfzPHKQP2xRxAP86Kfig',
...                      'G0Tm2SQcTqu2d4GvfyrsMg',
...                      'yX-D0_oqRgSrCFoTjhmbJg')
get_communities(project_id, community_type_id)

Return all communities for the given community_type_id.

Parameters
  • project_id – Project identifier

  • community_type_id – Community type identifier

Returns

A list of communities.

get_community(project_id, community_type_id, community_id, verbose=False, query=None)

Return a specific community from the given community_type_id.

Parameters
  • project_id – Project identifier

  • community_type_id – Community type identifier

  • community_id – Community identifier

  • verbose – If set to True, also returns information about the number of items and subscriptions in the community, default is False

Returns

A dictionary of the given community.

Example:

>>> client.get_community('BFXfzPHKQP2xRxAP86Kfig',
...                      'G0Tm2SQcTqu2d4GvfyrsMg',
...                      'yX-D0_oqRgSrCFoTjhmbJg')
{u'id': u'yX-D0_oqRgSrCFoTjhmbJg',
 u'name': u'Rashford',
 u'created_at': u'2020-09-05T11:21:42',
 u'modified_at': u'2020-09-07T09:33:45',
 u'photo': u'https://twitter.com/MarcusRashford/photo',
 u'facet_value': u'Manchester United',
 }
get_community_followers(project_id, community_type_id, community_id)

Return the user details of users subscribed to the community with given community_id.

Parameters
  • project_id – Project identifier

  • community_type_id – Community type identifier

  • community_id – Community identifier

Returns

A list of dictionaries with user details.

Example:

>>> client.get_community_followers('BFXfzPHKQP2xRxAP86Kfig',
...                      'G0Tm2SQcTqu2d4GvfyrsMg',
...                      'yX-D0_oqRgSrCFoTjhmbJg')
[
    {u'full_name': u'Marcus Rashford',
    u'email': u'[email protected]',
    },
    .
    .
    .
    {u'full_name': u'David De Gea',
    u'email': u'[email protected]',
    }
]
modify_community(project_id, community_type_id, community_id, name=None, photo=None, facet_value=None)

Modify a community.

Parameters
  • project_id – Project identifier

  • community_type_id – Community type identifier

  • community_id – The identifier of the community to be modified

  • name – Name of the community

  • photo – Address to the photo of the community

  • facet_value – Value of the facet the community belongs to

Returns

A dictionary of the modified community.

Example:

>>> client.modify_community(project_id='BFXfzPHKQP2xRxAP86Kfig',
...                      community_type_id='G0Tm2SQcTqu2d4GvfyrsMg',
...                      community_id='yX-D0_oqRgSrCFoTjhmbJg',
...                      name='Marcus',
...                      photo='https://twitter.com/MarcusRashford/photo',
...                      facet_value='Manchester United')
{u'id': u'yX-D0_oqRgSrCFoTjhmbJg',
 u'name': u'Marcus',
 u'created_at': u'2020-09-05T11:21:42',
 u'modified_at': u'2020-09-05T13:24:40',
 u'photo': u'https://twitter.com/MarcusRashford/photo',
 u'facet_value': u'Manchester United',
 }