Skip to content

Commit 5d4a509

Browse files
authored
update API to use 8.1 and up (#55)
* update API to use 8.1 and up * add dependabot and update actions * replace travis with github actions * update README
1 parent b410fdf commit 5d4a509

File tree

17 files changed

+423
-881
lines changed

17 files changed

+423
-881
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/php.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
name: PHP Composer
1+
name: PHP Test
22

33
on:
44
push:
5-
branches: [master]
5+
branches: [ master ]
66
pull_request:
7-
branches: [master]
7+
branches: [ master ]
88

99
jobs:
10-
build:
11-
runs-on: ubuntu-latest
12-
10+
run:
11+
runs-on: ${{ matrix.operating-system }}
12+
strategy:
13+
matrix:
14+
operating-system: [ 'ubuntu-latest' ]
15+
php-versions: [ '8.1', '8.2', '8.3']
16+
phpunit-versions: [ 'latest' ]
17+
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
1318
steps:
14-
- uses: actions/checkout@v2
15-
16-
- name: Validate composer.json and composer.lock
17-
run: composer validate --strict
18-
19-
- name: Cache Composer packages
20-
id: composer-cache
21-
uses: actions/cache@v2
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
- name: Install PHP
22+
uses: shivammathur/setup-php@v2
2223
with:
23-
path: vendor
24-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
25-
restore-keys: |
26-
${{ runner.os }}-php-
27-
24+
php-version: ${{ matrix.php-versions }}
25+
extensions: json, curl
26+
tools: phpunit:${{ matrix.phpunit-versions }}
2827
- name: Install dependencies
29-
run: composer install --prefer-dist --no-progress
30-
31-
- name: Run test suite
32-
run: composer run-script test
28+
run: |
29+
composer install --prefer-dist --no-interaction
30+
- name: Execute tests
31+
run: vendor/bin/phpunit

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[![Build status](https://api.travis-ci.org/gerbenjacobs/HabboAPI.svg)](https://travis-ci.org/gerbenjacobs/HabboAPI)
1+
[![Build status](https://github.com/gerbenjacobs/HabboAPI/actions/workflows/php.yml/badge.svg)](https://github.com/gerbenjacobs/HabboAPI/actions/workflows/php.yml)
22
[![Latest Stable Version](https://poser.pugx.org/gerbenjacobs/habbo-api/v/stable.svg)](https://packagist.org/packages/gerbenjacobs/habbo-api)
3-
[![Join the chat at https://gitter.im/gerbenjacobs/HabboAPI](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gerbenjacobs/HabboAPI)
43
# HabboAPI
54
This PHP wrapper library is used to collect data from the _undocumented_ Habbo API.
6-
The project requires PHP 7.3 or higher and uses the Composer autoloader and PSR-4 standard.
5+
The project requires PHP 8.1 or higher and uses the Composer autoloader and PSR-4 standard.
6+
7+
Older versions for PHP 7.4 are available at [Packagist](https://packagist.org/packages/gerbenjacobs/habbo-api).
78

89
See the `example.php` file on how you could use this library.
910

@@ -35,6 +36,7 @@ See the `example.php` file on how you could use this library.
3536
```
3637

3738
## Changelog
39+
- April 30th, 2023 v6.0.0 - Fully support PHP 8.1 and up
3840
- December 29th, 2020 v5.0.0 - Add support for PHP 8 and drop support below PHP 7.3
3941
- December 18th, 2020 v4.1.0 - Adds "sandbox" as hotel, includes new values for `Habbo` entity; online, lastAccessTime, currentLevel, currentLevelCompleted, totalExperience, starGemCount
4042
- March 30th, 2020 v4.0.0 - Use Carbon 2.0 and drop support for PHP below 7.1.8
@@ -59,4 +61,4 @@ See the `example.php` file on how you could use this library.
5961
## Developer Installation
6062
1. Clone the project
6163
2. Run `composer install`
62-
3. Verify the install by running `./vendor/bin/phpunit` or opening the `example.php` page on a PHP server
64+
3. Verify the installation by running `vendor/bin/phpunit` or opening the `example.php` page on a PHP server

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=7.3",
21-
"nesbot/carbon": "~2",
20+
"php": ">=8.1",
21+
"nesbot/carbon": "^2.66",
2222
"ext-json": "*",
2323
"ext-curl": "*"
2424
},
@@ -28,9 +28,9 @@
2828
}
2929
},
3030
"require-dev": {
31-
"phpunit/phpunit": "9.5.*"
31+
"phpunit/phpunit": "^10.1"
3232
},
3333
"scripts": {
3434
"test": "vendor/bin/phpunit"
3535
}
36-
}
36+
}

example.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
// Shortcut for the FQN
66
use HabboAPI\Entities\Badge;
7-
use HabboAPI\Entities\Habbo;
8-
use HabboAPI\Entities\Photo;
97
use HabboAPI\Entities\Profile;
108
use HabboAPI\HabboAPI;
119
use HabboAPI\HabboParser;
@@ -15,12 +13,12 @@
1513
$habboApi = new HabboAPI($habboParser);
1614

1715
try {
18-
// Find the user 'koeientemmer' and get their ID
19-
$myHabbo = $habboApi->getHabbo('koeientemmer');
16+
// Find the user 'Macklebee' and get their ID
17+
$myHabbo = $habboApi->getHabbo('Macklebee');
2018

2119
// Get extra information about one of their groups
2220
// Note: This is actually a hardcoded group ID to showcase the parseGroup() endpoint
23-
$group = $habboApi->getGroup("g-hhus-b0751bd6408cc83a8e046de6949fd747");
21+
$group = $habboApi->getGroup("g-hhus-0419705237d0e8c004195c365810e7a7");
2422
} catch (Exception $e) {
2523
echo '
2624
<p>Oops. Can not find this Habbo!</p>
@@ -34,7 +32,6 @@
3432

3533
if ($myHabbo->hasProfile()) {
3634
// Collect all the profile info
37-
/** @var Profile $myProfile */
3835
$myProfile = $habboApi->getProfile($myHabbo->getId());
3936
} else {
4037
// This Habbo has a closed home, only show their Habbo object
@@ -59,7 +56,6 @@
5956

6057
// Some markup for the Habbo part
6158

62-
/* @var Habbo $habbo */
6359
$habbo = $myProfile->getHabbo();
6460
$onlineText = $habbo->isOnline() ? "yes" : "no";
6561
$lastAccess = ($habbo->getLastAccessTime()) ? $habbo->getLastAccessTime()->toFormattedDateString() : "N/A";
@@ -107,7 +103,6 @@
107103

108104
// Generate the photos
109105
if ($myPhotos) {
110-
/** @var Photo $myPhoto */
111106
foreach ($myPhotos as $myPhoto) {
112107
$html['photos'] .= '
113108
<div class="col-md-3">
@@ -216,7 +211,7 @@
216211
</p>
217212

218213
<?php $members = $group->getMembers();
219-
if (count((array)$members) > 0) : ?>
214+
if (count($members) > 0) : ?>
220215
<p>This group has <strong><?php echo count($group->getMembers()); ?></strong> members.
221216
Here are 10 random ones:</p>
222217

src/Entities/Achievement.php

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,46 @@
22
/**
33
* The entity model for an Achievement object
44
*/
5+
56
namespace HabboAPI\Entities;
67

8+
use Carbon\Carbon;
9+
710
/**
811
* Class Achievement
912
*
1013
* @package HabboAPI\Entities
1114
*/
1215
class Achievement implements Entity
1316
{
14-
private $id, $name, $category;
15-
private $requirements;
16-
private $level, $score;
17+
private string $id, $name, $category, $state;
18+
private \DateTimeInterface $creationTime;
19+
private int $level, $score;
1720

1821
/**
1922
* Parses achievement info array to Achievement object
20-
* @param $achievement
23+
* @param $data
2124
*/
22-
public function parse($achievement)
25+
public function parse($data): void
2326
{
2427
// add default fields
25-
$this->id = $achievement['achievement']['id'];
26-
$this->name = $achievement['achievement']['name'];
27-
$this->category = $achievement['achievement']['category'];
28+
$this->id = $data['achievement']['id'];
29+
$this->name = $data['achievement']['name'];
30+
$this->category = $data['achievement']['category'];
31+
if (isset($data['achievement']['state'])) {
32+
$this->state = $data['achievement']['state'];
33+
}
2834

29-
// add requirements if available
30-
if (isset($achievement['requirements'])) {
31-
$this->requirements = $achievement['requirements'];
35+
if (isset($data['achievement']['creationTime'])) {
36+
$this->creationTime = Carbon::parse($data['achievement']['creationTime']);
3237
}
3338

3439
// add user state if available
35-
if (isset($achievement['level'])) {
36-
$this->level = $achievement['level'];
40+
if (isset($data['level'])) {
41+
$this->level = $data['level'];
3742
}
38-
if (isset($achievement['score'])) {
39-
$this->score = $achievement['score'];
43+
if (isset($data['score'])) {
44+
$this->score = $data['score'];
4045
}
4146
}
4247

@@ -45,51 +50,51 @@ public function __toString()
4550
return $this->getName();
4651
}
4752

48-
/**
49-
* @return int
50-
*/
51-
public function getId()
53+
54+
public function getId(): int|string
5255
{
5356
return $this->id;
5457
}
5558

56-
/**
57-
* @return string
58-
*/
59-
public function getName()
59+
public function getName(): string
6060
{
6161
return $this->name;
6262
}
6363

64-
/**
65-
* @return string
66-
*/
67-
public function getCategory()
64+
public function getCategory(): string
6865
{
6966
return $this->category;
7067
}
7168

72-
/**
73-
* @return string
74-
*/
75-
public function getLevel()
69+
public function getLevel(): int
7670
{
7771
return $this->level;
7872
}
7973

80-
/**
81-
* @return string
82-
*/
83-
public function getScore()
74+
75+
public function getScore(): int
8476
{
8577
return $this->score;
8678
}
8779

88-
/**
89-
* @return array
90-
*/
91-
public function getRequirements()
80+
81+
public function getState(): string
82+
{
83+
return $this->state;
84+
}
85+
86+
public function setState(string $state): void
87+
{
88+
$this->state = $state;
89+
}
90+
91+
public function getCreationTime(): \DateTimeInterface
92+
{
93+
return $this->creationTime;
94+
}
95+
96+
public function setCreationTime(\DateTimeInterface $creationTime): void
9297
{
93-
return $this->requirements;
98+
$this->creationTime = $creationTime;
9499
}
95100
}

0 commit comments

Comments
 (0)