For the documentation, see https://foosoft.net/projects/anki-connect/

        :param str action:
        :param dict params:
        :param int version:
        :return:
183649
def post(action, params=None, version=6):
        
        if params is None:
            params = dict()
        to_send = {
            'action': action,
            'version': version,
            'params': params
        }

        r = requests.post(AnkiConnect.URL, json=to_send)
        return r.json()
265202
public Api getActionResult(String action, String params) throws Exception {
    Api result = this.getActionResult(action, params, null, null);
    return result;
  }
387218
def api_request(action, data, request_type, binary_key = nil)
      if !binary_key.nil?
        binary_key_data = data[binary_key]
        data.delete(binary_key)
      end

      if data[:format].nil? || data[:format] == 'json'
        data = prepare_json_payload(data)
      else
        data[:api_key] = @api_key
        data[:format] ||= 'json'
        data[:sig] = get_signature_hash(data, @secret)
      end

      if !binary_key.nil?
        data[binary_key] = binary_key_data
      end
      _result = http_request(action, data, request_type, binary_key)

      # NOTE: don't do the unserialize here
      if data[:format] == 'json'
        begin
          unserialized = JSON.parse(_result)
          return unserialized ? unserialized : _result
        rescue JSON::JSONError => e
          return {'error' => e}
        end
      end
      _result
    end
537327
def _get_action_from_method_and_request_uri(self, method, request_uri):
        

        # service response class should have 'SERVICE_NAME' class member,
        # if you want to get action from method and url
        if not hasattr(self, 'SERVICE_NAME'):
            return None
        service = self.SERVICE_NAME
        conn = boto3.client(service, region_name=self.region)

        # make cache if it does not exist yet
        if not hasattr(self, 'method_urls'):
            self.method_urls = defaultdict(lambda: defaultdict(str))
            op_names = conn._service_model.operation_names
            for op_name in op_names:
                op_model = conn._service_model.operation_model(op_name)
                _method = op_model.http['method']
                uri_regexp = self.uri_to_regexp(op_model.http['requestUri'])
                self.method_urls[_method][uri_regexp] = op_model.name
        regexp_and_names = self.method_urls[method]
        for regexp, name in regexp_and_names.items():
            match = re.match(regexp, request_uri)
            self.uri_match = match
            if match:
                return name
        return None
966560
def _begin_connection_action(self, action):
        

        connection_id = action.data['connection_id']
        internal_id = action.data['internal_id']
        callback = action.data['callback']

        # Make sure we are not reusing an id that is currently connected to something
        if self._get_connection_state(connection_id) != self.Disconnected:
            callback(connection_id, self.id, False, 'Connection ID is already in use for another connection')
            return

        if self._get_connection_state(internal_id) != self.Disconnected:
            callback(connection_id, self.id, False, 'Internal ID is already in use for another connection')
            return

        conn_data = {
            'state': self.Connecting,
            'microstate': None,
            'connection_id': connection_id,
            'internal_id': internal_id,
            'action': action,
            'context': action.data['context']
        }

        self._connections[connection_id] = conn_data
        self._int_connections[internal_id] = conn_data
431541
def _set_data(self, action):
        
        if 'query' in action:
            self._set_query_data(action)
        elif action == 'imageinfo':
            self._set_imageinfo_data()
        elif action == 'parse':
            self._set_parse_data()
        elif action == 'random':
            self._set_random_data()
        elif action == 'labels':
            self._set_labels()
        elif action == 'wikidata':
            self._set_wikidata()
            self.get_labels()
        elif action == 'restbase':
            self._set_restbase_data()

        self._update_imageinfo()
        self._update_params()
547169
def format_item(self, action, item_type='actor'):
        
        obj = getattr(action, item_type)
        return {
            'id': self.get_uri(action, obj),
            'url': self.get_url(action, obj),
            'objectType': ContentType.objects.get_for_model(obj).name,
            'displayName': text_type(obj)
        }
853620
def _begin_operation_action(self, action):
        

        conn_key = action.data['id']
        callback = action.data['callback']

        if self._get_connection_state(conn_key) != self.Idle:
            callback(conn_key, self.id, False, 'Cannot start operation, connection is not idle')
            return

        data = self._get_connection(conn_key)
        data['state'] = self.InProgress
        data['microstate'] = action.data['operation_name']
        data['action'] = action
727225
def addAction(self, action):
        
        self.ACTIONS.append(action)
        return "ACTION#{}".format(len(self.ACTIONS) - 1)
137259
def action(context, request, action=None, resource=None, uid=None):
    

    # allow to set the method via the header
    if action is None:
        action = request.get_header("HTTP_X_HTTP_METHOD_OVERRIDE", "CREATE").lower()

    # Fetch and call the action function of the API
    func_name = "{}_items".format(action)
    action_func = getattr(api, func_name, None)
    if action_func is None:
        api.fail(500, "API has no member named '{}'".format(func_name))

    portal_type = api.resource_to_portal_type(resource)
    items = action_func(portal_type=portal_type, uid=uid)

    return {
        "count": len(items),
        "items": items,
        "url": api.url_for("senaite.jsonapi.v1.action", action=action),
    }
1281906
def version(request):
    
    version_json = import_string(version_callback)(settings.BASE_DIR)
    if version_json is None:
        return HttpResponseNotFound('version.json not found')
    else:
        return JsonResponse(version_json)
659857
def _apiv1_run(self, action, headers=None, **kwargs):
        
        warnings.warn(
            "POEditor API v1 is deprecated. Use POEditorAPI._run method to call API v2",
            DeprecationWarning, stacklevel=2
        )

        url = "https://poeditor.com/api/"
        payload = kwargs
        payload.update({'action': action, 'api_token': self.api_token})

        return self._make_request(url, payload, headers)
1171979
def _validate_action_parameters(func, params):
    
    if params is not None:
        # Verify field name is valid
        valid_fields = [getattr(fields, f) for f in dir(fields) \
                if f.startswith("FIELD_")]
        for param in params:
            param_name, field_type = param['name'], param['fieldType']
            if param_name not in func.__code__.co_varnames:
                raise AssertionError("Unknown parameter name {0} specified for"\
                        " action {1}".format(
                        param_name, func.__name__))

            if field_type not in valid_fields:
                raise AssertionError("Unknown field type {0} specified for"\
                        " action {1} param {2}".format(
                        field_type, func.__name__, param_name))
1177877
def get(self, param=None, must=[APIKEY]):
        '''
        '''
        param = {} if param is None else param
        r = self.verify_param(param, must)
        if not r.is_succ():
            return r
        handle = CommonResultHandler(lambda rsp: {VERSION_V1:rsp.get(USER), VERSION_V2:rsp}[self.version()])
        return self.path('get.json').post(param, handle, r)
435882
def url_for(self, action='view', **kwargs):
        
        app = current_app._get_current_object() if current_app else None
        if app is not None and action in self.url_for_endpoints.get(app, {}):
            endpoint, paramattrs, _external = self.url_for_endpoints[app][action]
        else:
            try:
                endpoint, paramattrs, _external = self.url_for_endpoints[None][action]
            except KeyError:
                raise BuildError(action, kwargs, 'GET')
        params = {}
        for param, attr in list(paramattrs.items()):
            if isinstance(attr, tuple):
                # attr is a tuple containing:
                # 1. ('parent', 'name') --> self.parent.name
                # 2. ('**entity', 'name') --> kwargs['entity'].name
                if attr[0].startswith('**'):
                    item = kwargs.pop(attr[0][2:])
                    attr = attr[1:]
                else:
                    item = self
                for subattr in attr:
                    item = getattr(item, subattr)
                params[param] = item
            elif callable(attr):
                params[param] = attr(self)
            else:
                params[param] = getattr(self, attr)
        if _external is not None:
            params['_external'] = _external
        params.update(kwargs)  # Let kwargs override params

        # url_for from flask
        return url_for(endpoint, **params)
457606
def get(self, action, version=None):
        """"""
        by_version = self._by_action[action]
        if version in by_version:
            return by_version[version]
        else:
            return by_version[None]
732242
def action_as_json(action)
      json = {}
      json[:default_title] = action.title if action.title
      json[:default_icon] = action.icon if action.icon
      json[:default_popup] = action.popup if action.popup
      json
    end