# Collection of code snippets by Arne Vajhøj 
# (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import requests
import json

def invoke(urlstr, method, params):
    req = { 'method': method, 'params': params, 'jsonrpc': '2.0', 'id': 0, }
    return requests.post(urlstr, json=req).json()['result']

def test(urlstr):
    print(urlstr)
    v = invoke(urlstr, 'getInt', [])
    print(v)
    s = invoke(urlstr, 'getString', [])
    print(s)
    d = invoke(urlstr, 'getData', [])
    print(d)
    lstv = invoke(urlstr, 'getListOfInts', [])
    print(lstv)
    lsts = invoke(urlstr, 'getListOfStrings', [])
    print(lsts)
    lstd = invoke(urlstr, 'getListOfData', [])
    print(lstd)
    v1 = 123
    v2 = 456
    v3 = invoke(urlstr, 'add', [ v1, v2 ])
    print(v3)
    s1 = 'ABC'
    s2 = 'DEF'
    s3 = invoke(urlstr, 'concat', [ s1, s2 ])
    print(s3)
    d1 = { 'ival': 123, 'sval': 'ABC' }
    d2 = invoke(urlstr, 'modify', [ d1 ])
    print(d2)

test('http://localhost:8001/test')
test('http://localhost:8002/test')
test('http://localhost:8003/test')
test('http://localhost:8004/test')
test('http://localhost:8005/test')
test('http://localhost:8006/server.php')
test('http://localhost:8007/server.php')
