Example #1
0
    def getAll(self, crud):
        if crud.location not in self.data:
            self.data[crud.location] = {}

        if crud.raw_data:
            return ctx.success(self.data[crud.location], 200)

        items = []
        for key in self.data[crud.location].keys():
            entry = crud.create_entry(self.data[crud.location][key], key)
            items.append(entry)

        return ctx.success(items, 200)
Example #2
0
 def getAll(self):
     return ctx.success(
         {
             "@context": {
                 "hydra": "http://www.w3.org/ns/hydra/core#",
                 "vocab": hydra.VOCAB_URL + "#",
                 "Event": "http://schema.org/Event",
                 "name": "http://schema.org/name",
                 "description": "http://schema.org/description",
                 "start_date": {
                     "@id": "http://schema.org/startDate",
                     "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
                 },
                 "end_date": {
                     "@id": "http://schema.org/endDate",
                     "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
                 },
                 "location": {
                     "@id": "vocab:Event/Location",
                     "@type": "@id"
                 },
                 "actor": {
                     "@id": "vocab:Event/actor",
                     "@type": "@id"
                 }
             }
         },
         200,
         headers=hydra.LINK_HEADER)
Example #3
0
    def get(self, crud):
        if crud.location not in self.data:
            self.data[crud.location] = {}

        if crud.id not in self.data[crud.location]:
            return ctx.error("Entry not found", 1, 404)

        return ctx.success(self.data[crud.location][crud.id], 200)
Example #4
0
    def delete(self, crud):
        if crud.location not in self.data:
            self.data[crud.location] = {}

        if crud.id not in self.data[crud.location]:
            return ctx.error("Entry not found", 1, 404)

        del self.data[crud.location][crud.id]

        return ctx.success()
Example #5
0
    def add(self, crud):
        if crud.location not in self.data:
            self.data[crud.location] = {}

        if crud.id in self.data[crud.location]:
            return ctx.error("Entry already exists", 1, 400)

        self.data[crud.location][crud.id] = crud.data

        return ctx.success(crud.dump(), 201)
    def getAll(self):
        payload = {
            "@context": "/api/contexts/EntryPoint.jsonld",
            "@id": "/api/",
            "@type": "EntryPoint"
        }

        for classObj in hydra.get_entrypoint_classes():
            name = classObj.getEntryPointName()
            payload[name] = classObj.resource_name + "/"

        return ctx.success(payload, 200, headers=hydra.LINK_HEADER)
    def getAll(self):
        content = templates.render({
                "base_url": ctx.base_url
            },"doc.json")
        api = json.loads(content)
        api["supportedClass"] += [obj.toJSON() for obj in hydra.get_classes()]


        for classObj in hydra.get_entrypoint_classes():
            for apiClass in api["supportedClass"]:
                if apiClass["@id"] == "vocab:EntryPoint":
                    apiClass["supportedProperty"].append(classObj.getEntryPointDoc())
                    break

        api = json.loads(json.dumps(api, default=dumper, indent=2))
        return ctx.success(api, 200, headers = hydra.LINK_HEADER)
def generic_entry_replace_action(data, id, entry_context, entry_id, entry_type,
                                 db_name):
    entry_url = "{}{}".format(ctx.base_url, entry_id.replace("<id>", id))

    data["@context"] = entry_context
    data["@id"] = entry_url
    data["@type"] = entry_type

    result = myDB.replace_(db_name, id, data)
    if isinstance(result, Response):
        return result

    headers = hydra.LINK_HEADER
    headers["location"] = entry_url
    headers["content-location"] = entry_url
    return ctx.success(data, 201, headers=headers)
    def post(self, data):
            
        id = db.next_id()    
        data["@context"] =  "/api/contexts/Event.jsonld"
        data["@id"] =  "/api/events/{}".format(id)
        data["@type"] =  "http://schema.org/Event"

        result = myDB.add_(id, "Event", data)
        if isinstance(result, Response):
            return result

        event_url = "{}/api/events/{}".format(ctx.base_url, id)
        headers = hydra.LINK_HEADER
        headers["location"] = event_url
        headers["content-location"] = event_url
        return ctx.success(data, 201, headers=headers)
