Skip to content

Commit

Permalink
Merge pull request #39 from c0destep/develop
Browse files Browse the repository at this point in the history
[BUG] host resolve
  • Loading branch information
c0destep committed Mar 26, 2023
2 parents 130e59e + 969d564 commit f41a776
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 32 deletions.
39 changes: 39 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
List any dependencies that are required for this change.

Fixes # (issue)

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

# How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also
list any relevant details for your test configuration

- [ ] Test A
- [ ] Test B

**Test Configuration**:

* OS:
* Browser:
* Version:

# Checklist:

- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
run: ./vendor/bin/phpstan analyse src tests

- name: Run Tests
run: ./vendor/bin/phpunit --verbose
run: ./vendor/bin/phpunit
8 changes: 2 additions & 6 deletions captainhook.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"conditions": []
},
{
"action": "./vendor/bin/phpunit --verbose",
"action": "./vendor/bin/phpunit",
"options": [],
"conditions": []
}
Expand Down Expand Up @@ -62,10 +62,6 @@
},
"post-change": {
"enabled": true,
"actions": [
{
"action": "echo 'PHP'"
}
]
"actions": []
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ergebnis/composer-normalize": "^2",
"friendsofphp/php-cs-fixer": "^3",
"phpstan/phpstan": "^1",
"phpunit/phpunit": "^9",
"phpunit/phpunit": "^10",
"ramsey/conventional-commits": "^1"
},
"minimum-stability": "stable",
Expand Down
5 changes: 4 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php declare(strict_types=1);

use HolyBible\Bible;
use HolyBible\Books;

require_once 'vendor/autoload.php';

var_dump((new Bible())->getAvailableVersions());
$bible = new Bible();

print_r($bible->getChapter(Books::FIRST_CORINTHIANS, 2));
43 changes: 21 additions & 22 deletions src/Bible.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ class Bible
private const API_URL = 'https://www.abibliadigital.com.br/api/';

/**
* @var string
* @var string Bible version
*/
private string $version;
/**
* @var string|null
* @var string|null User token provided by API
*/
private ?string $userToken;

/**
* @param string $version Default NVI (Nova Versão Internacional)
* @param string|null $userToken
* @param string $version Bible version default is "nvi" [optional]
* @param string|null $userToken User token provided by API [optional]
*/
public function __construct(string $version = 'nvi', string $userToken = null)
{
Expand All @@ -35,37 +35,36 @@ public function __construct(string $version = 'nvi', string $userToken = null)
}

/**
* @param Books $book
* @param int $chapter
* @return string[]
* @param Books $book Bible book
* @param int $chapter Book chapter
* @return string[] List of all verses of the respective book and chapter
*/
public function getChapter(Books $book = Books::GENESIS, int $chapter = 1): array
{
return $this->getContentApi('verses/' . $this->version . DIRECTORY_SEPARATOR . $book->value . DIRECTORY_SEPARATOR . $chapter);
}

/**
* @param string $uri
* @return string[]
* @param string $uri API route
* @return string[] List with data
*/
public function getContentApi(string $uri): array
{
try {
$client = new Client([
'base_url' => self::API_URL,
'timeout' => 2.0
]);

if (!is_null($this->userToken)) {
$response = $client->get($uri, [
$response = $client->get(self::API_URL . $uri, [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $this->userToken
]
]);
} else {
$response = $client->get($uri);
$response = $client->get(self::API_URL . $uri);
}

if ($response->getStatusCode() !== 200) {
Expand All @@ -83,15 +82,15 @@ public function getContentApi(string $uri): array
}

/**
* @return string
* @return string Current bible version
*/
public function getCurrentVersion(): string
{
return $this->version;
}

/**
* @param string $version
* @param string $version Bible version
* @return Bible
*/
public function setVersion(string $version): Bible
Expand All @@ -101,15 +100,15 @@ public function setVersion(string $version): Bible
}

/**
* @return string|null
* @return string|null Current user token. NULL if you don't have one.
*/
public function getUserToken(): ?string
{
return $this->userToken;
}

/**
* @param string $userToken
* @param string $userToken User token
* @return Bible
*/
public function setUserToken(string $userToken): Bible
Expand All @@ -119,26 +118,26 @@ public function setUserToken(string $userToken): Bible
}

/**
* @return string[]
* @return string[] List of all books in the bible
*/
public function getBooks(): array
{
return $this->getContentApi('books');
}

/**
* @return string[]
* @return string[] List of all available versions of the Bible
*/
public function getAvailableVersions(): array
{
return $this->getContentApi('versions');
}

/**
* @param Books $book
* @param int $chapter
* @param int $verse
* @return string[]
* @param Books $book Bible book
* @param int $chapter Book chapter
* @param int $verse Chapter verse
* @return string[] Verse text
*/
public function getVerse(Books $book = Books::GENESIS, int $chapter = 1, int $verse = 1): array
{
Expand Down
2 changes: 1 addition & 1 deletion tests/BibleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function testGetBooks(): void

$this->assertIsArray($books, 'Error return not array');

$this->assertArrayHasKey('error', $books, $books['error']);
$this->assertArrayNotHasKey('error', $books, 'Error request');
}
}

0 comments on commit f41a776

Please sign in to comment.