<commit_before><?php
/* LoyaltyLion Coupon Import API 
 *
 * @category LoyaltyLion
 * @package LoyaltyLion_CouponImport
 * @author <NAME> 
 */
class LoyaltyLion_CouponImport_Model_Api2_PriceRule_Rest_Admin_V1 extends LoyaltyLion_CouponImport_Model_Api2_PriceRule
{
    /**
     * Create shopping cart price rule
     *
     * @param array $coupons
     * @return string|void
     */
    protected function _create($priceRule)
    {
        $model = Mage::getModel('salesrule/rule');
        $model->loadPost($priceRule);
        //Codes won't actually be auto-generated by Magento.
        //We just need to set this so we can have multiple codes:
        //The codes themselves will be imported from LoyaltyLion.
        $model->setUseAutoGeneration(1);
        $model->save();
        $data = $model->toArray();
        return $data;
    }
    /**
     * Retrieve price rule
     *
     * @return array
     */
    protected function _retrieve()
    {
        $ruleId = $this->getRequest()->getParam('rule_id');
        $rule = $this->_loadSalesRule($ruleId);
        $data = $rule->toArray();
        return $data;
    }
    protected function _retrieveCollection()
    {
        //implement this
    }
    /**
     * Load sales rule by ID.
     *
     * @param int $ruleId
     * @return Mage_SalesRule_Model_Rule
     */
    protected function _loadSalesRule($ruleId)
    {
        if (!$ruleId) {
            $this->_critical(Mage::helper('salesrule')
                ->__('Rule ID not specified.'), Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
        }
        $rule = Mage::getModel('salesrule/rule')->load($ruleId);
        if (!$rule->getId()) {
            $this->_critical(Mage::helper('salesrule')
                ->__('Rule was not found.'), Mage_Api2_Model_Server::HTTP_NOT_FOUND);
        }
        return $rule;
    }
}
<commit_msg>Return new rule URL in Location header<commit_after><?php
/* LoyaltyLion Coupon Import API 
 *
 * @category LoyaltyLion
 * @package LoyaltyLion_CouponImport
 * @author <NAME> 
 */
class LoyaltyLion_CouponImport_Model_Api2_PriceRule_Rest_Admin_V1 extends LoyaltyLion_CouponImport_Model_Api2_PriceRule
{
    /**
     * Create shopping cart price rule
     *
     * @param array $coupons
     * @return string|void
     */
    protected function _create($priceRule)
    {
        $model = Mage::getModel('salesrule/rule');
        $model->loadPost($priceRule);
        //Codes won't actually be auto-generated by Magento.
        //We just need to set this so we can have multiple codes:
        //The codes themselves will be imported from LoyaltyLion.
        $model->setUseAutoGeneration(1);
        $model->save();
        $data = $model->getData();
        $id = $data['rule_id'];
        //I can't find a method to give this URL so this could totally break easily :(
        return "/api/rest/loyaltylion/rules/{$id}";
    }
    /**
     * Retrieve price rule
     *
     * @return array
     */
    protected function _retrieve()
    {
        $ruleId = $this->getRequest()->getParam('rule_id');
        $rule = $this->_loadSalesRule($ruleId);
        $data = $rule->toArray();
        return $data;
    }
    protected function _retrieveCollection()
    {
        //implement this
    }
    /**
     * Load sales rule by ID.
     *
     * @param int $ruleId
     * @return Mage_SalesRule_Model_Rule
     */
    protected function _loadSalesRule($ruleId)
    {
        if (!$ruleId) {
            $this->_critical(Mage::helper('salesrule')
                ->__('Rule ID not specified.'), Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
        }
        $rule = Mage::getModel('salesrule/rule')->load($ruleId);
        if (!$rule->getId()) {
            $this->_critical(Mage::helper('salesrule')
                ->__('Rule was not found.'), Mage_Api2_Model_Server::HTTP_NOT_FOUND);
        }
        return $rule;
    }
}

{'fraction_non_alphanumeric': 0.12713178294573643, 'fraction_numerical': 0.0031007751937984496, 'mean_word_length': 2.357328707718994, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1119049', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1189, 'n_words': 259}