Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new client with sdk #822

Open
SlackingVeteran opened this issue Jan 22, 2018 · 12 comments
Open

Create new client with sdk #822

SlackingVeteran opened this issue Jan 22, 2018 · 12 comments

Comments

@SlackingVeteran
Copy link
Contributor

I was trying to figure out if android sdk allows to register new clients through sdk as well, I have searched a lot and no avail so far. Documentation has no references about creating new client. I have been able to initialize with existing users and use sdk to place calls but to add new client i have to login as administrator and add new client through the web page. It would be great if anyone can provide me some info about how to do it through sdk.

@SlackingVeteran
Copy link
Contributor Author

The only reference I have found so far is by using RestComm API for clients for which I have to use post http request. Its doable for now but exposing the method through sdk would have been lot better.

@gsaslis
Copy link
Contributor

gsaslis commented Jan 24, 2018

@atsakiridis @ognjenns could you plz share some feedback here?

@atsakiridis
Copy link
Collaborator

@suyashbhatt you are right, this is the way its working right now; you need to take care of creating a client yourself. We are aware of the pain in this part and have plans on improving the UX in this part. Some ideas are either creating a default client per account, or taking care of it inside the SDK as you propose. Let me try to get back to you when I have more news on that.

@gsaslis
Copy link
Contributor

gsaslis commented Feb 5, 2018

@atsakiridis thanks for the feedback here!

In that case, do you think it's worth putting a small note at the docs, documenting this fact (and guiding ppl how to create this client)?

@SlackingVeteran
Copy link
Contributor Author

SlackingVeteran commented Feb 5, 2018 via email

@atsakiridis
Copy link
Collaborator

Sure @gsaslis let me open an issue for that. Thanks @suyashbhatt let me get back to you when I have more information

@atsakiridis
Copy link
Collaborator

Opened #846 for this

@gsaslis
Copy link
Contributor

gsaslis commented Feb 12, 2018

cool @atsakiridis - thanks!

@suyashbhatt any luck getting this off the ground in the meantime?

@SlackingVeteran
Copy link
Contributor Author

SlackingVeteran commented Feb 12, 2018

I was successfully able to create new clients and authenticate within my android app. As I mentioned in my last comment I had to use retrofit to make post request and okhttp to create authentication token for retrofit.

@gsaslis
Copy link
Contributor

gsaslis commented Feb 13, 2018

great stuff @suyashbhatt !

In that case, could you perhaps share a code snippet here, for anyone else that stumbles across the same issue?

@SlackingVeteran
Copy link
Contributor Author

Create retrofit interface:

import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Path;

public interface RetrofitService {
    @FormUrlEncoded
    @POST("Accounts/{accountSid}/Clients.json")
    Call<Object> createClient(@Path("accountSid") String accountSid, @Field("Login") String login, @Field("Password") String password);
}

Create new client from Activity:

// Register user to restcomm
OkHttpClient okHttpClient = new OkHttpClient().newBuilder().addInterceptor(new Interceptor() {
    @Override
    public okhttp3.Response intercept(Chain chain) throws IOException {
        Request originalRequest = chain.request();
        Request.Builder builder = originalRequest.newBuilder().header("Authorization", Credentials.basic("Replace with your Account Sid", "Replace with your Account API Secret"));

        Request newRequest = builder.build();
        return chain.proceed(newRequest);
    }
}).build();
Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("http://your-ip-address:8443/restcomm/2012-04-24/")
        .addConverterFactory(GsonConverterFactory.create())
        .client(okHttpClient)
        .build();
mRetrofitService = retrofit.create(RetrofitService.class);
mRetrofitService.createClient("Replace with your Account Sid", "Replace with new client username", "Replace with new client password").enqueue(new Callback<Object>() {
    @Override public void onResponse(Call<Object> call, Response<Object> response) {
        Log.d(TAG, "onResponse: " + response.body().toString());
    }

    @Override public void onFailure(Call<Object> call, Throwable t) {
        Log.e(TAG, "onFailure: " + call, t);
    }
});

@atsakiridis
Copy link
Collaborator

Thanks for sharing @suyashbhatt, much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants