Skip to content

Commit

Permalink
Add methods for HAL resources
Browse files Browse the repository at this point in the history
  • Loading branch information
spaceone committed Sep 9, 2019
1 parent 96b1399 commit a36e519
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions httoop/codecs/application/hal_json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
"""JSON Hypertext Application Language (application/hal+json) codec"""

from __future__ import absolute_import

try:
Expand Down Expand Up @@ -98,6 +100,19 @@ def get_curie(self, relation):
return self.expand(link['href'], rel=rel)
return relation

def add_link(self, relation, link):
links = self['_links'].setdefault(relation, [])
if not isinstance(links, list):
links = [links]
links.append(link)
self['_links'][relation] = links
self['_links'][relation] = list(self.get_links(relation))

def add_resource(self, relation, resource):
resources = list(self.get_resources(relation))
resources.append(resource)
self['_embedded'][relation] = resources


class HAL(JSON):
mimetype = 'application/hal+json'
Expand Down

0 comments on commit a36e519

Please sign in to comment.