dynata-rex


Namedynata-rex JSON
Version 1.3.1 PyPI version JSON
download
home_pagehttps://github.com/dynata/rex-sdk-python
SummaryPackage for building and interacting with the Dynata Respondent Exchange (REX)
upload_time2023-07-11 17:47:46
maintainer
docs_urlNone
authorREX Maintainers
requires_python
license
keywords respondent exchange rex smor dynata python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # rex-sdk-python

Package for building and interacting with the Dynata Respondent Exchange (REX)

---

## Quickstart:

---

### _**Opportunity Registry**_

#### Instantiate a Registry Client

```py
from dynata_rex import OpportunityRegistry
registry = OpportunityRegistry('rex_access_key', 'rex_secret_key')
```

#### List opportunity notifications from the registry

```py
opportunities = registry.receive_notifications()


# [Opportunity(id=1,...), Opportunity(id=2,...), Opportunity(id=1,...)]
```

#### Convert an opportunity to JSON

```py
opportunity_json = Opportunity.json()
```

#### Acknowledge a list of notifications from the registry

```py
registry.ack_notifications([opportunity_1.id, ..., opportunity_N.id])
```
#### Acknowledge a single notification from the registry
```
registry.ack_notification(opportunity.id)
```

#### Get a list of corresponding opportunities from a project_id

```py
corresponding = registry.list_project_opportunities(opportunity.project_id)

# [12345, 45678, 78901]
```

#### Download a collection from a collection-type targeting cell

```py
data = registry.download_collection(cell.collection_id)
```

---

### _**Respondent Gateway**_

#### Instantiate a RespondentGateway Client

```py
from dynata_rex import RespondentGateway
gateway = RespondentGateway('rex_access_key', 'rex_secret_key')
```

#### Create a survey link for your respondent

```py
url = 'https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en'

signed_link = gateway.create_respondent_url(url,
                                            '1990-01-01',
                                            'male',
                                            '90210',
                                            'very-unique-respondent-id',

                                            ttl=60)
# https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en&birth_date=1990-01-01&gender=male&postal_code=90210&respondent_id=very-unique-respondent-id&access_key=rex_access_key&expiration=2021-11-29T15:35:12.993Z&signature=4353e8c4ca8f8fb75530214ac78139b55ca3f090438c639476b8584afe1396e6
```

#### Add additional query parameters to a link that will be present on return from survey

```py
url = 'https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en'

custom_params = {
    'custom_parameter': 'custom_value',
    'another_custom_parameter': 'another_custom_value'
}

signed_link = gateway.create_respondent_url(url,
                                            '1990-01-01',
                                            'male',
                                            '90210',
                                            'very-unique-respondent-id',
                                            additional_params=custom_params,
                                            ttl=60)

# https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en&custom_parameter=custom_value&another_custom_parameter=another_custom_value&birth_date=1990-01-01&gender=male&postal_code=90210&respondent_id=very-unique-respondent-id&access_key=rex_access_key&expiration=2021-12-02T13:48:55.759Z&signature=cf443326b73fb8af14c590e18d79a970fc3f73327c2d140c324ee1ce3020d064
```

#### Sign an inbound /start link with your credentials

```py
url = 'https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en'
signed_url = gateway.sign_url(url)

# "https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en&access_key=rex_access_key&expiration=2021-11-24T16:12:06.070Z&signature=fa8b5cac82d34bcf8026904b353349db5b1b871f735e07a601389cb6da2d744d"
```

#### Generate a URL-quoted signed url

```py
signed_url = gateway.sign_url(url, url_quoting=True)

# 'https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en&access_key=rex_access_key&expiration=2021-11-24T16%3A12%3A35.991Z&signature=4219cf63406ae429d94dbe9c33027816c264c1e2bf1edbadd2510eb9bf2351c3'
```

### Verify a signed /end link URL with your credentials

##### Valid URL

```py
# Termination Endlink
end_url = "https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=2&status=1&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z&signature=d351ff102b3ae6252d47fd54b859ecaf38c2701f214c233848bbdf64c0bc7fe1"

gateway.verify_url(end_url)

# True
```

##### Missing Signature

