Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grab a list of objects when they are not located at top level of a json response (HATEOAS) #90

Closed
richhl opened this issue Jul 6, 2015 · 4 comments

Comments

@richhl
Copy link

richhl commented Jul 6, 2015

How am i supposed to code my model section to grab the list of products of a json response as shown bellow?

{
    "_embedded": {
        "products": [
            {
                "_links": {
                    "Primero:codes": {
                        "href": "/codes"
                    }
               },
                "description": "Descripcion Primero",
                "img_url": "/images/original/missing.png",
                "legal": "Legal Primero",
                "name": "Primero",
                "provider": "Test proveedore",
                "provider_logo_url": "/logos/original/missing.png",
                "provider_url": "www.test.com",
                "steps": "Pasos Primero",
                "stock": 2,
                "summary": "Resumen Primero"
            }
        ]
    },

thx in advance.

@ssanders
Copy link

ssanders commented Jul 6, 2015

$json = json_decode($response->getBody(), true);

foreach ($json['_embedded']['products'] as $k => $v) {
     $description = $v['description'];
    // and so on
}

@richhl
Copy link
Author

richhl commented Jul 6, 2015

Thx @ssanders but i need to grab it through service description model....like this:

    "models": {
        "getProductsOutput": {
            "type": "object",
            "additionalProperties": {
                "location": "json",
                "$ref": "Product"
            }
        },
        "Product": {
            "type": "object",
            "properties": {
                "name": {
                    "location": "json",
                    "type": "integer"
                },
                "description": {
                    "location": "json",
                    "type": "string"
                }
            }
        }
    }

@Konafets
Copy link
Contributor

Did you figured out how to get the data?

@Konafets
Copy link
Contributor

I will close this issue. If your problem still exist with latest versions of Guzzle and Guzzle Service, feel free to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants