kfami/inpsyde-endpoint

Inpsyde Endpoint is a plugin that has been built to show my skills towards my job application at Inpsyde.

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Type:wordpress-plugin

1.4 2021-04-02 08:34 UTC

This package is auto-updated.

Last update: 2021-04-02 08:36:23 UTC


README

Inpsyde Endpoint is a plugin that has been built to show my skills towards my job application at Inpsyde. In the whole context, I'm using `we` instead of `I` while asuming being a representator of the plugin organisation.

Here is the description about the work:

We are using composer as dependency manager and object oriented convention for building the whole project. As per required by WordPress styling, we are loading the autoload file in the main file of the plugin. This makes all the classes available during required calls.

Installation:

Method 1. Simply copying to the plugins directory

To use the plugin, just clone the git repository https://kfami@bitbucket.org/kfami/inpsyde-endpoint.git and run composer update. The plugin is now ready to be added to your WordPress website. Then just copy the plugin folder to wp-content/plugins directory of your WordPress installtion and activate the plugin from the WordPress admin.

Method 2. Using composer in the WordPress

If you are managing your plugins as composer dependencies in your project. Just require "composer/installers": "~1.0" add the following configuration to your composer.json file before the last closing curly brace }.

"extra": {
    "installer-paths": {
        "wp-content/plugins/{$name}/": ["type:wordpress-plugin"]
    }
}

You may need to update the installation paths based on your project. After updating the composer.json file, please don't forget to run composer update.

Then fire composer require kfami/inpsyde-endpoint in termial to install the plugin like you do for installing other dependencies.

How the plugin works:

The plugin is working exactly the same as per the requirements shared in the task and here is the brief summary about it's working:

Method 1. Using Custom Endpoint

We have set up a custom endpoint for the users data table to be shown on a WordPress page. The data shown on the page is coming from the external url: https://jsonplaceholder.typicode.com/users. We are using inbuilt WordPress function wp_remote_get() for this purpose. The default custom endpoint is /users which can be customized through the settings page in the WordPress admin panel.

Method 2. Using Shortcode

If you want to display the users information on more than one pages, somewhere between your own page or inside your post. You can also use the [inpsyde_endpoint] shortcode.

Working within the page:

In the users table there is basic information about each and every user. But you can find more information by clicking on any of the information links provided in the each user's row in first three columns which are ID, Name and Username. This click loads data with ansynchronous javascript AJAX on the page. We have programmed this feature to show detailed information about only one user at a time. So, whenever you click any link, if it is already showing any user, it will replace the current user information with new one. We are using vanilla javascript for this purpose. We preffer not to use any library for such simple tasks.

Error Handeling:

Even if the request is done through AJAX, we still require the running internet connection to process it. If the internet stops working after loading the main users page the links won't work. So the plugin will display error message within the page for these kind of situations.

User Experience:

To maintain better user experience, we are using a loading spinner on click of the links. This helps the user to remain patient if the internet connection is too slow and/or requests take time more than expected. The page is automatically scrolled to the location of user's detailed information table on click of every link. So the user will not be confused about place of information to be displayed.

Styling:

The plugin is desinged to follow the installed theme styling. This means the page will look like seamless part of your website. Hence, we are not writing any custom css style to interfere with your theme styling.

Important Note:

The plugin is designed to auto discover the API url based on the permalink settings. But still if any page is already open and you change the permalink settings, consider refreshing the already opened pages.

Caching

We are using WordPress's inbuilt caching mechanism WordPress Transients to support caching in this project. While we were working on the project the max-age of the data received was 43200 seconds. But we have set the cache control to 3600 seconds. As of general disccussion we could also programed it to automatically set transient expiration from max-age parameter. But we felt the time 43200 seconds too long for caching so we are using 3600 seconds.

Admin Page

We have also provided a settings page in WordPress admin with menu name of Inpsyde Settings. You can fine tune the settings if the plugin is installed and active. You can change the default /users endpoint. Also we are sharing the shortcode [inpsyde_endpoint] to be used in any page.

Automated Tests

The automated tests were inspired by Mr. Giuseppe Mazzapica through url: https://giuseppe-mazzapica.gitbook.io/brain-monkey/. We are using Brain Monkey to monkey patch the functions without loading the WordPress API. We are also using "fzaninotto/faker": "^1.9" and "brain/faker": "dev-master" to simulate fake data during testing.

About the dependencies

To achieve all the requirements of the task, we have used the following dependencies:

"inpsyde/php-coding-standards": "^0.13.4"
"brain/monkey": "2.*"
"phpunit/phpunit": "^8.5"
"fzaninotto/faker": "^1.9"
"brain/faker": "dev-master"
  • "inpsyde/php-coding-standards": "^0.13.4" is required to match the code styling of Inpsyde.
  • "brain/monkey": "2.*" is used to do monkey patching of methods during unit testing.
  • "phpunit/phpunit": "^8.5" is used to perform unit tests on the project.
  • "fzaninotto/faker": "^1.9" is used to simulate fake data for the external API calls during testing.
  • "brain/faker": "dev-master" is used to simulate fake WordPress objests during testing.

Unit Tests

To run tests included in the package run ./vendor/bin/phpunit in your terminal.

PHPCS Checks

To run phpcs you need to give files as arguments in the termial. We tried all files in src and public folder along with the main plugin file inpsyde-endpoint.php. To fire checks for the same configuration, you can run ./vendor/bin/phpcs --standard="Inpsyde" src inpsyde-endpoint.php public in your termial.

About Translations

We are assuming that there is no requirement of multi lingual translations for this project. Hence using plain text everywhere in the whole project without any provision of translated domain or language specific text.

License and Copyright

Copyright 2021 Varun Kumar

The project is licensed under the Apache License, Version 2.0. You could read more at LICENSE. We are using an opern source license so you could use in any way you want to use it.