Install the dependencies via composer from the project root:
composer install
Go inside the web
directory and start PHP's internal webserver.
NOTE: this webserver is single-threaded and is not for production!
cd web
php -S 0.0.0.0:8000
Use the helper-script in the project-directory to spin up the Docker-container
# run docker-compose
docker-compose -f docker-compose.dev.yml up
# using the helper script in the root of the project
./dev up
If you want to change the PHP-version to work with, edit the file docker-compose.dev.yml
.
Comment out the line for the PHP-version you don't want and un-comment the line for
the PHP-version you do want. Then start the Docker-containers with one of the commands above
like ./dev up
.
Then install the database (ignore the errors)
./dev exec db mysql -u root -proot api < resources/schema.sql
./dev exec db mysql -u root -proot api < resources/fixtures.sql
If you want to see the version of PHP you're currently using in the PHP-docker container, you can issue the following command:
./dev exec php php -v
PHP 7.1.8-2+ubuntu16.04.1+deb.sury.org+4 (cli) (built: Aug 4 2017 13:04:12) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.8-2+ubuntu16.04.1+deb.sury.org+4, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
There are functional tests to assure the correct working of the API. These tests are created with behat.
Execute the tests with either the helper-script or with behat itself.
# use behat
cd tests/behat
../../vendor/bin/behat
# OR use the helper script in the root of the project
./dev test
In order to create a new call, specify the following data:
/api/v1/<name>/
)/api/v1/<websitename>/<endpoint>
)curl -v -X POST -H "Content-Type: application/json" -d'{
"website_name": "wecamp",
"website_url": "http://weca.mp/2017/",
"endpoints": [
{
"name": "coaches",
"selectors": [
{ "selector": "h5.center", "alias": "name" },
{ "selector": "span.bio", "alias": "bio" },
{ "selector": "label.card img", "alias": "profile_image" }
]
}
]
}
' http://localhost:8020/api/v1/create
On successful creation, an ID should be returned to you, which can be used to update or delete the call.
Before submitting a new call, it might be wise to test your call first, to see if the response is retrieved that you might want. To do so, simply call the /test endpoint, with the same parameters as you would the /create endpoint.
curl -v -X POST -H "Content-Type: application/json" -d'{
"website_name": "wecamp",
"website_url": "http://weca.mp/2017/",
"endpoints": [
{
"name": "coaches",
"selectors": [
{ "selector": "h5.center", "alias": "name" },
{ "selector": "span.bio", "alias": "bio" },
{ "selector": "label.card img", "alias": "profile_image" }
]
}
]
}
' http://localhost:8020/api/v1/test
You can retrieve information about a call, including the endpoint and selectors, by calling the /info/
curl http://localhost:8020/api/v1/info/wecamp/coaches
}
To call the data you created in the create call, simply use the website name and endpoint name in your url as such: