API d'accès Highrise avec Python?
Question
Comment puis-je accéder à 37 signaux API Highrise avec Python? emballages trouvés pour PHP / Ruby, mais pas Python. J'écris mon propre maintenant, quelqu'un a des conseils à obtenir sur le premier obstacle d'authentification avec Python?
La solution
J'ai écrit (écriture heures, vraiment) une enveloppe API Highrise pour Python. Il utilise des objets Python pour chacune des classes Highrise et travaille beaucoup 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
Autres conseils
Je viens de résoudre ce problème quand je suis tombé sur votre question. Voici ce que j'ai piraté ensemble à ce jour. Ce ne est pas assez (encore) mais il fonctionne. Je ne sais pas pycurl et après avoir regardé pendant un certain temps, je suis retourné à urllib2. Highrise utilise l'authentification de base de sorte que vous ne devez pas utiliser CURL vous pouvez utiliser urllib2. Il vous suffit de passer par toutes les étapes PWord Manager. La sortie est un fichier XML longue soit toutes les entreprises ou les personnes en fonction de l'URL que vous insérez. Si vous vouliez une seule personne que vous pourriez faire quelque chose comme « http ...... / personnes / 123.xml » ou « http ...... / personnes / 123-FNAME-lname.xml » (comme vous voyez dans l'url quand vous allez effectivement à un contact avec la tour d'habitation .xml ajoutée).
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!
Je viens de regarder le code php de l'un des php API wrappers et je vois qu'ils utilisent boucle; si vous avez regardé pycurl ??
à propos de l'authentification ici est un exemple 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)