Skip to main content

用于构建 Dynata Respondent Exchange (REX) 并与之交互的软件包

项目描述

rex-sdk-python

用于构建 Dynata Respondent Exchange (REX) 并与之交互的软件包

 

快速开始:

 

机会登记处

实例化注册表客户端

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

列出来自注册表的机会通知

opportunities = registry.receive_notifications()

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

将机会转换为 JSON

opportunity_json = Opportunity.json()

确认来自注册表的通知列表

registry.ack_notifications([opportunity_1.id, ..., opportunity_N.id])

确认来自注册表的单个通知

registry.ack_notification(opportunity.id)

从 project_id 获取相应机会的列表

corresponding = registry.list_project_opportunities(opportunity.project_id)

# [12345, 45678, 78901]

从集合类型定位单元下载集合

data = registry.download_collection(cell.collection_id)

 
 

受访者网关

实例化 RespondentGateway 客户端

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

为您的受访者创建调查链接

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

将附加查询参数添加到将在调查返回时出现的链接

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

使用您的凭据签署入站 /start 链接

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"

生成引用 URL 的签名 url

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'

使用您的凭据验证签名的 /end 链接 URL

有效网址
# 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 = "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
更改的参数(Term --> Complete Attempt)
# 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
从 Endlink 获取调查结果
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
从 Endlink 获取调查的处置 + 状态
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)
创建上下文
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'
检索上下文
gw.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'
#     }
# }
使上下文过期
gw.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'
# }
列出属性
gw.list_attributes('country', 'page_number', 'page_size')

# {
#    'data':
#    [
#       {
#           'active': true,
#           'parameter_id": 402
#       }
#    ]
# }
获取属性信息
gw.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"
#           ]
#       }
#   ]
# }

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

dynata_rex-1.2.1.tar.gz (18.8 kB 查看哈希

已上传 source