Osclass forums

Development => Development => Topic started by: programista on March 20, 2017, 06:31:41 pm

Title: [HELP] Any osclass REST API plugin or planned in near future?
Post by: programista on March 20, 2017, 06:31:41 pm
Hi.

My client needs an android app for osclass based site (heavily modified also by me).

But i need API access to make it happen. Had searched the forums but no luck.

And yes, i know that osclass now offers their official app with their own plugin. (rest api?)

Due to the project specifics, we need our own application and our own rest api.

It would be inventing the wheel again and a waste of time if i start the work and then some plugin will show up or an official api, so i need to ask before i start.

Making the app and api will take some time, approx. 1-2 moths, the questions are:

- Do osclass team plan to release the rest api plugin used in their official apps for free or separately in the time frame of 1-6 months?

- If not or the team can't comment on this now, are there any plans to include a free rest api in oclass, or if anything is being worked right now to make it happen in time frame 1-6 month (maybe even not related to the paid plugin in apps)

- Is there any free/paid REST API plugin for oclass available right now or will be in the time frame of 1-6 months, maybe even something incomplete, community project etc.

Best regards and hoping for some help
Andrew
Title: Re: [HELP] Any osclass REST API plugin or planned in near future?
Post by: _CONEJO on March 21, 2017, 11:17:01 am
Do we plan to release an API? "Yes", but that's a lot more complex question and there are a lot of issues to fix before
Do we plan to release an API soon? No


There are a lot of issues that arise with the idea of an API. For example, what happens with plugins? how do you include plugins in the API? You need to rewrite them specially for the API, your app needs to know how to consume the extra fields.
Title: Re: [HELP] Any osclass REST API plugin or planned in near future?
Post by: programista on March 22, 2017, 07:40:34 pm
Well, it could be without plugins support at the beginning to make it easier, but i think there is no point cuz plugins support is very easy to add.

Plugins can be supported in api the same way as any extensions in the code are supported now - by hooks, and it makes sense, one way or another, it is the only way it can be done, the only way to support custom code for plugins is... well.. custom code and you need hooks to do it.

Lets say search api, just any api you can think of, before outputting any json result (maybe using json api standard), just add to any api a hook to add any number of fields to the result, either be it single data response or a list of something, the same way you can add something before even making db queries, like add custom conditions to search.

Nothing new, it is already used everywhere in the current script.

But i guess you are already done all that, cuz you are selling commercial apps, to what, someone with plugins can't buy them? I don;t think so.

But, back to the point, thank you for the complete and precise answer for my questions, this all i needed, guess i will need to do i myself.

Thx again.
Title: Re: [HELP] Any osclass REST API plugin or planned in near future?
Post by: SteveJohnson on March 23, 2017, 06:39:14 pm
I understand this might be a complex question.. as the each theme may implement the core osclass in a different way, and also each plugin does different work.

Maybe there can be a core API, much like the core osclass script. And all plugins can optionally have their specific role in generating their part in the API?
Title: Re: [HELP] Any osclass REST API plugin or planned in near future?
Post by: _CONEJO on March 24, 2017, 10:00:38 am
Again, this is a more complex issue. We didn't find a nice solution that covers every plugin possible, as some of them modify the view/html.

Let's say we create an API for the core with "hooks" and it works fine, now, we want to use some plugin, like the most simple plugin, one which add some attributes to the listing, let's say it's a cars attributes one which let's you select make and model, pretty simple.. How do we know we need to show more form elements/fields for said plugin? Ok, don't panic, when we ask the API, it should reply with a JSON, with the form's fields, so we get our regular fields + our plugin fields.

But what happens if we want that when you select a make, then the dropdown menu for models only shows models of that make? In a normal website, we add some javascript, an ajax request and done, but... how our app knows it has to do an ajax request? how does it runs "javascript"? is that js added to the form fields? how?

Another example, social plugins that let you login into your website with a facebook , google or twitter account. How can you make them work with you app?

Other plugins, like payments plugins for example, adds new "pages" to your website, like a checkout page. How does your app know how to show that checkout page? And being specific of said plugins, how could you make a payment from your app?

