To configure the service, replace the parameters at the beginning of the file with your service parameters:
#Service details my $service_id = "example.com"; my $service_secret = "servicesecret"; #Notifications recipient - url encoded nid my $user = "nidvalue"; my $encoded_nid = urlencode($user);
The first two variables define the Service ID and Service Secret for the developed service. These parameters are mandatory when sending notifications to client applications. The Service Secret is used to authenticate the REST API requests sent by the service.
You need to replace the example values above with the values that you received when you registered your service.
The last parameter defines the recipient of the notification.
The next step is to create the create the cURL request from the parameters specified in step 1.
Nokia recommends using the WWW::cURL::Easy client instead of clients such as LWP::UserAgent.
#This example uses nid for pushing the notification my $request_uri = "https://alpha.one.ovi.com/nnapi/1.0/nid/$encoded_nid"; my $request_parameters = "payload=Test Notification from REST API"; #Initialize curl my $curl = WWW::Curl::Easy->new; $curl->setopt(CURLOPT_URL, $request_uri); $curl->setopt(CURLOPT_POST, 1); #TRUE $curl->setopt(CURLOPT_POSTFIELDS, $request_parameters); $curl->setopt(CURLOPT_HTTPAUTH, 2); #CURLAUTH_DIGEST $curl->setopt(CURLOPT_USERPWD, "$service_id:$service_secret");
The last step is to execute the request:
my $retcode = $curl->perform; if ($retcode == 0) { my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE); print "\nHTTP Response from Notifications API: $response_code\n"; } else { print("\nAn error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf."\n"); }