def generic_collection_get_action(collection_context, collection_id,
                                  collection_type, db_name):
    result = myDB.getAll_(db_name)
    if type(result) is Response:
        return result

    final_results = []
    for row in result:
        final_results.append({"@id": row["@id"], "@type": row["@type"]})

    collectionData = {
        "@context": collection_context,
        "@id": collection_id,
        "@type": collection_type,
        "members": final_results
    }
    return ctx.success(collectionData, 200, headers=hydra.LINK_HEADER)
Example #11
0
    def update(self, crud):
        if crud.location not in self.data:
            self.data[crud.location] = {}

        if crud.id not in self.data[crud.location]:
            return ctx.error("Entry not found", 1, 404)

        current_data = self.data[crud.location][crud.id]
        for key in crud.data:
            if key not in current_data:
                return ctx.error("Bad field {}".format(key), 1, 400)
            current_data[key] = crud.data[key]

        self.data[crud.location][crud.id] = current_data

        crud.data = current_data
        return ctx.success(crud.dump(), 200)
    def getAll(self):
        payload = {
            "@context": {
                "hydra": "http://www.w3.org/ns/hydra/core#",
                "vocab": hydra.VOCAB_URL + "#",
                "EntryPoint": "vocab:EntryPoint",
                "events": {
                    "@id": "vocab:EntryPoint/events",
                    "@type": "@id"
                },
                "actors": {
                    "@id": "vocab:EntryPoint/actors",
                    "@type": "@id"
                },
                "locations": {
                    "@id": "vocab:EntryPoint/locations",
                    "@type": "@id"
                },
                "reviews": {
                    "@id": "vocab:EntryPoint/reviews",
                    "@type": "@id"
                },
                "ratings": {
                    "@id": "vocab:EntryPoint/ratings",
                    "@type": "@id"
                },
                "authors": {
                    "@id": "vocab:EntryPoint/authors",
                    "@type": "@id"
                }
            }
        }

        for classObj in hydra.get_entrypoint_classes():
            name = classObj.getEntryPointName()
            payload["@context"][name] = {
                "@id": "vocab:EntryPoint/{}".format(name),
                "@type": "@id"
            }

        return ctx.success(payload, 200, headers=hydra.LINK_HEADER)
def onContext():
    global registered_classes

    method = str(request.method).lower()
    rule = str(request.url_rule)
    ctxName = rule.replace("/api/contexts/", "").replace(".jsonld", "")

    classes = [
        obj for obj in registered_classes.values()
        if obj.contextName == ctxName
    ]

    if len(classes) == 0:
        return ctx.error("unknown resource", 1, 404)

    obj = classes[0]
    context_json = {"@context": obj.apiContext}

    context_json["@context"]["hydra"] = "http://www.w3.org/ns/hydra/core#"
    context_json["@context"]["vocab"] = VOCAB_URL + "#"

    return ctx.success(context_json, 200, headers=LINK_HEADER)
 def getAll(self):
     events = myDB.getAll_("Event")
     events_ld = json.loads(templates.render({}, "events.json"))
     events_ld["members"] = events
     return ctx.success(events_ld, 200, headers = hydra.LINK_HEADER)
 def delete(self, id):
     event = myDB.delete_("Event", id)
     if type(event) is Response:
         return event
     return ctx.success({}, 200, headers = hydra.LINK_HEADER)
 def patch(self, data, id):
     event = myDB.update_("Event", id, data)
     if type(event) is Response:
         return event
     return ctx.success(event, 200, headers = hydra.LINK_HEADER)
def generic_entry_delete_action(id, entry_context, entry_id, entry_type,
                                db_name):
    result = myDB.delete_(db_name, id)
    if type(result) is Response:
        return result
    return ctx.success(result, 200, headers=hydra.LINK_HEADER)
 def get(self, id):
     event = myDB.get_("Event", id)
     if type(event) is Response:
         return event
     return ctx.success(event, 200, headers = hydra.LINK_HEADER)