Show More
@@ -11,18 +11,20 b' with JSON protocol both ways. An url to ' | |||||
11 | <your_server>/_admin/api |
|
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 | "api_key":"<api_key>", | |
18 | "method":"<method_name>", |
|
19 | "method":"<method_name>", | |
19 | "args":{"<arg_key>":"<arg_val>"} |
|
20 | "args":{"<arg_key>":"<arg_val>"} | |
20 | } |
|
21 | } | |
21 |
|
22 | |||
22 | Example call for autopulling remotes repos using curl:: |
|
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 | Simply provide |
|
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 | - *api_key* for access and permission validation. |
|
28 | - *api_key* for access and permission validation. | |
27 | - *method* is name of method to call |
|
29 | - *method* is name of method to call | |
28 | - *args* is an key:value list of arguments to pass to method |
|
30 | - *args* is an key:value list of arguments to pass to method | |
@@ -32,9 +34,10 b' Simply provide' | |||||
32 | api_key can be found in your user account page |
|
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 | "result": "<result>", | |
39 | "error": null |
|
42 | "error": null | |
40 | } |
|
43 | } |
@@ -50,6 +50,7 b' class JSONRPCError(BaseException):' | |||||
50 |
|
50 | |||
51 | def __init__(self, message): |
|
51 | def __init__(self, message): | |
52 | self.message = message |
|
52 | self.message = message | |
|
53 | super(JSONRPCError, self).__init__() | |||
53 |
|
54 | |||
54 | def __str__(self): |
|
55 | def __str__(self): | |
55 | return str(self.message) |
|
56 | return str(self.message) | |
@@ -60,7 +61,7 b' def jsonrpc_error(message, code=None):' | |||||
60 | Generate a Response object with a JSON-RPC error body |
|
61 | Generate a Response object with a JSON-RPC error body | |
61 | """ |
|
62 | """ | |
62 | from pylons.controllers.util import Response |
|
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 | status=code, |
|
65 | status=code, | |
65 | content_type='application/json') |
|
66 | content_type='application/json') | |
66 | return resp |
|
67 | return resp | |
@@ -117,6 +118,7 b' class JSONRPCController(WSGIController):' | |||||
117 | # check AUTH based on API KEY |
|
118 | # check AUTH based on API KEY | |
118 | try: |
|
119 | try: | |
119 | self._req_api_key = json_body['api_key'] |
|
120 | self._req_api_key = json_body['api_key'] | |
|
121 | self._req_id = json_body['id'] | |||
120 | self._req_method = json_body['method'] |
|
122 | self._req_method = json_body['method'] | |
121 | self._req_params = json_body['args'] |
|
123 | self._req_params = json_body['args'] | |
122 | log.debug('method: %s, params: %s', |
|
124 | log.debug('method: %s, params: %s', | |
@@ -220,7 +222,8 b' class JSONRPCController(WSGIController):' | |||||
220 | if self._error is not None: |
|
222 | if self._error is not None: | |
221 | raw_response = None |
|
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 | try: |
|
228 | try: | |
226 | return json.dumps(response) |
|
229 | return json.dumps(response) |
General Comments 0
You need to be logged in to leave comments.
Login now