Comment puis-je accéder aux 37 signaux de l'API de Highrise avec Python? Des wrappers trouvés pour PHP/Ruby, mais pas Python. Je suis en train d'écrire le mien maintenant, quelqu'un a des conseils pour surmonter le premier obstacle de l'authentification avec Python?Accéder à l'API de Highrise avec Python?
Répondre
J'ai écrit (j'écris vraiment) un wrapper API Highrise pour Python. Il utilise des objets Python pour chacune des classes de grande hauteur et de travailler un peu comme Django ORM:
>>> from pyrise import *
>>> Highrise.server('my-server')
>>> Highrise.auth('api-key-goes-here')
>>> p = Person()
>>> p.first_name = 'Joe'
>>> p.last_name = 'Schmoe'
>>> p.save()
Vous pouvez obtenir la source de GitHub: https://github.com/feedmagnet/pyrise
Ou l'installer à partir PyPI:
$ sudo pip install pyrise
Je regardais simplement le code php de l'un des php API wrappers et je vois qu'ils utilisent curl; alors avez-vous regardé pycurl ??
sur l'authentification est un exemple ici que vous pouvez commencer avec (ce n'est pas testé) ...
import pycurl
def on_receive(data):
# process your data here
pass
def connetion(url, token)
conn = pycurl.Curl()
# Set Token.
conn.setopt(pycurl.USERPWD, "%s:x" % (token,))
# the format TOKEN:x i get it from the PHP wrapper because usually the
# format should be USER:PASSWD so here i think they just use a token as
# a USERname and they set the password to 'x'.
conn.setopt(pycurl.URL, url)
# Set the XML data to POST data.
conn.setopt(pycurl.POSTFIELDS, XML_DATA)
# Add SSL.
conn.setopt(pycurl.SSL_VERIFYPEER, 0)
conn.setopt(pycurl.SSL_VERIFYHOST, 0)
# Set function that will be called as soon as the data is received.
conn.setopt(pycurl.WRITEFUNCTION, on_receive)
# Perform the data transfer.
conn.perform()
if __name__ == '__main__':
connection("http://yourcompany.highrisehq.com", your_token)
Voir here sur la façon de faire l'authentification de base. Aussi IIRC urllib prend en charge http://user:[email protected]
URL.
J'étais justement en train de résoudre ce problème quand je suis tombé sur votre question. Voici ce que j'ai piraté ensemble jusqu'à présent. Ce n'est pas joli (encore) mais ça marche. Je ne connais pas Pycurl et après l'avoir regardé pendant un moment je suis retourné à urllib2. Highrise utilise l'authentification de base, vous n'avez donc pas besoin d'utiliser CURL, vous pouvez utiliser urllib2. Vous avez juste à passer par toutes les étapes de Pword Manager. La sortie est un long fichier XML de toutes les entreprises ou des personnes en fonction de l'URL que vous insérez. Si vous vouliez seulement une personne, vous pourriez faire quelque chose comme 'http ....../people/123.xml' ou 'http ....../people/123-fname-lname.xml' (comme vous voyez dans l'url quand vous allez à un contact dans highrise avec le .xml ajouté).
import ullib2
PEOPLEurl = 'http://yourcompany.highrisehq.com/people.xml' #get all the people
# or
COMPANYurl = 'http://yourcompany.highrisehq.com/company.xml' #get all companies
token = '12345abcd' #your token
password = 'X'
passmanager = urllib2.HTTPPasswordMgrWithDefaultRealm()
passmanager.add_password(None, PEOPLEurl, token, password)
authhandler = urllib2.HTTPBasicAuthHandler(passmanager)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
page = urllib2.urlopen(PEOPLEurl).read()
print page #this will dump out all the people contacts in highrise
Tous les commentaires ou suggestions sur ce code serait utile!
pyrise est une excellente API mais elle repose sur httplib2 qui utilise des certificats SSL * maintenant * obsolètes et qui passera par erreur par défaut - vous devrez mettre à jour votre fichier https://www.kacerts.txt httplib2 depuis - http://www.geotrust.com/resources/root_certificates/certificates/GeoTrust_Global_CA.c er – Alvin