gerbenjacobs / HabboAPI

A PHP wrapper for the (undocumented) Habbo API
MIT License
45 stars 10 forks source link

Adjust API URL to be broader #9

Closed gerbenjacobs closed 9 years ago

gerbenjacobs commented 9 years ago

At the moment the url has to point to: https://www.habbo.com/api/public/ This does not account for the extradata endpoint, which is a requirement for the Photos story (#3)

There's also two alternatives:

DavydeVries commented 9 years ago

I'm using currently your API in my private project in laravel 4.2. And use this to access all APIs.

private $habboApi = [];

public function __construct()
{
    $hotels = ['fi', 'es', 'it', 'nl', 'de', 'fr', 'com.br', 'com', 'com.tr'];
    //$hotels = ['com', 'nl'];
    foreach($hotels as $hotel)
    {
        $habboParser                 = new HabboParser('https://www.habbo.'.$hotel.'/api/public/');
        $this->habboApi[ $hotel ]    = new HabboAPI($habboParser);
    }
}

Maybe strip off /api/public/ and add urls by a parser request? So if you call a habbo use /api/public/ and if we call a photo use /extradata/public/users/

gerbenjacobs commented 9 years ago

Yeah, I'm also just using the hotel domain extension as the unique thing/variable. The problem of that will be that if Habbo changes its URLs often, that it requires a code change. But I'm not sure if that chance is high.

So then I'd suggest we use new HabboParser('com') and then when you ask for getHabbo() it uses api/public and when you ask getPhotos() it will use extradata/public/.... Do you agree?

DavydeVries commented 9 years ago

I agree, new HabboParser('com') is a lot cleaner, the /api/public/ won't be changed I guess. Because all Habbo profiles are build on that url with JavaScript.

I guess the extradata url is in development stage by Habbo (het zou me niks verbazen als dit een speeltuin is voor de ontwikkelaars daar bij Sulake). And can change, like you said before that the stories probably be dropped...

DavydeVries commented 9 years ago

About: new HabboParser('com').

I suggest to recognize countries with domains extension or land short code:

Why

If you use some flag icons like this. You can't use the class flag-icon-com,flag-icon-com.tr,flag-icon-com.br. This is not your problem.

But someone that use your API can use one variable to call your API. And can use the same variable to define the right flag. Instead of doing the following here below.

My quick and dirty code
switch($country)
{
    case "us":
        $countryAPI  = "com";
        break;
    case "tr":
        $countryAPI  = "com.tr";
        break;
    case "br":
        $countryAPI  = "com.br";
        break;
    default:
        $countryAPI  = $country;
}
gerbenjacobs commented 9 years ago

Would you then also use PT for BR, MX for ES and BE for NL? (Which is why I chose the hotel domain extension, because Habbo.com would be: US, UK, AU, SG, DK, SE, NO)

DavydeVries commented 9 years ago

"Would you then also use PT for BR, MX for ES and BE for NL?"

Nope.. I agree with you on choosing domain extension. You're right about dealing with this.

An other idea about this, is adding landcode in the response. Based on the extracted hhxx- like substr($obj->getId(), 2, 2);, like br,de,es,fi,fr,it,nl,tr,us and use that for flags? But an US flag for someone that is from United Kingdom is a bad idea.. Why Habbo could not be separated?

But maybe is this not your/our territory. And leave this flag problem to the user of the API.

gerbenjacobs commented 9 years ago

Yep, because if you really think about it, flag icons are a UI/View problem. And people can easily map 'com' to 'us'. For my own project I actually renamed 'us.png' to 'com.png' :)

2015-11-28 13:17 GMT+01:00 Davy de Vries notifications@github.com:

"Would you then also use PT for BR, MX for ES and BE for NL?"

Nope.. I agree with you on choosing domain extension. You're right about dealing with this.

An other idea about this, is adding landcode in the response. Based on the extracted hhxx- like substr($obj->getId(), 2, 2);, like br,de,es,fi,fr, it,nl,tr,us and use that for flags? But an US flag for someone that is from United Kingdom is a bad idea.. Why Habbo could not be separated?

But maybe is this not your/our territory. And leave this flag problem to the user of the API.

— Reply to this email directly or view it on GitHub https://github.com/gerbenjacobs/HabboAPI/issues/9#issuecomment-160288298 .

DavydeVries commented 9 years ago

About: 'https://www.habbo.' . $hotel . '/api/' You have to move /api/ to $url = 'public/users?name=' . $identifier; Because on your way you have still problems with these urls: http://habbo.com/extradata/public/users/.

So my suggestion is:

$url = 'api/public/users?name=' . $identifier;

So you can access this too (in the future): $url = 'extradata/public/users/' . $identifier . '/photos'

gerbenjacobs commented 9 years ago

Good catch. I thought everything was behind api. Maybe just store extension only. Op 6 dec. 2015 15:16 schreef "Davy de Vries" notifications@github.com:

About: 'https://www.habbo.' . $hotel . '/api/' https://github.com/gerbenjacobs/HabboAPI/blob/v2/src/HabboParser.php#L38 You have to move /api/ to $url = 'public/users?name=' . $identifier; Because on your way you have still problems with these urls: http://habbo.com/extradata/public/users/. So my suggestion is:

$url = 'api/public/users?name=' . $identifier;

So you can access this too (in the future): $url = 'extradata/public/users/' . $identifier . '/photos'

— Reply to this email directly or view it on GitHub https://github.com/gerbenjacobs/HabboAPI/issues/9#issuecomment-162320525 .

DavydeVries commented 9 years ago

Maybe just store extension only.

You mean use full-urls by an request? Like this: 'https://habbo.'.$hotel.'/extradata/public/users/' 'https://habbo.'.$hotel.'/api/public/users?name='

You can do that but https://habbo.'.$hotel.'/ is always the same, so your api_base construction is a great way to handle this in my eyes. But maybe rename it to something like url_base/url_basis because it's not only api anymore.

BTW, if you change the url like I suggested above, it's possible to collect furnidata too (for in the future): http://habbo.' . $hotel . '/gamedata/furnidata/1