Grape Rails API with Android - android

I want to achieve a rest client on Android with my custom Grape API (Ruby on Rails) and was wondering where to start (in others words, if there's good practice about implementing it on an Android OS... or any good and RECENT example about it.)
So far, I've been checking out this video on Rest from a Google talk.
I came across this code for a rest client too.
And just started reading this.
Thank you. I'll be posting my solution soon.
So basically, I have a method in my rest API (in Grape) that looks something like this.
"http://localhost:3000/api/signin/"
Basically, if I do this command line I can have access/authenticate:
curl -H "Accept: application/vnd.lzgo-v1+json" -d email=myuser -d password=mypassword http://localhost:3000/api/signin/
Now, I'm attempting to build a kind of generic way to access my API obviously on android.
So far, I've been going with this guy implement with the RestService.
Intent intent = new Intent(activity, com.android.lzgo.service.RESTService.class);
intent.setData(Uri.parse("http://localhost:3000/api/signin/"));
Bundle params = new Bundle();
params.putString("email", "myuser");
params.putString("password", "mypassword");
intent.putExtra(RESTService.EXTRA_HTTP_VERB, RESTService.POST);
intent.putExtra(RESTService.EXTRA_PARAMS, params);
intent.putExtra(RESTService.EXTRA_RESULT_RECEIVER, getResultReceiver());
Then I'm kind of confuse in the RestService implementation, when my case is a POST.
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
postRequest.setHeader("Accept", "application/vnd.lzgo.v1+json");
postRequest.setEntity(formEntity);
If you look at my URL on top, it's seems more like parameters, so I might use instead postRequest.setParams()...

I have learned, when you use the emulator, localhost refers to the device's own loopback service, not the one on your machine as you may expect.
I had to use 10.0.2.2 to access your actual machine, it is an alias set up to help in development.

Related

Tasker App: Why my HTTP POST is not sending parameters?

I'm making a simple HTTP POST request using Tasker app, it's working fine but somehow it's not sending my arguments. HTTP GET is working fine. What am I doing wrong?
The only thing the server does is JSON stringify all received parameters and return them like: Text: { parameters }
HTTP GET is working:
HTTP POST works, it returns the response "text: {}" but doesn't return any parameter:
Now sometimes it shows "Bad Request Error 400"
I've tested it with another server and this issue persists...
Here's a fiddle to send get and post requests to the same server and both work.
I've exported my task as xml for you to test: You can download it here
Thanks in advance guys!
I have done a little testing with what you have supplied. It appears that your post parameters are making it to the server but %HTTPR is not getting populated. The Tasker documentation says that this variable will be populated if the response is "text-based", but this does not seem to be the case. I may not know what Tasker considers to be "text-based", but I have tried "text/plain" and "text/html" with no luck.
The work-around that I have come up with is to put the response into a file using the "Output File" field of the post task. (Leave "Content Type" blank or this won't work.) You can then read the file into a variable and do what you need to.
This is either a defect in Tasker, incorrect documentation, or just a misunderstanding of what it takes to make it work. This work-around, however, will get you what you need.
Here is a link to a GitHub repository with the updated task export. You may need to change the output file name/location to work with your device.
Update:
Since I posted the above solution, I have run across a Tasker plugin called "RESTask for Tasker". Evidently, Tasker has enough issues with HTML requests that a separate plugin was needed. I have tested this plugin with POST and it does work, so this is another way to go. The plugin is available on the Google Play store.

Kairos API - get JSON response

I would like to use Kairos' API for face recognition. It seems a pretty good system, but have no idea, how to catch examples. If I use a string, it is empty after the process. There isn't any example about this in API documentation, nor in its GitHub repo: https://github.com/kairosinc/Kairos-SDK-Android
I try to connect to http://api.kairos.com, but maybe there is a problem with authentication, or should use URL with some parameters added. I cannot found any information about this.
You might be missing the proper APP_ID and APP_KEY headers. Check out this answered solution using a Curl example.

HTTP AUTH authentification NOT WORKING on ANDROID

I am working with an IP camera, i need to get the picture from my android application,
First i have made an application in JAVA "standard", i use the same code for receive the stream in my android app.
The problem : "Authenticator" is simply not working on android, Yes i know on android it's not a standard VM, but it's in the google code so ..
I use it for the "login"
Authenticator.setDefault(new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("user","pass".toCharArray());
}});
I find an other topic (I have search a lot about it ..) where people say "the google code have a problem" they was speaking about a fix, but the topic was made around 2006 - 2010 ... We are in 2014
I can only use it for connect my HttpURLConnection, i can't use the tweak with headers because it only works with "BASIC" authentification, me in my case i need it to work with "AUTH" authentification ...
PS : The most topic we found they speak for a "BASIC" authentification, who is more "easy" to do (just in the http header), but in my case I NEED TO USE the "AUTH" type
EDIT: I have the link about "some topics" who relate the problem :
https://code.google.com/p/android/issues/detail?id=9579
https://code.google.com/p/android/issues/detail?id=4326
(if it can help), but again, people who work with BASIC authentification, can tweak the headers for "conturning" the problem, but me i can't because it's "AUTH" type
Thanks for help,

Android Rest client to Delphi XE2 Datasnap Rest server

I found many examples on Stack Overflow and I just don't know where to start since I have a particular prerequisite:
My Delphi Datasnap Rest server is using ZLibCompression and RSA encryption (in TTransportFilterCollection of DSHTTPWebDispatcher). Is there an Android restful API that can handle those? Any sample that already implements that?
I found this thread Android REST client, Sample? as a good starting point, both lightweight and well-formed clients are presented but is it enough for me?
Thanks in advance for any hint, sample or library that you could point me to.
you can use the Android Rest-Client for sending data to a webservice
see my answer in the post Adding body of call to POST using HttpURLConnection
I just used the proxy generator from Danasnap server TDSProxyGenerator component (http://yourserver:port/proxy/java_android.zip) and added this code to my android project...
I had to search for the DSRESTSSLFactory.java file that is not generated by the proxy (but required !!), i found it in a demo from embarcadero, and from that point the communication is entirely handled, all accessible procedures are publicated, and really really simple to use...

how to call RESTful web service from android?

I have written REST web service in netbean IDE using jersey framework and java. For every request user need to provide username and password , I know the authentication is not good.
Using curl command like :
curl -u username:password -X PUT http://localhsot:8080/user
Now I want to call REST web service from android class.What should I write? I am new to android. I have a android class which use DefaultHttpClient and CredentialUsernameAndPassword.
But when i run in eclipse, sometime I get runtime exception or sdk exception.
Do anyone give me sample code and suggestion?
thanks
Do you use basic authentication? if so: use this.
if (username != null && password != null) {
client.getCredentialsProvider().setCredentials(
new AuthScope(null, -1),
new UsernamePasswordCredentials(username, password));
}
or you can add those in a header as setHeader("Authentication", "Basic "+Base64EncodedString(username,pass);
What you are doing is using Proxy authentication. why?
this article may also be helpful somehow:
link
also the -u stands for the ntlm authorization so maybe look into that too. there were some topics where it said it is not supported on android or something but i am sure if you need it you can make a workaround.

Categories

Resources