API di accesso Highrise con Python?
Domanda
Come posso accedere a 37 segnali API di Highrise con Python? involucri trovati per PHP / Ruby, ma non Python. Sto scrivendo la mia ora, qualcuno ha consigli su come ottenere il primo ostacolo di autenticazione con Python?
Soluzione
ho scritto (scrittura del mattino, in realtà) un involucro API Highrise per Python. Esso utilizza Python oggetti per ciascuna delle classi di grattacieli ed funziona un po 'come il 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()
È possibile ottenere la fonte da GitHub: https://github.com/feedmagnet/pyrise
O installarlo dal PyPI:
$ sudo pip install pyrise
Altri suggerimenti
Stavo affrontando questo problema quando mi sono imbattuto su sua domanda. Ecco quello che ho messo insieme finora. La sua non è abbastanza (ancora), ma funziona. Non so pycurl e dopo aver guardato per un po 'sono tornato a urllib2. Highrise utilizza l'autenticazione di base in modo da non dover usare CURL è possibile utilizzare urllib2. Non vi resta che passare attraverso tutte le fasi Pword Manager. L'uscita è un file XML lunga di entrambi tutte le aziende o le persone a seconda di quale URL si inserisce. Se si voleva solo una persona si potrebbe fare qualcosa di simile a 'http ...... / persone / 123.xml' o 'http ...... / persone / 123-fname-lname.xml' (come si vede nell'URL quando effettivamente andare a un contatto in grattacielo con l'aggiunta .xml).
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
Tutte le risposte o suggerimenti su questo il codice sarebbe utile!
qui su come fare l'autenticazione di base. Anche IIRC supporti urllib http://user:password@example.com
URL.
stavo solo cercando di codice php di uno dei php API wrapper e vedo che usano riccio; così hai guardato per pycurl ??
circa l'autenticazione ecco un esempio che si può iniziare con (non è testato) ...
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)