inakiabt / etsy-php

Etsy API wrapper for PHP
74 stars 59 forks source link

Facilitate fetching of associations #1

Closed atrauzzi closed 11 years ago

atrauzzi commented 11 years ago

It doesn't seem like this library currently supports fetching of associations.

https://www.etsy.com/developers/documentation/getting_started/resources#section_associations

Would you be able to add this? :)

inakiabt commented 11 years ago

Sure, I'll take a look. At least, I could add now a simple interface (method extra parameters) to support associations.

inakiabt commented 11 years ago

What do you think about an interface like this:

        $args = array(
            'params' => array(
                'listing_id' => 654321
            ),
            // A list of associations
            'associations' => array(
                // Could be a simple association, sending something like: ?includes=Images
                'Images',
                // Or a composed one with (all are optional as Etsy API says) "scope", "limit", "offset", "select" and sub-associations ("associations")
                array(
                    // ?includes=ShippingInfo(currency_code, primary_cost):active:1:0/DestinationCountry(name,slug)
                    'ShippingInfo' => array( 
                        'scope' => 'active',
                        'limit' => 1,
                        'offset' => 0,
                        'select' => array('currency_code', 'primary_cost'),
                        // The only issue here is that sub-associations couldn't be more than one, I guess.
                        'associations' => array(
                                                      array(
                            'DestinationCountry' => array(
                                'select' => array('name', 'slug')
                            )
                                                      )
                        )
                    )
                )
            )
        );

        // It should send: /listings/654321?includes=Images,ShippingInfo(currency_code, primary_cost):active:1:0/DestinationCountry(name,slug)
        $result = $this->api->getListing($args);

I don't know if I am missing something. Let me know, thanks.

inakiabt commented 11 years ago

I've changed the interface with:

    $args = array(
            'params' => array(
                'listing_id' => 654321
            ),
            // A list of associations
            'associations' => array(
                // Could be a simple association, sending something like: ?includes=Images
                'Images',
                // Or a composed one with (all are optional as Etsy API says) "scope", "limit", "offset", "select" and sub-associations ("associations")
                // ?includes=ShippingInfo(currency_code, primary_cost):active:1:0/DestinationCountry(name,slug)
                'ShippingInfo' => array( 
                    'scope' => 'active',
                    'limit' => 1,
                    'offset' => 0,
                    'select' => array('currency_code', 'primary_cost'),
                    // The only issue here is that sub-associations couldn't be more than one, I guess.
                    'associations' => array(
                        'DestinationCountry' => array(
                            'select' => array('name', 'slug')
                        )
                    )
                )
            )
        );

Thanks!

rickywiens commented 11 years ago

Thanks! :)