How to use the recurly.resource.Page function in recurly

To help you get started, we’ve selected a few recurly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github recurly / recurly-client-python / tests / test_resource.py View on Github external
def test_cast_page(self):
        # should return a page of cast data
        page = cast(
            {
                "object": "list",
                "has_more": True,
                "next": "/resources?cursor=123",
                "data": [
                    {"object": "my_resource", "my_string": "kmxu3f3qof17"},
                    {"object": "my_resource", "my_string": "kmxu3f3qof18"},
                ],
            }
        )

        self.assertEqual(type(page), recurly.resource.Page)
        self.assertEqual(page.has_more, True)
        self.assertEqual(page.next, "/resources?cursor=123")
        self.assertEqual(type(page.data[0]), MyResource)
        self.assertEqual(page.data[0].my_string, "kmxu3f3qof17")
github recurly / recurly-client-python / recurly / resource.py View on Github external
def cast_json(cls, properties, class_name=None, response=None):
        """Casts a dict of properties into a Recurly Resource"""

        if class_name is None and "object" in properties:
            # If it's a Page, let's return that now
            if (
                properties["object"] == "list"
                and "data" in properties
                and "has_more" in properties
            ):
                properties["data"] = [Resource.cast_json(i) for i in properties["data"]]
                return Page(properties)

            # If it's not a Page, we need to derive the class name
            # from the "object" property. The class_name passed in should
            # take precedence.
            name_parts = properties["object"].split("_")
            class_name = "".join(x.title() for x in name_parts)

        klass = cls.locator(class_name)

        # Special case for Empty class
        if class_name == Empty:
            klass = Empty

        # If we can't find a resource class, we should return
        # the untyped properties dict. If in strict-mode, explode.
        if klass is None: