API REST SoapUI POST - BOSE Speaker API - api

OK apologies, I have never used REST and i'm struggling to get to grips with an API.
So i'm using soapui to process the requests. I can run GET fine as it's just returning data, but I cannot work out how to post.
for example:
http://10.0.1.75:8090/info
Returns all info about the device.
So to control the device I need to send this:
http://10.0.1.75:8090/key
<key state="press" sender="Gabbo">$KEY_VALUE</key>
<key state="release" sender="Gabbo">$KEY_VALUE</key>
This seems so simple I must be missing something but I cannot see how to post these parameters in soapui? Once i've worked out one I can write the whole API.
Thanks in advance.

This example should answer your question:
<body>
<button onclick="postVolume(0)">Volume 00</button>
<button onclick="postVolume(10)">Volume 10</button>
<button onclick="postVolume(20)">Volume 20</button>
<button onclick="postVolume(30)">Volume 30</button>
<button onclick="postVolume(40)">Volume 40</button>
<script>
function postVolume(volume) {
var xml = '' +
"<?xml version='1.0' encoding='UTF-8' ?>" +
"<volume>" + volume + "</volume>";
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","http://10.0.1.75:8090/volume",true);
xmlhttp.send(xml);
};
</script>
</body>
Hope this will help you :-)

Related

ReCAPTCHA doesn't work on localhost

I'm building a website with a form with reCAPTCHA check. As required from Google documentation, I've created a key for the target domain. Then, I've created a form containing reCAPTCHA section
HTML form
<form method="post" action="index.php">
<div class="g-recaptcha" data-sitekey="PUBLIC_KEY"></div>
<input type="submit" name="submit" />
</form>
PHP response check
When form is submitted, reCAPTCHA response is verified (in this example, it's simply printed).
$recaptcha = filter_input(INPUT_POST, 'g-recaptcha-response', FILTER_SANITIZE_STRING);
$googleurl = "https://www.google.com/recaptcha/api/siteverify";
$privatekey = "PRIVATE_KEY";
$remoteip = $_SERVER['REMOTE_ADDR'];
$curl = new Curl($googleurl."?secret=".$privatekey."&response=".$recaptcha."&remoteip=".$remoteip);
$response = json_decode($curl->exec(), true);
print_r($response);
die();
Curl is a class that simply builds a curl request and return result.
The problem
The snippet works fine online and I've checked $response values both with success and error cases. But during development, I must use it on localhost too. As stated in this post, all keys should work locally. But when I run the code, nothing is shown.
Though this question is older I post the answer because many people may run into the same problem. I think that this may be related to the general authentification problem with running reCaptcha on localhost which can be solved using secure token
I posted the solution here for reference
UPDATE - the working code:
For secure token generation I'm using slushie's php implementation
The PHP part:
<?PHP
use ReCaptchaSecureToken\ReCaptchaToken as ReCaptchaToken;
require_once("libs/ReCaptchaToken.php");
//Generate recaptcha token
$config = [ 'site_key' => 'place-your-site-key-here',
'site_secret' => 'place-your-secret-key-here'
];
$recaptcha_token = new ReCaptchaToken($config);
$recaptcha_session_id = uniqid('recaptcha');
$recaptcha_secure_token = $recaptcha_token->secureToken($recaptcha_session_id);
?>
The HTML:
<html>
<head>
...
<script src='//www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form>
...
<div class="g-recaptcha" data-sitekey="place-your-site-key-here" data-stoken="<?PHP echo $recaptcha_secure_token; ?>"></div>
</form>
</body>
</html>

Apps Script webapp: how to authenticate bigquery?

I am trying to get my apps script webapp to execute as "user accessing the webapp", but its bigquery should run as me, the developer. (If I run the webapp as me, everything works...) I looked at the documentation at https://developers.google.com/bigquery/docs/authorization. There is no apps script example, so I tried to get the javascript example working.
<html>
<head>
<script src="https://apis.google.com/js/client.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
function auth() {
gapi.auth.authorize(config, function() {
gapi.client.load('bigquery', 'v2');
$('#client_initiated').html('BigQuery client authorized');
$('#auth_button').fadeOut();
$('#dataset_button').fadeIn();
});
}
// User Submitted Variables
var projectNumber = 'XXXXXXXXXX';
var clientId = 'XXXXXXXXXX.apps.googleusercontent.com';
var config = {
'client_id': clientId,
'scope': 'https://www.googleapis.com/auth/bigquery'
};
function listDatasets() {
var request = gapi.client.bigquery.datasets.list({
'projectId':projectNumber
});
request.execute(function(response) {
$('#result_box').html(JSON.stringify(response.result.datasets, null));
});
}
</script>
</head>
<body>
<button id="auth_button" onclick="auth();">Authorize</button>
<div id="client_initiated"></div>
<button id="dataset_button" style="display:none;" onclick="listDatasets();">Show datasets</button>
<div id="result_box"></div>
</body>
</html>
I generated a client id as a browser app with https://script.google.com as the server address. With the code above, I get this error: Cannot read property 'authorize_m___' of undefined.
My question is twofold: 1) Would an apps script webapp authenticate in the same way as the javascript app authenticates? I.e. can I use that code as a guide for my apps script?
And 2) any suggestions about how to debug the javascript sample code? Note that I ran this code as an apps script webapp.... That is probably an error....
The answer... or workaround answer is given here: How to pass parameters from one Google-Apps-Script to another and execute?
I can use two stage authentication in place of direct authentication: the user logs in as him/herself, I get the user's name to find their files, then switch to a webapp that uses BigQuery and execs as me, the developer.
A good workaround for advanced services authentication under apps scripts....

