2010-11-01 69 views
0

如何使用Python訪問37個信號Highrise的API?發現PHP/Ruby的包裝,但不是Python。我正在寫我自己的,任何人都有關於通過Python認證的第一個障礙的建議?使用Python訪問Highrise的API?

回答

4

我寫了(正在編寫,真的)一個Python的Highrise API包裝器。它使用Python對象爲每個高層類和工作帶來很多喜歡Django的ORM:一封來自PyPI https://github.com/feedmagnet/pyrise

或者安裝:

>>> 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() 

你可以從GitHub獲得源

$ sudo pip install pyrise 
+0

pyrise是一個很好的API封裝器,雖然它依賴於使用* now *過期SSL證書的httplib2,並且默認情況下會出錯 - 您需要從geotrust更新httplib2 cacerts.txt文件 - http:///www.geotrust.com/resources/root_certificates/certificates/GeoTrust_Global_CA.c呃 – Alvin 2012-03-15 00:53:03

0

我只是在尋找php API wrappers之一的php代碼,我發現它們使用了捲曲;所以你看看pycurl ??

對這裏的認證,您可以使用啓動一個例子(它未測試)...

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) 
1

當我偶然發現你的問題時,我只是解決了這個問題。這是我迄今爲止一起入侵的內容。它不漂亮(但),但它的作品。我不知道Pycurl,看了一會之後,我回到了urllib2。 Highrise使用基本身份驗證,因此您不必使用CURL即可使用urllib2。你只需要通過所有的Pword Manager步驟。輸出是所有公司或人員的長XML文件,具體取決於您插入的URL。如果你只想要一個人,你可以做'http ....../people/123.xml'或'http ....../people/123-fname-lname.xml'(就像你看到的那樣在URL中,當你實際上去了高層的聯繫人,添加了.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 

任何意見或建議,這代碼將是有益的!