python3 sdk与耐克服务交互
nikepysdk的Python项目详细描述
这是一个nike服务的非正式python3 api包装。在制品。
基本用法
importnikepysdknike=nikepysdk.NikeSdk()username='test@example.com'password='Password123!'access_token=nike.get_access_token(username,password)print(access_token)# Some long access tokenaccount_verified=nike.is_account_verified(access_token)print(account_verified)# True or Falseaccount_data={'email':'newaccount@example.com','password':'Password12345!','first_name':'John','last_name':'Smith','date_of_birth':'2000-01-01',# YYYY-MM-DD'gender':'male'# or female}account_created=nike.create_account(account_data)print(account_created)event=nike.get_event_by_id(88145)print(event.event_id,event.title,event.location)
sdk文档
nike.get_access_token
nike.get_access_token(username, password)
返回给定用户名和密码的帐户的访问令牌 可用于与经过身份验证的API终结点交互的。
参数
- string-帐户的用户名
- string-帐户的密码
返回
string字符串格式的访问令牌
示例
username='example@test.com'password='Password123!'access_token=nike.get_access_token(username,password)print(access_token)# Some long string
nike.create_account
nike.create_account(account_data)
根据帐户数据创建新的Nike+帐户。account_data是 具有以下模式的词典:
{ 'email': string, 'password': string, 'first_name': string, 'last_name': string, 'date_of_birth': string, # YYYY-MM-DD 'gender': string # 'male' or 'female' }
参数
- dict-帐户数据作为dict
返回
bool成功创建帐户
示例
account_data={'email':'newaccount@example.com','password':'Password12345!','first_name':'John','last_name':'Smith','date_of_birth':'2000-01-01',# YYYY-MM-DD'gender':'male'# or female}account_created=nike.create_account(account_data)print(account_created)# True, hopefully
nike.is_account_verified
nike.is_account_verified(access_token)
检查给定帐户的有效访问令牌是否验证了帐户
参数
- string-帐户访问令牌
返回
bool如果帐户已验证或未验证
示例
is_verified=nike.create_account(access_token)print(is_verified)# True, hopefully
nike.send_sms_code
nike.send_sms_code(access_token, phone_number)
向给定其访问令牌的帐户发送短信验证码,并 电话号码。
参数
- string-帐户访问令牌
- string-要向其发送代码的电话号码
返回
bool操作成功
示例
phone_number='1112223333'sms_sent=nike.send_sms_code(access_token,phone_number)print(sms_sent)# True, hopefully
nike.verify_sms_code
nike.verify_sms_code(access_token, sms_code)
验证帐户的短信代码。
参数
- string-帐户访问令牌
- string-收到的短信代码
返回
bool操作成功
示例
sms_code='123456'sms_verified=nike.verify_sms_code(access_token,sms_code)print(sms_verified)# True, hopefully
nike.add_shipping_address
nike.add_shipping_address(access_token, shipping_info)
向帐户添加新的发货地址。shipping_info是 具有以下架构的词典:
{ 'first_name': string, 'last_name': string, 'address_1': string, 'address_2': string, 'city': string, 'state': string, # Initials 'zip': string, 'phone': string, # 1112223333 }
参数
- string-帐户的访问令牌
- dict-将地址数据作为dict发送
返回
string用于添加帐单信息的地址ID
示例
shipping_info={'first_name':'John','last_name':'Smith','address_1':'123 Main Street','address_2':'APT 1A','city':'Sometown','state':'OH','zip':'12345','phone':'1234567890'}address_id=nike.add_shipping_address(access_token,shipping_info)print(address_id)# Some uuid4 string
nike.add_card
nike.add_card(access_token, card_info)
向帐户添加新卡。card_info是具有 遵循模式:
{ 'number': string, 'type': string, # VISA or similar 'exp_month': string, # XX 'exp_year': string, # XXXX 'cvv': string }
参数
- string-帐户的访问令牌
- dict-卡数据作为dict
返回
stringcard id用于添加帐单信息
示例
card_info={'number':'1111222233334444,'type':'VISA',# VISA or similar'exp_month':'12',# XX'exp_year':'2021',# XXXX'cvv':'123'}card_id=nike.add_card(access_token,card_info)print(card_id)# Some uuid4 string
nike.add_billing_info
nike.add_billing_info(access_token, access_token, billing_info, address_id, card_id)
向帐户添加新的帐单配置文件。billing_info是 具有以下架构的词典:
{ 'first_name': string, 'last_name': string, 'address_1': string, 'address_2': string, 'city': string, 'state': string, # Initials 'zip': string, 'phone': string, # 1112223333 }
address_id和card_id是由返回的ID add_shipping_address和add_card。
参数
- string-帐户的访问令牌
- dict-计费数据为dict
- string-要添加到配置文件的地址ID
- string-要添加到配置文件的卡ID
返回
bool操作成功
示例
billing_info={'first_name':'John','last_name':'Smith','address_1':'123 Main Street','address_2':'APT 1A','city':'Sometown','state':'OH','zip':'12345','phone':'1234567890'}billing_added=nike.add_billing_info(access_token,billing_info,address_id,card_id)print(billing_added)# True, hopefully
nike.get_event_by_id
nike.get_event_by_id(event_id)
返回包含事件信息的NikeEvent对象
参数
- string-id事件
返回
NikeEvent事件数据作为NikeEvento对象
示例
event_id='12345'event=nike.get_event_by_id(event_id)print(event.title)# Some string