```py
missing_signature = "https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=2&status=1&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z"

gateway.verify_url(missing_signature)

# False
```

##### Altered Parameters (Term --> Complete Attempt)

```py
# Disposition changed to 1 (from 2) and status to 0 (from 1)

altered_parameters = "https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=1&status=0&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z&signature=d351ff102b3ae6252d47fd54b859ecaf38c2701f214c233848bbdf64c0bc7fe1"

gateway.verify_url(altered_parameters)

# False
```

##### Get Disposition of a Survey from Endlink

```py
termination = "https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=2&status=1&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z&signature=d351ff102b3ae6252d47fd54b859ecaf38c2701f214c233848bbdf64c0bc7fe1"

disposition = gateway.get_respondent_disposition(termination)

# <GatewayDispositionsEnum.TERMINATION: 2>

disposition.name

# 'TERMINATION'

disposition.value

# 2
```

##### Get Disposition + Status of a Survey from Endlink

```py
termination = "https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=2&status=1&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z&signature=d351ff102b3ae6252d47fd54b859ecaf38c2701f214c233848bbdf64c0bc7fe1"

status = gateway.get_respondent_status(termination)

#<GatewayStatusEnum.TERMINATION_DYNATA: (<GatewayDispositionsEnum.TERMINATION: 2>, 1)>

status.name

# 'TERMINATION_DYNATA'

status.value

# (<GatewayDispositionsEnum.TERMINATION: 2>, 1)
```

##### Create a context

```py
context_id = 'super-unique-ctx-id'
data = {
    'ctx': 'parent-context-id',           # From survey link 'ctx' parameter
    'gender': 'male',
    'birth_data': '1999-09-09',
    'postal_code': '90210'
}
gateway.create_context(context_id, data)

# 'super-unique-ctx-id'
```

##### Retrieve a context

```py
gateway.get_context('super-unique-ctx-id')

# {
#    'id': 'super-unique-ctx-id',
#    'items': {
#        'ctx': 'parent-context-id',
#        'gender': 'male',
#        'birth_data': '1999-09-09',
#        'postal_code': '90210'
#     }
# }
```

##### Expire a context

```py
gateway.expire_context('super-unique-ctx-id')

# {
#    'id': 'super-unique-ctx-id',
#    'items': {
#        'ctx': 'parent-context-id',
#        'gender': 'male',
#        'birth_data': '1999-09-09',
#        'postal_code': '90210'
#     },
#     'expiration': '2021-11-30T16:10:44Z'
# }
```

##### List Attributes

```py
gateway.list_attributes('country', 'page_number', 'page_size')

# {
#    'data':
#    [
#       {
#           'active': true,
#           'parameter_id": 402
#       }
#    ]
# }
```

##### Get Attribute Info

```py
gateway.get_attribute_info('attribute-id')

# {
#   'id': 402,
#   'name': "This Parameter",
#   'description': "Details of what this is",
#   'display_mode: "N" (Optional),
#   'parent_dependencies':
#   [
#       'answer_ids':
#       [
#           { 12 }
#       ],
#       'parameter_id':403
#   ],
#   'expiration_duration': 36000 (Optional),
#   'is_active': true,
#   'countries':
#   [
#       { "US" }
#   ],
#   'question': (Optional)
#   {
#       'text': "How much wood can a woodchuck?",
#       'translations':
#       [
#           {
#               'locale': "BG",
#               'text': "Other Language"
#           }
#       ]
#   }
#   'answers':
#   [
#       {
#           'id': 99,
#           'text': "A ton",
#           'countries':
#           [
#               { "US" }
#           ],
#           'translations':
#           [
#               {
#                   'locale': "GB",
#                   'text': "Other language"
#           ]
#       }
#   ]
# }
```

#### put respondent

```python
from dynata_rex.models import PutRespondentRequest, Attribute

respondent = PutRespondentRequest(
    respondent_id="respondent_id",
    gender="gender", # str | None
    country="country",
    language="language",
    birth_date="birth_date", # str | None
    attributes= [Attribute(attribute_id=111, answers=[111, 222, 333])],
    postal_code="postal_code" # str | None
)

gateway.put_respondent(respondent)
```

#### put respondent answers

