geo.php 4.06 KB
<?php
class Flora_Api_Service_Geo extends Flora_Api_Service
{
    const API_CONTINENT = "geo/continent";
    const API_CONTINENTS = "geo/continents";
    const API_SUBCONTINENT = "geo/subcontinent";
    const API_SUBCONTINENTS = "geo/subcontinents";
    const API_COUNTRY = "geo/country";
    const API_COUNTRIES = "geo/countries";
    const API_CITY = "geo/city";
    const API_CITIES = "geo/cities";
    const API_REGION = "geo/region";
    const API_REGIONS = "geo/regions";
    const API_USERIPINFO = "geo/useripinfo";

    /**
     * Retrieves information about continent for given numeric ID or ISO code
     * @param $id int|string Numeric ID or ISO code
     * @return Flora_Model_Geo_Continent
     */
    public function getContinentByID($id)
    {
        return $this->call(self::API_CONTINENT, array("id" => $id));
    }

    /**
     * @param int $limit
     * @param int $offset
     * @return Flora_Collection|Flora_Model_Geo_Continent[]
     */
    public function getContinentsList($limit = 0, $offset = 0)
    {
        return $this->call(self::API_CONTINENTS, array("limit" => (int)$limit, "offset" => (int)$offset));
    }

    /**
     * Retrieves information about continent for given numeric ID or ISO code
     * @param $id int|string Numeric ID or ISO code
     * @return Flora_Model_Geo_SubContinent
     */
    public function getSubContinentByID($id)
    {
        return $this->call(self::API_SUBCONTINENT, array("id" => $id));
    }


    /**
     * @param int $parent_id
     * @param int $limit
     * @param int $offset
     * @return Flora_Collection|Flora_Model_Geo_Subcontinent[]
     */
    public function getSubcontinentsList($parent_id = 0, $limit = 0, $offset = 0)
    {
        return $this->call(self::API_SUBCONTINENTS, array("limit" => (int)$limit, "offset" => (int)$offset,
            "parent_id" => (int)$parent_id));
    }

    /**
     * @param $id int|string Numeric ID or ISO code
     * @return Flora_Model_Geo_Country
     */
    public function getCountryByID($id)
    {
        return $this->call(self::API_COUNTRY, array("id" => $id));
    }

    /**
     * @param int $parent_id
     * @param int $limit
     * @param int $offset
     * @return Flora_Collection|Flora_Model_Geo_Country[]
     */
    public function getCountriesList($parent_id = 0, $limit = 0, $offset = 0)
    {
        return $this->call(self::API_COUNTRIES, array("limit" => (int)$limit, "offset" => (int)$offset,
            "parent_id" => (int)$parent_id));
    }

    /**
     * @param $id int Numeric ID
     * @param $with_not_delivered bool
     * @return Flora_Model_Geo_City
     */
    public function getCityByID($id, $with_not_delivered = false)
    {
        return $this->call(self::API_CITY, array('id' => $id, 'with_not_delivered' => $with_not_delivered));
    }

    /**
     * @param int $country_id
     * @param int $region_id
     * @param int $limit
     * @param int $offset
     * @param bool $with_not_delivered
     * @return Flora_Collection|Flora_Model_Geo_City[]
     */
    public function getCitiesList($country_id = 0, $region_id = 0, $limit = 0, $offset = 0, $with_not_delivered = false)
    {
        return $this->call(self::API_CITIES,
            array("limit" => (int)$limit, "offset" => (int)$offset,
                  "country_id" => (int)$country_id, "region_id" => (int)$region_id,
                  "with_not_delivered" => $with_not_delivered));
    }

    /**
     * @param $id int Numeric ID
     * @return Flora_Model_Geo_Region
     */
    public function getRegionByID($id)
    {
        return $this->call(self::API_REGION, array("id" => $id));
    }

    /**
     * @param int $country_id
     * @param int $limit
     * @param int $offset
     * @return Flora_Collection|Flora_Model_Geo_City[]
     */
    public function getRegionsList($country_id = 0, $limit = 0, $offset = 0)
    {
        return $this->call(self::API_REGIONS, array("limit" => (int)$limit, "offset" => (int)$offset,
            "country_id" => (int)$country_id));
    }

    /**
     * @return stdClass
     */
    public function getUserIPInfo()
    {
        return $this->call(self::API_USERIPINFO);
    }
}