Esempio n. 1
0
def rule_add(appname):
    '''
        create api to add rule.
        Request URL:  /appname/rule/rule/add
        Http Method: POST
        Parameters :
            {
                "title": "xxxx"
                "min_version": 0,
                "max_version": 0,
                "source":[1],
                "locale":[1],
                "operator":[1],
                "package":[1],
                "min_value": 0,
                "max_value": 0,
                "gray_scale": 100,
                "gray_start": 1
            }
        Return :
        {
            "status":0
            "data":{
                "items":[
                    {
                        "id": 1,
                        "title":"海豚英文版",
                        "min_version": 0,
                        "max_version": 0,
                        "first_created": "2015-02-05 21:37:38",
                        "last_modified": "2015-02-05 21:37:38"
                    },
                    {
                        "id": 2,
                        "title":"联通",
                        "min_version": 0,
                        "max_version": 0,
                        "first_created": "2015-02-05 21:37:38",
                        "last_modified": "2015-02-05 21:37:38"
                    }
                ]
            }
        }

    '''
    # check post data
    data = get_valid_params(request, Rule.params)
    if isinstance(data, Response):
        return data

    # check the id of  pn/op/src/lc
    rule_params = ["package", "operator", "source", "locale"]
    data = check_rule_params(appname, data, rule_params)
    if isinstance(data, Response):
        return data

    # add logic
    return create(appname, Rule, data)
Esempio n. 2
0
def rule_update(appname):
    '''
        this api is used to modify one rule
        Request URL:  /appname/rule/rule/update
        HTTP Method:POST
        Parameters:
            {
                "title": "xxxx"
                "min_version": 0,
                "max_version": 0,
                "source":[1],
                "locale":[1],
                "operator":[1],
                "package":[1],
                "min_value": 0,
                "max_value": 0,
                "gray_scale": 100,
                "gray_start": 1
            }
        Return :
        {
            "status":0
            "data":{
                "id": 1,
                "title":"海豚英文版",
                "min_version": 0,
                "max_version": 0,
                "first_created": "2015-02-05 21:37:38",
                "last_modified": "2015-02-05 21:37:38"
            }
        }
        '''
    # check post data
    required_list = list(Rule.params) + ["id&need&int", ]
    data = get_valid_params(request, required_list)
    if isinstance(data, Response):
        return data

    # check the id of  pn/op/src/lc
    rule_params = ["package", "operator", "source", "locale"]
    data = check_rule_params(appname, data, rule_params)
    if isinstance(data, Response):
        return data
    return info_mod(appname, Rule, data)