Ejemplo n.º 1
0
    def get(self, id):
        if id is None:
            p_query = filter_artifact_builds(request)

            json_data = {'meta': pagination_metadata(p_query, request.args)}
            json_data['items'] = [item.json() for item in p_query.items]

            return jsonify(json_data), 200

        else:
            build = models.ArtifactBuild.query.filter_by(id=id).first()
            if build:
                return jsonify(build.json()), 200
            else:
                return json_error(404, "Not Found", "No such build found.")
Ejemplo n.º 2
0
    def get(self, id):
        """ Returns Freshmaker Events.

        If ``id`` is set, only the Freshmaker Event defined by that ID is
        returned.

        :query string message_id: Return only events with this :ref:`message_id<event_message_id>`.
        :query string search_key: Return only events with this :ref:`search_key<event_search_key>`.
        :query number event_type_id: Return only events with this :ref:`event_type_id<event_event_type_id>`.
        :query number/string state: Return only events int this :ref:`state<event_state>`.
        :query bool show_full_json: When ``True``, the returned Freshmaker Event JSON objects
            contains all the fields described in the
            :ref:`Freshmaker Event representation for API version 1<event_json_api_1>`.

            When ``False``, the returned Freshmaker Event JSON objects are in the
            :ref:`Freshmaker Event representation for API version 2<event_json_api_2>` format.

            Default value for API version 1 is ``True``, for API version 2 is ``False``.

        :query string order_by: Order the events by the given field. If ``-`` prefix is used,
            the order will be descending. The default value is ``-id``. Available fields are:

            - :ref:`id<event_id>`
            - :ref:`message_id<event_message_id>`

        :statuscode 200: Requested events are returned.
        :statuscode 404: Freshmaker event not found.
        """
        # Boolean that is set to false if builds should not
        # be displayed in order to increase api speed
        # For API v1, this is true by default to not break the backward compatibility
        # For API v2, this is false by default
        value = request.args.getlist('show_full_json')
        show_full_json = request.base_url.find("/api/1/") != -1
        if len(value) == 1 and value[0] == 'False':
            show_full_json = False
        elif len(value) == 1 and value[0] == 'True':
            show_full_json = True

        if id is None:
            p_query = filter_events(request)

            json_data = {'meta': pagination_metadata(p_query, request.args)}

            if not show_full_json:
                json_data['items'] = [
                    item.json_min() for item in p_query.items
                ]
            else:
                json_data['items'] = [item.json() for item in p_query.items]

            return jsonify(json_data), 200

        else:
            event = models.Event.query.filter_by(id=id).first()
            if event:
                if not show_full_json:
                    return jsonify(event.json_min()), 200
                return jsonify(event.json()), 200
            else:
                return json_error(404, "Not Found", "No such event found.")