def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, Namespace( subject=FollowerRelationship, version="v1", ), follower_relationship_id=obj.id, ) links["user"] = Link.for_( Operation.Retrieve, Namespace( subject=User, version="v1", ), user_id=obj.user_id, ) links["follower"] = Link.for_( Operation.Retrieve, Namespace( subject=User, version="v1", ), user_id=obj.follower_id, ) return links.to_dict()
def links(self): links = Links() links["self"] = Link.for_(self.operation, self.ns, qs=self.page.to_tuples(), **self.extra) if self.page.offset + self.page.limit < self.count: links["next"] = Link.for_(self.operation, self.ns, qs=self.page.next().to_tuples(), **self.extra) if self.page.offset > 0: links["prev"] = Link.for_(self.operation, self.ns, qs=self.page.prev().to_tuples(), **self.extra) return links
def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, Namespace(subject=Topping, version="v1",), topping_id=obj.id, ) links["parent:pizza"] = Link.for_( Operation.Search, Namespace(subject=Pizza, version="v1"), id=obj.pizza_id ) return links.to_dict()
def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, Namespace( subject=User, version="v1", ), user_id=obj.id, ) links["tweets"] = Link.for_( Operation.SearchFor, Namespace( subject=User, object_="tweets", version="v1", ), user_id=obj.id, ) links["followers"] = Link.for_( Operation.SearchFor, Namespace( subject=User, object_="followers", version="v1", ), user_id=obj.id, ) links["following"] = Link.for_( Operation.SearchFor, Namespace( subject=User, object_="following", version="v1", ), user_id=obj.id, ) links["feed"] = Link.for_( Operation.SearchFor, Namespace( subject=User, object_="feed", version="v1", ), user_id=obj.id, ) return links.to_dict()
def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, Namespace(subject=Person), person_id=obj.id, ) return links.to_dict()
def links(self): """ Include previous and next links. """ links = super(OffsetLimitPaginatedList, self).links if self._page.offset + self._page.limit < self.count: links["next"] = Link.for_(self._operation, self._ns, qs=self._page.next_page.to_items(), **self._context) if self.offset > 0: links["prev"] = Link.for_(self._operation, self._ns, qs=self._page.prev_page.to_items(), **self._context) return links
def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, Namespace(subject=Address), address_id=obj.id, ) return links.to_dict()
def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, Namespace(subject=OrderEvent, version="v1",), order_event_id=obj.id, ) return links.to_dict()
def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, Namespace( subject=Tweet, version="v1", ), tweet_id=obj.id, ) links["user"] = Link.for_( Operation.Retrieve, Namespace( subject=User, version="v1", ), user_id=obj.user_id, ) return links.to_dict()
def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, Namespace( subject=Example, version="v1", ), example_id=obj.id, ) return links.to_dict()
def links(self): """ Include a self link. """ links = Links() links["self"] = Link.for_(self._operation, self._ns, qs=self._page.to_items(), **self._context) return links
def test_link_for_operation_without_namespace(): graph = create_object_graph(name="example", testing=True) ns = Namespace(subject="foo") @graph.route(ns.collection_path, Operation.Search, ns) def func(): pass with graph.app.test_request_context(): link = Link.for_(Operation.Search, ns) assert_that(link.href, is_(equal_to("http://localhost/api/foo")))
def iter_links(operations, page): """ Generate links for an iterable of operations on a starting page. """ for operation, ns, rule, func in operations: yield Link.for_( operation=operation, ns=ns, type=ns.subject_name, qs=page.to_tuples(), )
def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, ns=Namespace( subject=Address, path=Namespace(subject=Person, ).instance_path, ), person_id=obj.person_id, address_id=obj.id, ) return links.to_dict()
def links(self): """ Include previous and next links. """ links = super(OffsetLimitPaginatedList, self).links if self._page.offset + self._page.limit < self.count: links["next"] = Link.for_( self._operation, self._ns, qs=self._page.next_page.to_items(), **self._context ) if self.offset > 0: links["prev"] = Link.for_( self._operation, self._ns, qs=self._page.prev_page.to_items(), **self._context ) return links
def links(self): """ Include a self link. """ links = Links() links["self"] = Link.for_( self._operation, self._ns, qs=self._page.to_items(), **self._context ) return links
def test_link_for_operation_templated(): graph = create_object_graph(name="example", testing=True) ns = Namespace(subject="foo") @graph.route(ns.instance_path, Operation.Retrieve, ns) def func(): pass with graph.app.test_request_context(): link = Link.for_(Operation.Retrieve, ns, allow_templates=True) assert_that( link.href, is_(equal_to("http://localhost/api/foo/{}".format("{foo_id}"))))
def discover(): # accept pagination limit from request page = Page.from_query_string(load_query_string_data(page_schema)) page.offset = 0 response_data = dict(_links=Links({ "self": Link.for_(Operation.Discover, ns, qs=page.to_tuples()), "search": [ link for link in iter_links( self.find_matching_endpoints(ns), page) ], }).to_dict()) return make_response(response_data)
def get_links(self, obj): links = Links() links["self"] = Link.for_( Operation.Retrieve, Namespace( subject=Order, version="v1", ), order_id=obj.id, ) # links["child:pizza"] = Link.for_( # Operation.Retrieve, # Namespace( # subject=Pizza, # version="v1", # ), # pizza_id=obj.pizza_id, # ) return links.to_dict()
def get_links(self, obj): links = Links() links["self"] = Link.for_(Operation.Retrieve, Person, person_id=obj.id) return links.to_dict()