How to work with two Parse account in 'one' app - android

We are creating an Android launcher with several 'pre-installed' apps. These apps are actually part of the same code though to the user and from out perspective these apps are different logical units.
We work with Parse Core and would like to split the data into two different logical 'apps'. Can it be done?
We thought to call 'Parse.initialize' several times with different App & Client keys but then how should we proceed to report to different apps?
Thanks.

I have faced exactly the same issue a few months ago. Atleast, I was not developing a launcher. So, I'm posting my solution to the problem below.
Note: You cannot do it with Parse SDK
So the solution is to do it by having your app expose their own APIs. This has several advantages such as, your parse-apps could be owned by different accounts, while not violating the Parse terms of use.
TL;DR
Create two different apps and expose the API's using cloud code. Use a REST client to transact data back and forth.
Full Solution
The first step is to create two parse-apps, that you think suits individual needs of your launcher software. You can generate express servers for both the apps. Essentially, the result of this step is that, you will have two different apps with your own APIs to be consumed.
Now get rid of the Parse SDKs you might probably be using currently. Select a suitable REST client, in my case it was retrofit. Configure it such a way that it can consume different base-URLs for individual calls. The following is a Retrofit specific example.
A Function that Returns a REST Adapter with a Base URL
public FirstAppApi getFirstAppApi() {
return new RestAdapter.Builder()
.setEndpoint("http://app-one.parseapp.com/")
.build()
.create(FirstAppApi.class);
}
In this example FirstAppApi is essentially a Retrofit interface. Similarly, you can create adapter for the second parse-app as well. Now, to do a data transaction, its just a matter of deciding which app you should use. See a few examples below.
// Get an author from the first Parse app
Author author = getFirstAppApi().getAuthorByName("Shakespeare");
// Get books of the author from the second Parse app
List<Book> books = getSecondAppApi().getBooksByAuthor(author);
A few things needs to be taken care in this implementation. The API is exposed publicly, eventhough the app name, and thus the base-url is known only to you. So, the API should be well secured when completed. You should double confirm with Parse guys that it does not violate their terms of use.

I think you can try to repackage jar-files of Parse SDK with jarjar tool.
Another way is to get source code of Parse SDK(it is opensourced) and refactor it (change package name).
After you do it you can work with two Parse accounts using different classes:
com.parse.Parse.initialized();
com.parse2.Parse.initialized();
If you use Parse's offline storage only second option is available. But you also have to change database name for second Parse instanse (com.parse2.Parse). You need to change com/parse2/OfflineSQLiteOpenHelper.java
/** package */ class OfflineSQLiteOpenHelper extends ParseSQLiteOpenHelper {
// ...
/**
* The SQLite Database name.
*/
private static final String DATABASE_NAME = "ParseOfflineStore2"; // <=====
private static final int DATABASE_VERSION = 4;

Related

To create a Tendermint Private LAN BlockChain and access it

I am working on a review submission project on Tendermint in Windows.
I want to submit a tamper-proof review about a organisation and hence want to create a private block-chain network with no validators and say 5 users, who submit their review via android app through abci-cli to the private blockchain.
Can anyone guide me how to proceed with this. I am new to this whole topic and very confused about where to start.
I got this How to create a Tendermint local network with same ip
but want to run say 5 user accounts from different mobiles and Tendermint on 1 laptop(to create Blockchain). What I want to build is possible?
Any help is appreciated.
First of all, if you want to create a tamper-proof review system, you'll need as many validators as you can have, not just one. You need them because it's straightforward to hack one validator and exploit your system. But if you have many validators, it's not so easy (given they are independent - different data centers, racks, ..). The whole power of blockchains emerges from having a large number of separate machines which can't easily be hacked.
Second, you can have as many users as you want (of course, there is an upper limit on how many txs per second Tendermint can process).
Third, it's better if you use native Android API to send transactions. Tendermint has 3 HTTP endpoints for transactions (https://tendermint.github.io/slate/#broadcasttxsync).

How to make api.ai agent learn something dynamically?

I am currently using api.ai , to create agent to perform specific tasks, but one question i don't have answer to is , can i make it learn something while chatting , mean that i speak my name is 'John Cena' and she should store it and then whenever i ask her again bot should answer me that. i know there is a way to do it by logging into api.ai web and manually add entries , but it will not help, is there any work around programmatically or automatically ? the file i've been using to practice is given in github . and here is working DEMO
You basically need for your bot to "learn" facts. There are many different ways to achieve this, but recently the most common way is to arrange knowledge into Semantic "Triples" and store the knowledge into a Graph repository (like Neo4j, Titan, Spark Graph, etc). In your example, "my name is John Cena" would translate into a Triple like ("anubava","Name","John Cena"). That way, the next time you are logged in as anubhava and ask "What is my name?", it would translate into a Graph search that will return "John Cena". A word of caution, achieving this is not trivial and would require some significant amount of fine tuning. For more info, you can check here and here.
Finally, most complete solutions (that I know of), are Server Side solutions. If you want for the whole knowledge base to reside in your mobile device, you could probably use the resources there as inspiration, and build your own Linked Data repository using an embedded database.
Hope this helps. Good luck.
To store and recall the user's name, you'll need to set up a webhook with some basic data persistence capabilities. Any database or key-value store would work fine.
Here's the breakdown:
Implement webhook fulfillment for the intent that captures the user's name. The webhook should store the name along with a unique, identifying ID that you should supply from your front-end in either the sessionId or as a context parameter in your call to /query.
Implement webhook fulfillment for the intent that reads the user's name. The webhook should look up the name by ID and return a response that tells the user their name.
The high-level docs for writing a fulfillment webhook are here:
https://docs.api.ai/docs/webhook

Can we use parse to create two different kind of users with two different functionality.

We have developed an android app where the user can select few apparels and request for delivery (Cash on Delivery). Till now we were syncing the apparels from our web app. Now we want to transform the android app to an independent entity. Can we use parse to create two different kind of users
where the user can only browse product and order
where the merchant can upload products and their details.
Can we get the approach for doing this. We are using Android Studio for development.
I think I understand your question, and you can do that.
There are some ways to get that. On parse, when you create the user entity (by default), you will get "role" entity, that allow you create roles for your users.
Another way, (I'm currently using this for one project), is set to user entity a property like isAdmin or something like that as a boolean and then, you will check that to show the correct layout.
I hope this help you.

Listening for updates with RESTful APIs

I have a messenger app that makes GET /conversations requests to populate a list of the conversations of the user.
The next step is to make it "listen" for updates so that it marks conversations that have been updated and add conversations that have been created.
Should I use the same /conversations resource to get the updates or should I rather have a separate resource for that? Perhaps, something like /conversationUpdates.
It depends on whether you want to follow RESTful conventions. Many client side libraries such as backbone and extjs have fairly deep support for declaring a resource with a URI and then using the different HTTP methods (GET, POST, DELETE, etc.) against it. This might sometimes lessen the work clients need to do and folks will be grateful.
Following the convention will also make your api less surprising. There are undoubtedly other conventions for API's and not every domain space is well modeled with REST.
Rereading your post, I see you want to have an api that that just gets new posts. What constitutes new? New since the last time the client called the end point? In such instances an api might accept a parameter like the last identifier that had been received (if you are using something like a auto increment field, or a mongodb id). In that case you would just use the /conversations endpoint, with an extra parameter.
Firstly, I'd stick here with the GET method, since this is exactly the point: getting data.
As for the resource name, I'd go with the same, specifying it further in the query, something like /conversations?state=new. My point here is that the resource itself is still the same but you only want a subset of it.
However, if you plan on updating other things than conversations, you can use /updates/conversations since in this case, an update can be considered as a resource, itself composed of, among other things, conversations.

Have data fixed or fetch for it Android

I am interested what approach to choose in situation if you have a client/server application in which you have some categories (just a type name - like coffee shop, restaurant, etc. and an icon for it), that you may want to expand in future.
One way to do it, as I see it know, is to have a string list resource (xml) and appropriate icons on the client side (concretely Android client), and when you want to add new categories, you will have to build new version and deploy it (if I'm not wrong and it all gets to binary for when compiled).
The other way is to have the type list on the server (let's say as a simple entity with type and icon), and that you're client fetches for it whenever is needed, per example, first fetch all the category names, and then the appropriate icon for selected.
So I'm interested in what is better in a situation like this?
This is ultimately called Syncing functionality. It depends on the requirement and situations.
There are actually 3 ways to implement such functionality:
Put all the required things inside the app and deploy onto the play store.
Put static things inside the app(client) and dynamic changed values on the server.
Put everything on server and sync into client as and when required.
Way 1:
In this way, you need to put everything into the app. Advantages of doing it are you would not have to depend on server and it loads faster. Disadvantage of doing is you would have to deploy app as and when data changes, even if you do a change in single value.
Way 2:
In this way, you can keep static things like company logo, company banners and all such values which are usually don't change frequently. And you can store rest of the values which you think changes frequently like employee list/details.
So if there is new data available, client needs to be notified so that it can sync latest data into the local database.
Advantage of Way 2 is you wouldn't have to load static things again.
Way 3:
In this way, everything is supposed to be on server, client has to sync data on first launch and then whenever new data is available.
Advantage of way 3 is you don't need to deploy app if any change in data values. But as this is depend highly on network connectivity/server, developer has to implement all the corner cases to avoid sync/data loss.

Categories

Resources