```python
from dynata_rex.models import PutRespondentAnswersRequest, Attribute

respondent_answers = PutRespondentAnswersRequest(
    respondent_id="respondent_id",
    attributes= [Attribute(attribute_id=111, answers=[111, 222, 333])]
)

gateway.put_respondent_answers(respondent_answers)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dynata/rex-sdk-python",
    "name": "dynata-rex",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "respondent exchange rex smor dynata python",
    "author": "REX Maintainers",
    "author_email": "tech.supply@Dynata.com",
    "download_url": "https://files.pythonhosted.org/packages/22/10/c9ec5ecd816b72335abed48f1b589ac81b18de45fe4eb93ec23b7a683ed3/dynata_rex-1.3.1.tar.gz",
    "platform": "Any",
    "description": "# rex-sdk-python\n\nPackage for building and interacting with the Dynata Respondent Exchange (REX)\n\n---\n\n## Quickstart:\n\n---\n\n### _**Opportunity Registry**_\n\n#### Instantiate a Registry Client\n\n```py\nfrom dynata_rex import OpportunityRegistry\nregistry = OpportunityRegistry('rex_access_key', 'rex_secret_key')\n```\n\n#### List opportunity notifications from the registry\n\n```py\nopportunities = registry.receive_notifications()\n\n\n# [Opportunity(id=1,...), Opportunity(id=2,...), Opportunity(id=1,...)]\n```\n\n#### Convert an opportunity to JSON\n\n```py\nopportunity_json = Opportunity.json()\n```\n\n#### Acknowledge a list of notifications from the registry\n\n```py\nregistry.ack_notifications([opportunity_1.id, ..., opportunity_N.id])\n```\n#### Acknowledge a single notification from the registry\n```\nregistry.ack_notification(opportunity.id)\n```\n\n#### Get a list of corresponding opportunities from a project_id\n\n```py\ncorresponding = registry.list_project_opportunities(opportunity.project_id)\n\n# [12345, 45678, 78901]\n```\n\n#### Download a collection from a collection-type targeting cell\n\n```py\ndata = registry.download_collection(cell.collection_id)\n```\n\n---\n\n### _**Respondent Gateway**_\n\n#### Instantiate a RespondentGateway Client\n\n```py\nfrom dynata_rex import RespondentGateway\ngateway = RespondentGateway('rex_access_key', 'rex_secret_key')\n```\n\n#### Create a survey link for your respondent\n\n```py\nurl = 'https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en'\n\nsigned_link = gateway.create_respondent_url(url,\n                                            '1990-01-01',\n                                            'male',\n                                            '90210',\n                                            'very-unique-respondent-id',\n\n                                            ttl=60)\n# https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en&birth_date=1990-01-01&gender=male&postal_code=90210&respondent_id=very-unique-respondent-id&access_key=rex_access_key&expiration=2021-11-29T15:35:12.993Z&signature=4353e8c4ca8f8fb75530214ac78139b55ca3f090438c639476b8584afe1396e6\n```\n\n#### Add additional query parameters to a link that will be present on return from survey\n\n```py\nurl = 'https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en'\n\ncustom_params = {\n    'custom_parameter': 'custom_value',\n    'another_custom_parameter': 'another_custom_value'\n}\n\nsigned_link = gateway.create_respondent_url(url,\n                                            '1990-01-01',\n                                            'male',\n                                            '90210',\n                                            'very-unique-respondent-id',\n                                            additional_params=custom_params,\n                                            ttl=60)\n\n# https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en&custom_parameter=custom_value&another_custom_parameter=another_custom_value&birth_date=1990-01-01&gender=male&postal_code=90210&respondent_id=very-unique-respondent-id&access_key=rex_access_key&expiration=2021-12-02T13:48:55.759Z&signature=cf443326b73fb8af14c590e18d79a970fc3f73327c2d140c324ee1ce3020d064\n```\n\n#### Sign an inbound /start link with your credentials\n\n```py\nurl = 'https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en'\nsigned_url = gateway.sign_url(url)\n\n# \"https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en&access_key=rex_access_key&expiration=2021-11-24T16:12:06.070Z&signature=fa8b5cac82d34bcf8026904b353349db5b1b871f735e07a601389cb6da2d744d\"\n```\n\n#### Generate a URL-quoted signed url\n\n```py\nsigned_url = gateway.sign_url(url, url_quoting=True)\n\n# 'https://respondent.fake.rex.dynata.com/start?ctx=XXXX&language=en&access_key=rex_access_key&expiration=2021-11-24T16%3A12%3A35.991Z&signature=4219cf63406ae429d94dbe9c33027816c264c1e2bf1edbadd2510eb9bf2351c3'\n```\n\n### Verify a signed /end link URL with your credentials\n\n##### Valid URL\n\n```py\n# Termination Endlink\nend_url = \"https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=2&status=1&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z&signature=d351ff102b3ae6252d47fd54b859ecaf38c2701f214c233848bbdf64c0bc7fe1\"\n\ngateway.verify_url(end_url)\n\n# True\n```\n\n##### Missing Signature\n\n```py\nmissing_signature = \"https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=2&status=1&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z\"\n\ngateway.verify_url(missing_signature)\n\n# False\n```\n\n##### Altered Parameters (Term --> Complete Attempt)\n\n```py\n# Disposition changed to 1 (from 2) and status to 0 (from 1)\n\naltered_parameters = \"https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=1&status=0&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z&signature=d351ff102b3ae6252d47fd54b859ecaf38c2701f214c233848bbdf64c0bc7fe1\"\n\ngateway.verify_url(altered_parameters)\n\n# False\n```\n\n##### Get Disposition of a Survey from Endlink\n\n```py\ntermination = \"https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=2&status=1&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z&signature=d351ff102b3ae6252d47fd54b859ecaf38c2701f214c233848bbdf64c0bc7fe1\"\n\ndisposition = gateway.get_respondent_disposition(termination)\n\n# <GatewayDispositionsEnum.TERMINATION: 2>\n\ndisposition.name\n\n# 'TERMINATION'\n\ndisposition.value\n\n# 2\n```\n\n##### Get Disposition + Status of a Survey from Endlink\n\n```py\ntermination = \"https://respondent.fake.rex.dynata.com/end?ctx=XXXX&transaction_id=123456&disposition=2&status=1&access_key=rex_access_key&expiration=2021-11-24T19:23:23.439Z&signature=d351ff102b3ae6252d47fd54b859ecaf38c2701f214c233848bbdf64c0bc7fe1\"\n\nstatus = gateway.get_respondent_status(termination)\n\n#<GatewayStatusEnum.TERMINATION_DYNATA: (<GatewayDispositionsEnum.TERMINATION: 2>, 1)>\n\nstatus.name\n\n# 'TERMINATION_DYNATA'\n\nstatus.value\n\n# (<GatewayDispositionsEnum.TERMINATION: 2>, 1)\n```\n\n##### Create a context\n\n```py\ncontext_id = 'super-unique-ctx-id'\ndata = {\n    'ctx': 'parent-context-id',           # From survey link 'ctx' parameter\n    'gender': 'male',\n    'birth_data': '1999-09-09',\n    'postal_code': '90210'\n}\ngateway.create_context(context_id, data)\n\n# 'super-unique-ctx-id'\n```\n\n##### Retrieve a context\n\n```py\ngateway.get_context('super-unique-ctx-id')\n\n# {\n#    'id': 'super-unique-ctx-id',\n#    'items': {\n#        'ctx': 'parent-context-id',\n#        'gender': 'male',\n#        'birth_data': '1999-09-09',\n#        'postal_code': '90210'\n#     }\n# }\n```\n\n##### Expire a context\n\n```py\ngateway.expire_context('super-unique-ctx-id')\n\n# {\n#    'id': 'super-unique-ctx-id',\n#    'items': {\n#        'ctx': 'parent-context-id',\n#        'gender': 'male',\n#        'birth_data': '1999-09-09',\n#        'postal_code': '90210'\n#     },\n#     'expiration': '2021-11-30T16:10:44Z'\n# }\n```\n\n##### List Attributes\n\n```py\ngateway.list_attributes('country', 'page_number', 'page_size')\n\n# {\n#    'data':\n#    [\n#       {\n#           'active': true,\n#           'parameter_id\": 402\n#       }\n#    ]\n# }\n```\n\n##### Get Attribute Info\n\n```py\ngateway.get_attribute_info('attribute-id')\n\n# {\n#   'id': 402,\n#   'name': \"This Parameter\",\n#   'description': \"Details of what this is\",\n#   'display_mode: \"N\" (Optional),\n#   'parent_dependencies':\n#   [\n#       'answer_ids':\n#       [\n#           { 12 }\n#       ],\n#       'parameter_id':403\n#   ],\n#   'expiration_duration': 36000 (Optional),\n#   'is_active': true,\n#   'countries':\n#   [\n#       { \"US\" }\n#   ],\n#   'question': (Optional)\n#   {\n#       'text': \"How much wood can a woodchuck?\",\n#       'translations':\n#       [\n#           {\n#               'locale': \"BG\",\n#               'text': \"Other Language\"\n#           }\n#       ]\n#   }\n#   'answers':\n#   [\n#       {\n#           'id': 99,\n#           'text': \"A ton\",\n#           'countries':\n#           [\n#               { \"US\" }\n#           ],\n#           'translations':\n#           [\n#               {\n#                   'locale': \"GB\",\n#                   'text': \"Other language\"\n#           ]\n#       }\n#   ]\n# }\n```\n\n#### put respondent\n\n```python\nfrom dynata_rex.models import PutRespondentRequest, Attribute\n\nrespondent = PutRespondentRequest(\n    respondent_id=\"respondent_id\",\n    gender=\"gender\", # str | None\n    country=\"country\",\n    language=\"language\",\n    birth_date=\"birth_date\", # str | None\n    attributes= [Attribute(attribute_id=111, answers=[111, 222, 333])],\n    postal_code=\"postal_code\" # str | None\n)\n\ngateway.put_respondent(respondent)\n```\n\n#### put respondent answers\n\n```python\nfrom dynata_rex.models import PutRespondentAnswersRequest, Attribute\n\nrespondent_answers = PutRespondentAnswersRequest(\n    respondent_id=\"respondent_id\",\n    attributes= [Attribute(attribute_id=111, answers=[111, 222, 333])]\n)\n\ngateway.put_respondent_answers(respondent_answers)\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Package for building and interacting with the Dynata Respondent Exchange (REX)",
    "version": "1.3.1",
    "project_urls": {
        "Homepage": "https://github.com/dynata/rex-sdk-python"
    },
    "split_keywords": [
        "respondent",
        "exchange",
        "rex",
        "smor",
        "dynata",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4eb5065543554d7bca2afef672c0bb6e8cf16243fe0a89a45df673d3dfadb09c",
                "md5": "6f0aa2f61fa84f4509f223c01a02f230",
                "sha256": "b0b8184387589ce31289d2bc5d632c7b7fe315535e9d33884ce986448b444fc1"
            },
            "downloads": -1,
            "filename": "dynata_rex-1.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6f0aa2f61fa84f4509f223c01a02f230",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 27369,
            "upload_time": "2023-07-11T17:47:44",
            "upload_time_iso_8601": "2023-07-11T17:47:44.584741Z",
            "url": "https://files.pythonhosted.org/packages/4e/b5/065543554d7bca2afef672c0bb6e8cf16243fe0a89a45df673d3dfadb09c/dynata_rex-1.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2210c9ec5ecd816b72335abed48f1b589ac81b18de45fe4eb93ec23b7a683ed3",
                "md5": "64362835c2e1a0b7781082050b6c4db5",
                "sha256": "c82d4806fb32d04526b9097d710e004d0a7060d23d5a6c1362b3f342b22e4d48"
            },
            "downloads": -1,
            "filename": "dynata_rex-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "64362835c2e1a0b7781082050b6c4db5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 25959,
            "upload_time": "2023-07-11T17:47:46",
            "upload_time_iso_8601": "2023-07-11T17:47:46.202963Z",
            "url": "https://files.pythonhosted.org/packages/22/10/c9ec5ecd816b72335abed48f1b589ac81b18de45fe4eb93ec23b7a683ed3/dynata_rex-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-11 17:47:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dynata",
    "github_project": "rex-sdk-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "dynata-rex"
}
        
Elapsed time: 0.09556s