LoginSignup
2
2

More than 5 years have passed since last update.

rubyからopenXのAPIを叩く

Posted at

openXのAPIを叩くにはまず先にログインする必要がある。
ここに示す例はopenXで広告主を追加するAPIを実行するrubyのスクリプトである。

広告主追加

まず『logon』メソッドを呼ぶ。
そこで戻ってきた『sessionId』を『call』メソッド第一引数として指定する。

addAdvertiser.rb
#!/usr/bin/env ruby
require 'xmlrpc/client'

login_client = XMLRPC::Client.new2('http://ホスト名/www/api/v1/xmlrpc/LogonXmlRpcService.php')
sessionId = login_client.call('logon', 'ユーザー名', 'パスワード')

client = XMLRPC::Client.new2('http://ホスト名/www/api/v1/xmlrpc/AdvertiserXmlRpcService.php')
param = {'agencyId' => 1, 'advertiserName' => '会社名', 'contactName' => '営業担当者', 'emailAddress' => 'メールアドレス', 'username' => 'ユーザー', 'password' => 'パスワード', 'comments' => 'コメント'}

client.call('addAdvertiser', sessionId ,param)


2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2