Pythonで37シグナルHighriseのAPIにアクセスするにはどうすればよいですか?PHP / Rubyのラッパーが見つかりましたが、Pythonは見つかりませんでした。私は今自分で書いていますが、Pythonでの認証の最初のハードルを乗り越えるためのアドバイスはありますか?
4 に答える
私は Python 用の Highrise API ラッパーを書きました (実際に書いています)。各 Highrise クラスに Python オブジェクトを使用し、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()
ソースは GitHub から入手できます: https://github.com/feedmagnet/pyrise
または、PyPI からインストールします。
$ sudo pip install pyrise
あなたの質問に出くわしたとき、私はちょうどこの問題に取り組んでいました。これが私がこれまでに一緒にハッキングしたものです。(まだ)きれいではありませんが、機能します。私は Pycurl を知らないので、しばらく見てから urllib2 に戻りました。Highrise は Basic 認証を使用するため、urllib2 を使用できる CURL を使用する必要はありません。Pword Manager のすべての手順を実行するだけです。出力は、挿入した URL に応じて、すべての企業または人物の長い XML ファイルです。1 人だけが必要な場合は、'http....../people/123.xml' または 'http....../people/123-fname-lname.xml' のようにすることができます (ご覧のとおり.xmlが追加された高層ビルの連絡先に実際にアクセスしたときのURLで)。
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
このコードに関するフィードバックや提案は役に立ちます!
PHP API ラッパーの 1 つの php コードを調べたところ、それらが curl を使用していることがわかります。だからあなたは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)
基本認証の方法については、こちらを参照してください。また、IIRC urllib はhttp://user:password@example.com
URL をサポートしています。