How to use PHP variable in Swagger Annotations - swagger

First of all am so excited about this Swagger PHP, very expressive!
Is there any way we can give PHP variables within swagger annotations.
Below is my code:
define('API_PATH', '/api/demo');
/**
* #SWG\Swagger(
* basePath="{API_PATH}",
* host="11.7.11.16:xxxx",
* schemes={"http"},
Tried giving like $api_path inside annotation as well but its taking as string and API call is failing....
basePath="$api_path",
Any help will be appreciated

You could consider using the constant:
in constants.php
define('API_PATH', ''/api/demo");
in api.php
/**
* #SWG\Swagger(basePath=API_PATH, ...)
*/
Which can be loaded using the bootstrap option:
$ swagger --bootstrap constants.php api.php

Related

Doxygen anchor inside function

I have a filter which converts actual code into #code/#endcode blocks but I can't figure out a way to create a #ref link to these sections.
Here's a snippet of what I mean:
/**
* Refer to this example: #ref example1
* #param $arg1
* #param $arg2
*/
public function somefunction($arg1, $arg2)
{
/**
* #anchor example1 #code
if (true)
{
$this = 'bollox';
}
* #endcode
**/
}
The output of this looks pretty much like what I want (although I haven't decided on how best to truly indicate the link point...exmple1 springs to mind).
The problem is that the hyperlink for example1 links to the filename.html#example1.
I've checked the source and there is an anchor class being generated.
I understand I'm not really using anchor as documented.
Any suggestions welcome.
Note: I'm not specifically trying to get anchor to work...just want a hyperlink/bookmark to link a \ref (or similar).

Response code Null (0) today, app was working yesterday (API Integration)

I have integrated Asana task lists into my company's website for our development team. All was going well until today - the page I created now errors out with a response code of NULL (or 0). In my very limited experience, this is an issue with the Asana connection, correct? Is this something I can fix on my side or is Asana API currently down (considering this worked up until today)?
We are using the API key, not OAuth, as everyone who has access to this task list is on the same workspace.
Edit:
I have 2 api keys that I am working with - 1 for production, 1 for development. I switch them out when I hand over a branch for my boss to merge in.
Testing API key works just fine.
Production API key does not work - always a response code null when trying to pull back tasks.
I am brand new to API development and I do not know how to use curl to make these calls. I am using a library found here:
https://github.com/ajimix/asana-api-php-class/blob/master/asana.php
More specifically, here is my code:
/*
* We are only interested in the JVZoo workspace
* Unless we are testing, in which we will use Faith In Motion workspace
*/
$JVZ_workspace_id = 18868754507673;
$FIM_workspace_id = 47486153348950;
/*
* Which one are we using right now?
*/
$workspace = $FIM_workspace_id;
/*
* Now lets do the same thing with Projects
* There should only be one project - JVZoo.com
* Unless we are testing - More JVZoo Testing
*
* We do need to dynamically show the project name
* This will help on confusion if we are accidently in the
* wrong project
*
* Then start building an array with these pieces
*/
$JVZ_project = array();
$JVZ_project['id'] = 53244927972665;
$JVZ_project['name'] = "JVZoo.com";
$FIM_project = array();
$FIM_project['id'] = 54787074465868;
$FIM_project['name'] = "More JVZoo Testing";
/*
* Which one are we using?
*/
$project = $FIM_project;
/*
* In order to help reduce load time even more,
* we are not going to return the project name
*
* This way we do not need to ask Asana for the project information
* This does change the layout of the view, however
*
* And finally grab all tasks for each project
* Connection check
*
* Return all tasks from this workspace and hand-filter
* to show both assigned and followed tasks
*/
$tasksJson = $asana->getProjectTasks($project['id']);
if ($asana->responseCode != '200' || is_null($tasksJson))
{
$this->session->set_flashdata('error', 'Error while trying to get tasks from Asana, response code: ' . $asana->responseCode);
redirect_and_continue_processing('/dashboard');
return;
}
FIM is my test environment.
JVZ is my production environment.
/**
* Returns all unarchived tasks of a given project
*
* #param string $projectId
* #param array $opt Array of options to pass
* (#see https://asana.com/developers/documentation/getting-started/input-output-options)
*
* #return string JSON or null
*/
public function getProjectTasks($projectId, array $opts = array())
{
$options = http_build_query($opts);
return $this->askAsana($this->taskUrl . '?project=' . $projectId . '&' . $options);
}
I did a PR on the parameter passed in to line that is returned above. In my FIM environment, I get this:
https://app.asana.com/api/1.0/tasks?project=54787074465868&
For my production environment:
https://app.asana.com/api/1.0/tasks?project=53244927972665&

Parse a report with powershell

I'm trying to gather some statistics using powershell.
I have about 4,000 reports that look like this (all in their own Report.txt files - some have more fields. I've sniped it):
What I would like to do (thinking out loud) is take each [ ] and make that a csv header and then add each item under that header under it. Then I can run simple count statements against it and pull out some data. Maybe there is a better/easier way?
The idea is to have some like:
Requested Permissions: android.permission.INTERNET 3,562 of 4,000
Requested Permissions: android.permission.READ_SMS 1 of 4,000
etc...
So far i've stripped down the string so it no longer has white spaces and *.
[ Package name ]
* com.software.application
[ Requested Permissions ]
* android.permission.INTERNET
* android.permission.READ_PHONE_STATE
* android.permission.READ_SMS
* android.permission.RECEIVE_SMS
* android.permission.SEND_SMS
* android.permission.WAKE_LOCK
* android.permission.WRITE_EXTERNAL_STORAGE
* com.google.android.c2dm.permission.RECEIVE
* com.software.application.permission.C2D_MESSAGE
[ Responsible API calls for used Permissions ]
* android/app/NotificationManager;->notify
* android/content/Context;->sendBroadcast
* android/content/Context;->startService
* android/os/PowerManager$WakeLock;->acquire
* android/os/PowerManager$WakeLock;->release
* android/telephony/SmsManager;->sendTextMessage
[ Potentially dangerous Calls ]
* getSystemService
* HttpPost
* sendSMS
Current output example:
[PotentiallydangerousCalls]
getSystemService
HttpPost
sendSMS
So it's a bit cleaner now...
I will put some code if I have time, but here is a roadbook :
1) Write a function (CsvToObject) that take the path and name of a csv file and return a PSObject with a property with each [value]
This function can take advantage of switch ... case PowerShell structure with regex and file usage.
2) Take every *.csv file (Get-ChildItem) , call your function and pipe the result in Export-CSV
Your current output example is structured like an ini file. This Scripting Guy post on ini files might be useful. Some regex help here and here.

