def put(self, brand_id):
        if not request.json['name'].strip():
            api.abort(400)

        brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id)

        if not brand:
            api.abort(brand_service.BrandServiceResponse.DoesNotExist)

        return brand_service.update_brand_name(account_id=get_account_id(get_token()), brand=brand, change_data=request.json)
Example #2
0
    def post(self):
        brand = brand_service.get_brand_by_id(get_account_id(get_token()),
                                              request.json['brand_id'])

        if not brand:
            api.abort(404)

        # Get synonyms from brand
        synonyms = [
            synonym.synonym
            for synonym in synonym_service.get_brand_synonyms(brand.id)
        ]
        if not synonyms:
            api.abort(400)

        request_data = {
            'from': request.json['from'],
            'to': request.json['to'],
            'synonyms': synonyms
        }

        statistics_response = get_overview_statistics(
            request.json['granularity'], request_data)

        return statistics_response.json(), statistics_response.status_code
    def delete(self, brand_id):
        brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id)

        if not brand:
            api.abort(brand_service.BrandServiceResponse.DoesNotExist)

        return brand_service.delete_brand(brand)
    def get(self, brand_id):
        brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id)

        if not brand:
            api.abort(brand_service.BrandServiceResponse.DoesNotExist)

        statistics = get_brand_statistics(brand)
        return {'id': brand.id, 'name': brand.name, 'sentiment_average': statistics['sentiment_average'],
                'sentiment_trend': statistics['sentiment_trend'], 'posts': statistics['posts']}
    def get(self):
        results = []

        for brand in brand_service.get_brands_by_account(get_account_id(get_token())):
            statistics = get_brand_statistics(brand)
            results.append({'id': brand.id, 'name': brand.name, 'sentiment_average': statistics['sentiment_average'],
                            'sentiment_trend': statistics['sentiment_trend'], 'posts': statistics['posts']})

        return results
    def get(self, brand_id):
        brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id)

        if not brand:
            api.abort(brand_service.BrandServiceResponse.DoesNotExist)

        synonyms = synonym_service.get_brand_synonyms(brand.id)

        # Instead of returning the model for each synonym, we just return the synonym itself
        return [{'synonym': synonym.synonym} for synonym in synonyms]
    def post(self, brand_id):
        if not request.json['synonym'].strip():
            api.abort(400)

        brand = brand_service.get_brand_by_id(get_account_id(get_token()), brand_id)

        if not brand:
            api.abort(brand_service.BrandServiceResponse.DoesNotExist)

        return synonym_service.add_synonym(brand.id, request.json)
    def post(self):
        if not request.json['name'].strip():
            api.abort(400)

        return brand_service.create_brand(get_account_id(get_token()), request.json)