Show More
@@ -11,18 +11,20 b' with JSON protocol both ways. An url to ' | |||
|
11 | 11 | <your_server>/_admin/api |
|
12 | 12 | |
|
13 | 13 | |
|
14 |
All clients |
|
|
14 | All clients are required to send JSON-RPC spec JSON data:: | |
|
15 | 15 | |
|
16 | { | |
|
16 | { | |
|
17 | "id:<id>, | |
|
17 | 18 |
|
|
18 | 19 | "method":"<method_name>", |
|
19 | 20 | "args":{"<arg_key>":"<arg_val>"} |
|
20 | 21 | } |
|
21 | 22 | |
|
22 | 23 | Example call for autopulling remotes repos using curl:: |
|
23 | curl https://server.com/_admin/api -X POST -H 'content-type:text/plain' --data-binary '{"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repo":"CPython"}}' | |
|
24 | curl https://server.com/_admin/api -X POST -H 'content-type:text/plain' --data-binary '{"id":1,"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repo":"CPython"}}' | |
|
24 | 25 | |
|
25 | 26 | Simply provide |
|
27 | - *id* A value of any type, which is used to match the response with the request that it is replying to. | |
|
26 | 28 | - *api_key* for access and permission validation. |
|
27 | 29 | - *method* is name of method to call |
|
28 | 30 | - *args* is an key:value list of arguments to pass to method |
@@ -32,9 +34,10 b' Simply provide' | |||
|
32 | 34 | api_key can be found in your user account page |
|
33 | 35 | |
|
34 | 36 | |
|
35 |
RhodeCode API will return always a JSON |
|
|
37 | RhodeCode API will return always a JSON-RPC response:: | |
|
36 | 38 | |
|
37 | { | |
|
39 | { | |
|
40 | "id":<id>, | |
|
38 | 41 |
|
|
39 | 42 | "error": null |
|
40 | 43 | } |
@@ -50,6 +50,7 b' class JSONRPCError(BaseException):' | |||
|
50 | 50 | |
|
51 | 51 | def __init__(self, message): |
|
52 | 52 | self.message = message |
|
53 | super(JSONRPCError, self).__init__() | |
|
53 | 54 | |
|
54 | 55 | def __str__(self): |
|
55 | 56 | return str(self.message) |
@@ -60,7 +61,7 b' def jsonrpc_error(message, code=None):' | |||
|
60 | 61 | Generate a Response object with a JSON-RPC error body |
|
61 | 62 | """ |
|
62 | 63 | from pylons.controllers.util import Response |
|
63 | resp = Response(body=json.dumps(dict(result=None, error=message)), | |
|
64 | resp = Response(body=json.dumps(dict(id=None, result=None, error=message)), | |
|
64 | 65 | status=code, |
|
65 | 66 | content_type='application/json') |
|
66 | 67 | return resp |
@@ -117,6 +118,7 b' class JSONRPCController(WSGIController):' | |||
|
117 | 118 | # check AUTH based on API KEY |
|
118 | 119 | try: |
|
119 | 120 | self._req_api_key = json_body['api_key'] |
|
121 | self._req_id = json_body['id'] | |
|
120 | 122 | self._req_method = json_body['method'] |
|
121 | 123 | self._req_params = json_body['args'] |
|
122 | 124 | log.debug('method: %s, params: %s', |
@@ -220,7 +222,8 b' class JSONRPCController(WSGIController):' | |||
|
220 | 222 | if self._error is not None: |
|
221 | 223 | raw_response = None |
|
222 | 224 | |
|
223 |
response = dict(result=raw_response, |
|
|
225 | response = dict(id=self._req_id, result=raw_response, | |
|
226 | error=self._error) | |
|
224 | 227 | |
|
225 | 228 | try: |
|
226 | 229 | return json.dumps(response) |
General Comments 0
You need to be logged in to leave comments.
Login now