Sunday 26 February 2017

How to get hot trends Using Google trends api php

Google Trends is a public web facility of Google Inc., based on Google Search, that shows how often a particular search-term is entered relative to the total search-volume across various regions of the world, and in various languages. 
From: en.wikipedia.org/wiki/Google_Trends

Use following code to get the hot trends from google. 
  
try {            
            $url='http://www.google.com/trends/hottrends/atom/hourly';                        
            $client = new Zend_Http_Client($url);
            $response = $client->request('GET');
            $jsonData = ($response->getBody());
            echo 'Google Trends';            
            preg_match_all('/(.*)<\/a>/', $jsonData, $trends);
            /** preg_match_all('/(.*)<\/a>/', $jsonData, $trends);**/
             foreach($trends[0] as $trend) {
                echo "{$trend}";
                }

        } catch (Exception $e) {
            echo 'Error' . $e->getMessage();
        }     

Swagger UI - REST API tool

Question: What is swagger?
It is REST API documentation tool which is used to list the APIs and view the request and response.
In this, we need to add some annotations in your functions and then it will automatically generate a beautiful and user-friendly documentation for your APIs.


Question: Where it is used?
Whenever we develop an android, IOS (Apple) application, we need to create an APIs for them. 

To check the API details (URL, Request, response), we use Swagger.


Question: Who is using swagger?
Backend Developer: developer used it while creating Or updating an API.
Team Leader: As it give List of APIs with request and response. Team leader used it review the APIs.
Android/IOS Developer: While integrating the APIs, Its quite help the developer because they can check the response of APIs with different request. 


Question: What are benefits of swagger?
  1. Its give list of APIs with short description.
  2. Its give the Request and Response of API.
  3. We can test the response of API with different request.
  4. We need to integrate in application first time, after the we need to add some annotations in functions/APIs.
  5. Can be integrate in Core PHP or Framework.
  6. We need not to list and details of apis manually.



Question: What is Swagger Editor?
The Swagger Editor is the tool for quickly getting started with the Swagger Specification. 
Create new APIs OR update existing ones in a powerful Editor which visually renders your Swagger definition and provides real time error-feedback.
http://editor.swagger.io/#/


Question: Give a Demo URL?
http://petstore.swagger.io/


Question: From where i can download?
http://swagger.io/docs/#swagger-ui-documentation-29


Question: How to Add API in swagger?
Add Following code before the class declaration

/**
 * @SWG\Resource(
 *     apiVersion="1.0",
 *     swaggerVersion="1.2",
 *     description="Search users"
 * )
 */



Question: How to add new Operation for an API?
Add Following code before the method declaration
    /**
     * @SWG\Api(
     *     path="/search",
     *     @SWG\Operation(
     *         method="POST",
     *         summary="Get users near your location",
     *         type="Users list",
     *         @SWG\Parameters(
     *             @SWG\Parameter(
     *                 name="interests",
     *                 paramType="form",
     *                 description="comma seperated looking for",
     *                 required=false,
     *                 type="string",
     *                 minimum="1.0"
     *             ),
     *             @SWG\Parameter(
     *                 name="page",
     *                 paramType="form",
     *                 description="page number",
     *                 required=true,
     *                 type="string",
     *                 minimum="1.0"
     *             ),
     *         ),
     *         @SWG\ResponseMessage(code=400, message="Invalid Data")
     *     )
     * )
     */

Saturday 25 February 2017

Email Sending Using Node.js

Send email using nodejs,Angularjs and express in 5 simple steps

First of all I am going to more discuss Nodejs about sending (gmail,yahoo,etc.)e-mail with Node.js.
and then i am going to more use Angularjs.js and NodeMailer(Nodejs) package.


LIST OF FEATURES : Sending Email Using Node.js


1 : It works with SSL(secure)server and TLS(insecure) smtp servers
2 : in nodejs, supports new smtp authentication(auth.) (PLAIN,CRAMMD5,LOGIN.etc)
3 : in nodejs,all emails are queued (list )and the queue is sent (emails) asynchronously format
4 : in nodejs, supports sending Simple or more functionality html emails and basic emails templates with multiple(one or more) attachments (MIME)
5 : send mail with attachments(pdf,doc,txt,images.etc..) can be added as also strings,and other streams or url file paths send
6 : The header supports to the utf-8 headers pass data and body mail in nodejs

There are just List of 5 steps to sending an email using nodejs with angularjs

1 : First of all Install the node­mailer package.
2 : Create a transport object using nodemailer.createTransport() and pass it your email credentials.
3 : Prepare the message to be sent in the body(nodejs).
4 : info (cridentials)Create an object with (HOST,PORT,EMAIL,USERNAME,PASSWORD)information about the sender, email subject(Like ), recipient and the body content that we prepared earlier.
5 : Send the email using — transporter.sendMail() in nodejs

STEP 1: Step-by-step Install the node­mailer package in nodejs.

1 npm install nodemailer

STEP 2: Second step creating a transport the object in your application route handler in nodejs apps.

var sendnodemailermail = require('nodemailer');
var routersemail = express.Router();
app.use('/welCome', routersemail);
routersemail.post('/', sEmailhandleSHello); // nodejs handle the route at ng4free.com/welCome
function sEmailhandleSHello(req, res) {
    //and display Not the movie in transporter!
    var stransportermail = sendnodemailermail.createTransport({
        service: 'ng4free',
        auth: {
            user: 'admin@ng4free.com', // write Your email id required
            pass: '**!password@#$' //Setup Your password required
        }
    });
    ...//your content
    ...//your content
    ...//your content
}

STEP 3: Now Third step Prepare some content plaintext mail or HTML content send mail to be sent in the HTML body.
Now In this script,I am going to simply(plain mail) use some text(Like welcome to techieupgrader.in).


1 var data_text_mail = 'Welcome to ng4free.com \n\n' + req.body.name;

STEP 4: Cre­ate a sim­ple JSON object with the nec­es­sary val­ues for send­ing the email.


var SemailmailOptionsdata = {
    from: '<admin@youremail.com>', // write your Email sender address
    to: 'php@youremail.com', // write your Email list of receivers
    subject: 'My First Nodejs Email send', // write your Email Subject line
    text: data_text_mail //, // plaintext body
    // html: '<b>Welcome to techieupgrader.in
<img draggable="false" class="emoji" alt="✔" src="https://s.w.org/images/core/emoji/2/
</b>'
// You can choose to send an HTML body instead
};

STEP 5: Good luck. Actually send sucessfully the email using nodejs and handle display the response in nodejs.


transporter.sendMail(SemailmailOptionsdata, function(mail_error, resultdata){
    if(mail_error){
        console.log(mail_error);
        res.json({info: 'mail_error'});
    }else{
        console.log('Message sent: ' + resultdata.response);
        res.json({info: resultdata.response});
    };
});