Add helper `needs_api_tokens()`

Open
#44 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
backend

Research direction

Start with helpers.php and the existing Formats\GitHub, Formats\Twitter, and Formats\Facebook matches_host methods. Decide whether the helper should return service names or credential names, as the issue offers both options. Done means needs_api_tokens($url) identifies the required tokens for those services and returns an empty result for other URLs.

Written by the indexing model from the issue text.

Description

Might it be a good idea to add this helper function to helpers.php, now that there are 3 silo's that need API keys?

function needs_api_tokens($url) {
  if(Formats\GitHub::matches_host($url)) return 'github';
  if(Formats\Twitter::matches_host($url)) return 'twitter';
  if(Formats\Facebook::matches_host($url)) return 'facebook';
  return false;
}

Instead of these strings, we can also return an array of the credentials we expect.

function needs_api_tokens($url) {
  if(Formats\GitHub::matches_host($url)) return ['github_access_token'];
  if(Formats\Twitter::matches_host($url)) return ['twitter_api_key','twitter_api_secret','twitter_access_token','twitter_access_token_secret'];
  if(Formats\Facebook::matches_host($url)) return ['facebook_app_id','facebook_app_secret'];
  return [];
}
Dominant language
PHP
Stars
96
Forks
17
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from aaronpk/XRay

All issues in aaronpk/XRay

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.