Skip to content

Commit

Permalink
add company profile
Browse files Browse the repository at this point in the history
  • Loading branch information
daniwebdev committed Oct 31, 2023
1 parent d18848e commit 10f11de
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 10 deletions.
64 changes: 64 additions & 0 deletions src/Resources/CompanyProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
namespace GOAPI\IO\Resources;

class CompanyProfile {

public function __construct(
public $symbol,
public $name,
public $about,
public $logo,
public $npwp,
public $phone,
public $fax,
public $email,
public $sector_name,
public $status,
public $sub_industry_name,
public $sub_sector_name,
public $website,
public $address,
public $ipo_fund_raised,
public $ipo_listing_date,
public $ipo_offering_shares,
public $ipo_percentage,
public $ipo_securities_administration_bureau,
public $ipo_total_listed_shares,
public $ipo_founders_shares,
public $secretary,
public $commissioners,
public $directors,
public $shareholders
) {}


public static function fromArray(array $data) {
return new CompanyProfile(
symbol: $data['symbol'],
name: $data['name'],
about: $data['about'],
logo: $data['logo'],
npwp: $data['npwp'],
phone: $data['phone'],
fax: $data['fax'],
email: $data['email'],
sector_name: $data['sector_name'],
status: $data['status'],
sub_industry_name: $data['sub_industry_name'],
sub_sector_name: $data['sub_sector_name'],
website: $data['website'],
address: $data['address'],
ipo_fund_raised: $data['ipo_fund_raised'],
ipo_listing_date: $data['ipo_listing_date'],
ipo_offering_shares: $data['ipo_offering_shares'],
ipo_percentage: $data['ipo_percentage'],
ipo_securities_administration_bureau: $data['ipo_securities_administration_bureau'],
ipo_total_listed_shares: $data['ipo_total_listed_shares'],
ipo_founders_shares: $data['ipo_founders_shares'],
secretary: $data['secretary'],
commissioners: $data['commissioners'],
directors: $data['directors'],
shareholders: $data['shareholders']
);
}
}
22 changes: 14 additions & 8 deletions src/StockIDX.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public function getCompanies() {
});
}

public function getProfile($symbol) {
$endpoint = "/$symbol/profile";

if($this->makeRequest($endpoint)['data']) {
return \GOAPI\IO\Resources\CompanyProfile::fromArray($this->makeRequest($endpoint)['data']);
}

}

public function getStockPrices(array $symbols) {
$endpoint = "/prices";
$params = ["symbols" => implode(',', $symbols)];
Expand Down Expand Up @@ -118,12 +127,9 @@ public function getStockIndicators($page = 1, $date = null) {
if ($date) {
$params["date"] = $date;
}
return $this->makeRequest($endpoint, $params);
}
}

// Example usage:
// $apiBaseUrl = "https://api.example.com";
// $stockAPI = new StockIDX($apiBaseUrl);
// $stockPrices = $stockAPI->getStockPrices("BBCA,AALI,GOTO");
// var_dump($stockPrices);
return (new Collection($this->makeRequest($endpoint, $params)['data']['results']))->map(function($item) {
return \GOAPI\IO\Resources\StockIndicator::fromArray($item);
});
}
}
29 changes: 27 additions & 2 deletions tests/StockIDXTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

});


test('get companies', function() use($client) {
$stockIDX = $client->createStockIDX();

Expand Down Expand Up @@ -47,11 +46,37 @@
expect($results)->toBeArray();
});

test('get stock top loser', function() use($client) {
$stockIDX = $client->createStockIDX();

$results = $stockIDX->getTopLoserStocks()->values();
expect($results)->toBeArray();
});

test('get stock top gainer', function() use($client) {
$stockIDX = $client->createStockIDX();

$results = $stockIDX->getTopGainerStocks()->values();
expect($results)->toBeArray();
});

test('get broker summary', function() use($client) {
$stockIDX = $client->createStockIDX();
$results = $stockIDX->getBrokerSummary('BBCA', '2023-10-30');

expect($results instanceof \GOAPI\IO\Collection)->toBeTrue();
});


test('get stock indicators', function() use($client) {
$stockIDX = $client->createStockIDX();
$results = $stockIDX->getStockIndicators(page: 1, date: '2023-10-30');

expect($results instanceof \GOAPI\IO\Collection)->toBeTrue();
});

test('get company profile', function() use($client) {
$stockIDX = $client->createStockIDX();
$response = $stockIDX->getProfile(symbol: 'BBCA');

expect($response instanceof \GOAPI\IO\Resources\CompanyProfile)->toBeTrue();
});

0 comments on commit 10f11de

Please sign in to comment.