Play framework 2.04 browser request is hanging once multipartFormData maxlength has been reached. How to solve it?

My server side code is the following (just for the sake of testing it):
def upload = Action(parse.maxLength(maxLength = 10*1024, parser.multipartFormData)) {
implicit request =>
Logger.info("data: " + request.body.dataParts)
Logger.info("file: " + request.body.file("picture"))
Logger.info("req: " + request.contentType)
Logger.info("req body: " + request.body)
Ok("File has been uploaded")
}
My client side code is a simple form that has an input of type file.
#helper.form(action = routes.Application.upload, 'enctype -> "multipart/form-data") {
<p>
<input type="text" name="name" />
</p>
<p>
<input id="imageFile" type="file" name="picture" accept="image/*" />
</p>
<p>
<input type="submit" value="Save" />
</p>
}
The problem is that if you try to upload files that are bigger than 10KB the browser will hang waiting for the server to finish even though it appears that the server has finished consuming the request. How to solve it?
Unfortunately, there seems to be a problem related to this in Play 2.0.4 and the browser will hang waiting for the file to finish uploading even though the request body has been consumed in the server side. A discussion regarding the issue can be found here and it was reported here (play doesn't finish consuming request if maxlength is reached).
Fortunately, this has been resolved in Play 2.1 and the first release candidate is already available. So, the best thing to do would be to migrate your app to Play 2.1.

trying to stream music using soundcloud sdk

hi guys am new to java script..
I am trying to stream a sound track in soundcloud using their java script SDK but my code is not working please let me know how to make this work. Below is my code
<!DOCTYPE html>
<html><head>
<script src=”http://connect.soundcloud.com/sdk.js”></script>
<script src=”http://code.jquery.com/jquery-1.7.1.min.js”></script>
<script>
SC.initialize({
client_id: “15c5a12b5d640af73b16bd240753ffbb?,
redirect_uri: “http://connect.soundcloud.com/examples/callback.html”
});
$("#stream").live("click", function(){
SC.stream("http://api.soundcloud.com/tracks/293", {autoPlay: true});
});
</script>
</head>
<body>
<input type="button" href="#" id="stream" class="big button" value="Stream It Again, Sam" />
</body>
</html>
A couple of things I can spot, that may just be a result of copy & pasting your code, but good to check anyways:
You've got a combination of smart quotes (i.e. ”) and dumb quotes (i.e. ") in your code. Change all of the smart quotes to dumb quotes.
Your client_id has a ? appended to it. Replace the ? with a ".
Make those changes, reload and you should be off to the races.
Btw, for your example here you can also omit the redirect_url. Having it there won't do any harm though:
SC.initialize({
client_id: "15c5a12b5d640af73b16bd240753ffbb"
});
In addition to the changes mentioned above, changing the JQuery version to 1.4 worked for me.

Ajax call not working in Google gadget

I have a conversion rate script which i know works perfectly outside of a Google gadget however i cannot figure out why it doesn't work inside of a gadget.
Here is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs author="Purefx.co.uk" height="280"></ModulePrefs>
<UserPref name="title" display_name="Widget Title" default_value="Currency Converter"/>
<UserPref name="color" display_name="Widget color" default_value="Color" datatype="enum">
<EnumValue value="Color"/>
<EnumValue value="Black and White"/>
</UserPref>
<UserPref name="style" display_name="Widget Style" default_value="Sidebar" datatype="enum">
<EnumValue value="Sidebar"/>
<EnumValue value="header/footer"/>
</UserPref>
<UserPref name="attribution" display_name="Attribution text" default_value="Purefx" datatype="enum">
<EnumValue value="Purefx"/>
<EnumValue value="Foreign Exchange"/>
<EnumValue value="Currency exchange"/>
</UserPref>
<Content type="html"><![CDATA[
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#convert').click(function(){
//Get all the values
var amount = $('#amount').val();
var from = $('#from').val();
var to = $('#to').val();
//Make data string
var dataString = "amount=" + amount + "&from=" + from + "&to=" + to;
$.ajax({
type: "POST",
url: "ajax_converter.php",
data: dataString,
success: function(data){
//Show results div
$('#results').show();
//Put received response into result div
$('#results').html(data);
}
});
});
});
</script>
]]>
</Content>
</Module>
I haven't included the html part of the content or the php script as that part is 100% working and irrelevant to this problem.
I think the problem is specifically the execution of the Ajax call, on clicking 'convert' nothing is being 'posted' in the firebug console window.
I can't find anything that might suggest i'm missing something so any thoughts are appreciated.
Many thanks in advance
You cannot make direct calls from inside a gadget because a gadget lives inside a gadget container and all calls are proxied by the gadget container.
You must use io.makeRequest to fetch remote data.
More info, see http://code.google.com/apis/gadgets/docs/remote-content.html