Is it possible to call a webservice from UIAutomation?
on this webpage http://www.geonames.org/export/ajax-postalcode-autocomplete.html
it is possible to type in country and postal code, and get following reponse
http://api.geonames.org/postalCodeLookupJSON?postalcode=2830&country=DK&username=demo
{"postalcodes":[{"postalcode":"2830","countryCode":"DK","lng":12.4666667,"placeName":"Virum","lat":55.8}]}
Im fairly new to this, is there a way i can call the service with arguments or build the url myself and call that and get a response as JSON into UIAutomation?
You can do it like this:
var result = target.host().performTaskWithPathArgumentsTimeout("/usr/bin/curl", ["http://yoururl"], 30);
var json = JSON.parse(result.stdout)
Related
I am trying integrate the new Twitter API specifically the streaming tweets part in my android app, I am using Retrofit for my http calls.
When I try to make the call to get the streaming tweets it just hangs and does not return anything.
this is my retrofit call
#Streaming
#GET("tweets/search/stream")
suspend fun getFilteredStream(#Header("Authorization") token:String)
I then tried making a call with just OkHttp as shown in the documentation I get a successful response but I dont know how to stream the data.
I can make the call successfully via a curl call and see the data no problem.
How do I stream the data via retrofit or OkHttp
Update:
With OkHttp I was able to get data by doing this
val client: OkHttpClient = OkHttpClient().newBuilder()
.build()
val request: Request = Request.Builder()
.url("https://api.twitter.com/2/tweets/search/stream")
.method("GET", null)
.build()
val response: Response = client.newCall(request).execute()
val source = response.body?.source()
val buffer = Buffer()
while(!source!!.exhausted()){
response.body?.source()?.read(buffer, 8192)
val data = buffer.readString(Charset.defaultCharset())
}
data holds the string data representation of multiple tweet objects but how do I read one tweet at a time, or parse the response like this?
From the docs, I think you'll need to combine the two examples you have.
https://github.com/square/retrofit/blob/108fe23964b986107aed352ba467cd2007d15208/retrofit/src/main/java/retrofit2/http/Streaming.java
Treat the response body on methods returning {#link ResponseBody ResponseBody} as is, i.e. without converting the body to {#code byte[]}.
And example calling code
https://github.com/square/retrofit/blob/108fe23964b986107aed352ba467cd2007d15208/retrofit/src/test/java/retrofit2/CallTest.java#L599
I suspect, dependending on the JSON API you use you may be able to use a Streaming API from the response body. But if not you could split on either just newline or newline followed by { on next line and parse individually. Sorry I can't help here.
See https://en.wikipedia.org/wiki/JSON_streaming#Concatenated_JSON
I need to get the permission to access to specific URL, but before that I need to get the responseKey, and the way to get the responseKey is to access to this URL in the browser: https://api.getgo.com/oauth/v2/authorize?client_id={consumerKey}&response_type=code. After accessing
it contains the responseKey what I need. It will look something like: http://example.com/oauthreturn/?code={responseKey}. The question is how I can get the responseKey in code in google-apps-scrpits.
This what i wrote:
function myFunction() {
var client_id='xxxxxxxxxxxxxxxxx'
var url ="https://api.getgo.com/oauth/v2/authorize?client_id="+client_id+"&response_type=code";
var resp = UrlFetchApp.fetch(url)
}
but I get a HTML code response
In your code var resp = UrlFetchApp.fetch(url) will create a HTTPResponse object. First, you will want to know if the response code is 200 OK. To gather that information you should use getResponseCode() and check if it equals to 200. If that is the case, then you must parse the code. To do that you can first use getContentText() and after that parse(). One example implementation, that is compatible with your code, can be this one:
if (resp.getResponseCode() == 200) {
var results = JSON.parse(resp.getContentText());
}
You can then access to the data referring to that variable and the name of the parameter. For example, you could use results.code, results.token… If this explanation doesn't clarify your question, please ask me again for further help.
I am trying to do an upload via api, when the data is small eg:100 rows the upload works fine and I get the response as expected but when the upload is large, eg:1M rows, the test fails with Time-out-exception. How can I handle this? Is Thread.sleep() a recommended method?
You can use like this. if it is not working, please provide code.
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(5000)
.setSocketTimeout(5000).build();
HttpClientConfig httpClientFactory = HttpClientConfig.httpClientConfig()
.httpClientFactory(() -> HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build());
RestAssured.config = RestAssured.config().httpClient(httpClientFactory);
I was using an HTTP POST method using the URL
"https://stream.twitter.com/1.1/statuses/filter.json" and in the body I was posting the key/value I wanted to get tweets from - for example "track=london". This was working fine.
Now I am trying to switch to AKKA-CAMEL and I am using their twitter consumer. I am using an endpoint URL of:
def endpointUri: String = s"twitter:////search?type=direct&keywords=${Settings.queryList()}&consumerKey=${tweeterCredentials.consumerKey}&consumerSecret=${tweeterCredentials.consumerSecret}&accessToken=${tweeterCredentials.accessToken}&accessTokenSecret=${tweeterCredentials.accessTokenSecret}"
I get a response from twitter but it is not in JSON and it is not the same information about the tweet as before. It just return the tweet text but before I was getting the whole metadata which I need to analyze.
Does somebody knows how to configure Camel URI to return JSON and the whole metadata as before?
Thanks
I got this to work by using the following syntax:
def endpointUri: String = s"twitter://streaming/filter?type=event&keywords=${Settings.queryList()}&consumerKey=${tweeterCredentials.consumerKey}&consumerSecret=${tweeterCredentials.consumerSecret}&accessToken=${tweeterCredentials.accessToken}&accessTokenSecret=${tweeterCredentials.accessTokenSecret}"
Where: Settings.queryList return a comma separated list of keyworkds. The object tweeterCredentials holds the keys from Tweeter to access the site.
Also it is necessary to set autoAck like this in Camel:
override def autoAck = true
This prevents a timeout exception.
i've got an android app and a really simple web service that make an insert in a DB with 3 values.
the titanium code is most like the example given on the docs
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function(e) {};
xhr.open('POST','http://www.micheleantonaci.altervista.org/test/foobar.php');
xhr.send({
"latitude":00100,
"longitude":10000,
"type":'From Nexus'
});
and the web service is just
<?php
$con=mysql_connect('http://www.micheleantonaci.altervista.org/','***','***');
mysql_select_db('***',$con);
if(isset($_REQUEST['submit']))
{
$latitude=$_POST['latitude'];
$longitude=$_POST['longitude'];
$kind=$_POST['type'];
$sql="insert into foobar (latitude,longitude,type) values ('$latitude','$longitude','$kind')";
$res=mysql_query($sql) or die (mysql_error());
}
?>
now, when i try the webservice giving the values with the browser it works good, but with the app I get no results at all, any suggestions? tha app doesn't crash or log any error
You must use PHP function json_decode to get values.
Try adding the header like this:
xhr.setRequestHeader("Content-Type", "application/json");
You should also do a var_dump($_POST) in your PHP to see what's in it, not sure you'll get your stuff in separated variables...
When I see a problem like this, I setup 'Charles' or a similar proxy and have the device send it's request through the proxy. Then you can see if the device is send what is expected.
You could also try
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
The code is right, the problem was on the framework itself, at that day the post method wasn't working.
Nowadays it has been fixed.