Drupal 7: Print pdf using dompdf

I need help in installation of dompdf. Where should I place the extracted zip file in the directory? I've followed the INSTALL.txt, and it says "Extract the contents of the downloaded package into one of the supported paths." Does it mean placing into "Modules" folder? if so, an error occurs requesting for ".info". And it's not supplied. Please help, I'm confused! Thanks!
The supported paths are listed in the install.txt file:
supported paths:
* print module lib directory (usually sites/all/modules/print/lib)
* libraries directory (sites/all/libraries)
I prefer the second option, it will keep you from having to do this every time you update the module.
In other words it should look like this sites/all/libraries/dompdf
here's how I loaded it
I moved the folder dompdf-0.5.1 to the /sites/all/libraries folder
I edited dompdf_config.inc.php by replacing the DOMPDF_autoload() function with:
Code:
function DOMPDF_autoload($class) {
/* Add this checking - START */
if (mb_strtolower($class)== 'firephp'){
return;
}
/* Add this checking - END */
$filename = mb_strtolower($class) . ".cls.php";
require_once(DOMPDF_INC_DIR . "/$filename");
}
if ( !function_exists("__autoload") ) {
/**
* Default __autoload() function
*
* #param string $class
*/
function __autoload($class) {
DOMPDF_autoload($class);
}
}
now you should be able use it like so in any other module
Code:
require_once(realpath('.')."/sites/all/libraries/dompdf-0.5.1/dompdf_config.inc.php");
spl_autoload_register('DOMPDF_autoload');
$obj = new DOMPDF();
This worked and I was able to use the DOMPDF object/class.

solr sanitizing query

I am using solr with ruby on rails.
It's all working well, I just need to know if there's any existing code to sanitize user input, like a query starting with ? or *
I don't know any code that does this, but theoretically it could be done by looking at the parsing code in Lucene and searching for throw new ParseException (only 16 matches!).
In practice, I think you're better off just catching any solr exceptions in your code and showing an "invalid query" message or something like that.
EDIT: Here are a couple of "sanitizers":
http://pivotallabs.com/users/zach/blog/articles/937-sanitizing-solr-requests
http://github.com/jvoorhis/lucene_query
http://e-mats.org/2010/01/escaping-characters-in-a-solr-query-solr-url/
If you are using Solarium with PHP then you can use the Solarium_Escape::term() method.
/**
* Escape a term
*
* A term is a single word.
* All characters that have a special meaning in a Solr query are escaped.
*
* If you want to use the input as a phrase please use the {#link phrase()}
* method, because a phrase requires much less escaping.\
*
* #link http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
*
* #param string $input
* #return string
*/
static public function term($input)
{
$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
return preg_replace($pattern, '\\\$1', $input);
}

Resources