Finally, there are other plugins, like sliders, cookie consent, age warning, anything related to banners/ad management,... that you will not be able to use on your app.


In short, we didn't find a nice solution for any plugin that uses javascript and some HTML "a bit different", if you have one, please, let us know.

Title: Re: [HELP] Any osclass REST API plugin or planned in near future?
Post by: programista on March 26, 2017, 07:34:31 pm
OK, but your examples are totally wrong and useless. You are looking at this in the wrong direction.

If someone uses a plugin then this plugin must support the api, not the way around, that osclass must support any plugin automatically with rest api, this is impossible, cuz plugins are made by 3rd party. And if someone creates a plugin then the support for api, must be in that plugin, coded by the creator of the plugin.

And the same thing goes for mobile app, if someone want to use a plugin in api, he need to code that support, first in plugin, second in app.

The rest api should be never concerned with javascript/view/html, anything that is not data and is web technology, if some plugin modifies view html or inject js, it has nothing to do with the api as the rest api will never return js/view/html , only data that needs to be supported in apps.

You are looking for a nice solution for a problem that doesn't exists.

In your examples, cars attributes, the site owner knows that he will use that plugin, so he knows that he need to have additional fields in his mobile app, this needs to be integrated together.

And the app don't need to get fields from api, it already knows what to send, cars plugin needs to be extended to support the api search of oclass code.

So in the api search in oclass, there will be hooks like: "api_before_search", "api_after_search", the first allows to add conditions, the second to add fields to results. The plugin just needs to support them both, then the app can send additional fields and thus receive also additional fields, per item.

You can even not change a thing, cuz if you activate the cars attrubutes and the code for api and normal search will be shared then thats it, if you request it from app, with the right fields, it will just work.

The app can make any request someone desire, so as for visual filtering, dropdowns etc. , this is also the plugin creator responsibility to add also an api route to get make and model for the app that needs it.

Social plugins, the same thing, api hooks need to be added to osclass login/register etc. code, the app owner need to add his OWN UI and code to support that in the app, the social plugin will need to support the api hooks that osclass adds.

Payments plugins, the same thing, if it adds a page then app owner needs to support in his app, but also the plugin need to support new api hooks to return all data that are need in app to make it happen.

The app will know what to show cuz it needs to be coded, there are no magic here, everything will not make itself and work automatically.

So yes, a lot of plugins will not be compatible with api at start, but in time they will be updated.

Osclass just need to make the right api hooks in the right places, to allow send any fields to the core functions that are needed and to receive the results.

Hook are great, cuz you don't need to use them if you don't want to, if a plugin changes the view/html/js, nothing of this will return to mobile app.

That is the whole point of api, send data, receive data, and of course that means many plugin will be at start incompatible, it is perfectly normal.

Just look at wordpress rest api, i mean they didn't check all existing plugins compatibility right? Yeah, it is just a separate entity, you can use it, but you don't need to.
Title: Re: [HELP] Any osclass REST API plugin or planned in near future?
Post by: _CONEJO on March 27, 2017, 10:41:14 am
I could see some problems with your approach:

- If you install a new plugin, you may need to release a new version of your app
- If you disable a plugin, you may need to release a new version of your app
- If you change the configuration, you may need to release a new version of your app
- If you upgrade your plugins, you may need to release a new version of your app

And with few plugins this might not be a problem, but with more than a few it could be a problem.
And you have another issue, that is to make your users upgrade your mobile app at every change, because if they don't, the app may be broken and not usable at all. For example, you install a new plugin that add some required fields to your listings, old version users will not be able to use your app correctly.


But anyway, hooks are already there, that's how the plugins work nowadays, in search for example we already have: before_search, search_conditions, search & after_search, not sure what more hooks you need. Our main problem is how to output the data to make it useful. But if you want a simple api, you could make it in very few lines, just hook to before_html and output the View's variables as json.

And as a remember, Osclass is a free and open source project, anyone could collaborate and send a pull-request with their idea / changes/ fix, your help is welcome.