这是我在python中所做的。
import json
from google.appengine.api import urlfetch
from firebase_token_generator import create_token
#FIREBASE EXTRACT
#Using urlfetch because Appengine does not use requests to talk to firebase.
def firebase_leads():
leads_str = urlfetch.fetch(FIREBASE_URL + 'leads/.json?auth=' +\
token,\
method=urlfetch.GET)
leads = json.loads(leads_str.content)
return leads
def get_pipedrive_person_id(leads):
person = {
'name' : leads['FIRST_NAME'] + ' ' + leads['LAST_NAME'],
'email': [leads['EMAIL']],
'phone': [leads['PHONE']]
}
person_send = urlfetch.fetch(PIPEDRIVE_URL + '/persons?api_token=' +\
PIPEDRIVE_SECRET,\
payload=json.dumps(person),\
method=urlfetch.POST,
headers={'Content-Type': 'application/json'})
if person_send.status_code > 210:
print 'something is not right with the Pipedrive API. Status code: '
print person_send.status_code
else:
person_content = json.loads(person_send.content)
return person_content['data']['id']
@app.route('/leads')
def check_for_leads():
"""Get leads dictionary and send it to Pipedrive."""
leads = firebase_leads()
import pdb; pdb.set_trace()
print leads
for i in leads:
person_id = get_pipedrive_person_id(leads[i])
update = pipedrive_deals(leads[i], person_id)
if 400 < update.status_code > 600:
return str(update.status_code)
return str(update.status_code)
以下是支持leads
提取的Firebase规则。
{
"rules": {
"leads": {
".write": true,
".read": "auth.uid === 'lead_checker'",
"$lead_id": {
".read": "data.child('CREATED').val() > (now - 120000)",
".validate": "root.child('leads'+'/'+$lead_id).exists() && root.child('leads'+'/'+$lead_id).hasChildren(['CREATED','EMAIL', 'FIRST_NAME', 'LAST_NAME', 'LEAD_DESCRIPTION', 'PHONE'])"
}
}
}
}
当我运行模拟器时,我无法对.read
的{{1}}进行身份验证,因为它会在$lead_id
中对auth.uid==='lead_checker'
进行更高级验证。
如何使用leads
验证leads
的孙子?
在.val('CREATED') > (now - 120000)
.validate
$lead_id
时,.write: true
下的leads
规则是否有效?