I want to add REST endpoints to Seltzer

25 views
Skip to first unread message

Joshua Pritt

unread,
Feb 13, 2015, 5:39:26 PM2/13/15
to seltzer...@googlegroups.com
By adding REST endpoints it would be easy for a 3rd party app request info from the database!
Should this just be a new module?  I'm thinking yes.  I've already got the fork in my melbourne makerspace git repo.

Edward L Platt

unread,
Feb 15, 2015, 7:37:51 PM2/15/15
to seltzer...@googlegroups.com
Yes! I've been thinking about this a lot lately. I think REST endpoints will be an important part of Seltzer moving forward, and may be a way to enable interoperability with other apps.

I really like the REST+JSON style shown here:
https://www.youtube.com/watch?v=mZ8_QgJ5mbs

I've been playing around with possible formats here:
https://github.com/elplatt/taxonomy/blob/master/tests/data/association.json

Rather than having many different endpoints for members, payments, rfid keys, etc., I'm leaning towards having an "entity" endpoint that encapsulates all of those, and a "taxonomy" endpoint that's used to tag and classify those entities. This would make interoperability with other systems a lot easier.

This is basically an RDF-style linked data scheme, and there's now a json specification for doing this that we may want to follow:
http://json-ld.org/

-Ed

On Fri, Feb 13, 2015 at 5:39 PM, Joshua Pritt <ramg...@gmail.com> wrote:
By adding REST endpoints it would be easy for a 3rd party app request info from the database!
Should this just be a new module?  I'm thinking yes.  I've already got the fork in my melbourne makerspace git repo.

--
You received this message because you are subscribed to the Google Groups "seltzercrm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seltzercrm-de...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Edward L. Platt

This electronic mail message was sent from my desktop personal computer.  Please forgive any long-winded, overly-prosaic ramblings.

Joshua Pritt

unread,
Feb 16, 2015, 1:53:48 PM2/16/15
to seltzer...@googlegroups.com
The first REST query I want to make is "give me the list of CURRENT MEMBERS" that have paid up for the month (members that have NOT lapsed).
I'm sure this will be the #1 most used query from other applications such as door locks etc.

Design idea:

REST URL:

returns JSON since format parameter "f" was set to JSON.  Could be HTML or XML.
queries the DB using the following:
payment_accounts(["cid" => 1]) 
Then check if the amount returned is <= 0.
Return a list of all the current members:

{ "currentmembers": [ { "member": { "name": "Josh Pritt", "email": "ramg...@gmail.com", }, "member": { "name": "John Doe", "email": "jd...@gmail.com", } } ] }

Edward L Platt

unread,
Feb 16, 2015, 3:57:58 PM2/16/15
to seltzer...@googlegroups.com
Here's a modification that's more REST/JSON-LD style, using mongo's query syntax:

REST URL:
https://yourserver.com/crm/api/entity?filter={"type":"contact","memberships":{"$elemMatch": {"$nin": "endDate"}}}

[
{
"@type": "contact",
"name": "Josh Pritt",
"email": "ramg...@gmail.com",
"memberships": [
{ "startDate": "2015-01-01" }
]
},
{
"@type": "contact",
"name": "John Doe",
"email": "jd...@gmail.com"
"memberships": [
{ "startDate": "2015-02-01" }
]
}
]

Edward L Platt

unread,
Feb 16, 2015, 4:21:32 PM2/16/15
to seltzer...@googlegroups.com
Actually, even better, check out the format in the README at https://github.com/hackers4peace/plp-docs

Loomio and related apps are working towards this as a standard.

Joshua Pritt

unread,
Feb 16, 2015, 4:26:10 PM2/16/15
to seltzer...@googlegroups.com
oh yeah much better!
So I should just go ahead and fork that template module and create the API module in my fork of Seltzer?
Any more design review required for this?  It's a pretty simple thing but it can made as complicated as we want it.
Perhaps some Pseudocode?

for the "get all current paid up members" query:

loop through all contacts
  get the account amount for each contact
  if amount <= 0 then add contact to returnList

for each contact in returnList
  deserialize contact into JSON string, add to returnJSON string

return returnJSON string 



On Mon, Feb 16, 2015 at 3:57 PM, Edward L Platt <e...@elplatt.com> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "seltzercrm-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/seltzercrm-dev/gKPPJmrRAaI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to seltzercrm-de...@googlegroups.com.

Edward L Platt

unread,
Feb 16, 2015, 4:30:25 PM2/16/15
to seltzer...@googlegroups.com
You could either fork seltzer, or create a new repo for just the module. The REST module will likely end up in core, but I've been trying to create new modules as their own repos.

--
You received this message because you are subscribed to the Google Groups "seltzercrm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seltzercrm-de...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Joshua Pritt

unread,
Feb 16, 2015, 4:35:27 PM2/16/15
to seltzer...@googlegroups.com
I was thinking REST would be a module.  Would it still be able to call core functions like payment_accounts(["cid" => 1])  if it was just a module?
Otherwise it would need to be part of core so we don't have to reinvent the wheel for those similar queries.
Or, since the REST queries could be anything then it would sometimes need to have its own query into the DB so it would need to created new anyway so it wouldn't matter if it was core or a module?

James Nylen

unread,
Mar 21, 2015, 4:35:27 PM3/21/15
to seltzer...@googlegroups.com
I participated in the Seltzer call/demo this week on behalf of Red Mountain Makers in Birmingham, AL where I'm the treasurer.  I'm very interested in REST or other API features for Seltzer, but coming from the other side:  I need our financial system to be able to tell Seltzer that we've received a payment, and have it update the state accordingly.  I don't think adding a PayPal integration is the right approach here:  it needs to be generic in case we change payment processors in the future.

I'd like to write some code for this.  I found the module documentation on the GitHub wiki and will look at the Amazon payments module.  Beyond that, any hints like an outline of the general approach to take, or places to hook into the payments code, would be helpful.  I'm more familiar with straight JSON than JSON-LD but it doesn't look too bad from the samples above.

Edward L Platt

unread,
Mar 22, 2015, 7:59:22 PM3/22/15
to seltzer...@googlegroups.com
This is a bit tricky because Seltzer wasn't built with REST in mind. Here's what I'd recommend.

REST is a big part of my plans for the code sprint this summer, and it's going to be a lot of work to integrate it with seltzer. So if you need something sooner, it's probably best to create a separate server that provides the rest endpoints and interfaces with the seltzer database.

Would that work?

-Ed

Joshua Pritt

unread,
Mar 22, 2015, 9:29:20 PM3/22/15
to seltzer...@googlegroups.com
The way I added the REST URL for our needs was to just create my own PHP script from scratch that just directly connects to the Seltzer database and does its own SQL queries.

I'll clean out our IP, user, password, etc. from our code and post it on our GitHub so anyone can change or improve it for their needs too.

I can help you with your code sprint, Ed, to get the REST stuff put into the core code if you want.

I'll post on this thread again once I have it up.


On Friday, February 13, 2015 at 5:39:26 PM UTC-5, Joshua Pritt wrote:

Joshua Pritt

unread,
Mar 22, 2015, 10:40:46 PM3/22/15
to seltzer...@googlegroups.com
OK I uploaded my crude REST API hack into my fork of the Seltzer repo on our Melbourne Makerspace github.
Take a look and feel free to make fun of my code or help make it better.
It works for our RFID door lock so that's pretty cool that I was able to get all this hacked together in just two or three weeks.
Let me know if you have any questions about it all.



On Friday, February 13, 2015 at 5:39:26 PM UTC-5, Joshua Pritt wrote:

Edward L Platt

unread,
Mar 23, 2015, 10:47:55 AM3/23/15
to seltzer...@googlegroups.com
Thanks Josh!

--
You received this message because you are subscribed to the Google Groups "seltzercrm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seltzercrm-de...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joshua Pritt

unread,
Mar 23, 2015, 10:51:26 AM3/23/15
to seltzer...@googlegroups.com
Don't thank me yet.  Not until you take a look at the code and check my work to see if there's a better way first.
This was just a quick hack to make our RFID door lock work and was my first attempt.
My main idea was a way to expose an SQL query via HTTP for Internet of Things devices to query the Seltzer DB.
There very well might be a better way to do this.

--
You received this message because you are subscribed to a topic in the Google Groups "seltzercrm-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/seltzercrm-dev/gKPPJmrRAaI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to seltzercrm-de...@googlegroups.com.

Joshua Pritt

unread,
Mar 23, 2015, 10:52:52 AM3/23/15
to seltzer...@googlegroups.com
Oh yeah!  I forgot to link in the wiki page for our RFID Door lock project so you can see how it all comes together:



Chris Murray

unread,
Mar 24, 2015, 8:27:25 AM3/24/15
to seltzer...@googlegroups.com
Looks good to me!

I wonder though, since the config.inc.php would have the db connection details, in your dbconnect.php should you just use an include statement and/or reference the existing global variables?



All the best,

Chris 8-)

Joshua Pritt

unread,
Mar 24, 2015, 9:03:52 AM3/24/15
to seltzer...@googlegroups.com
That would probably be even better!  I can update the code to point to the config.inc.php and try it out later today or tomorrow.  Keep the good ideas coming everyone!

Edward L Platt

unread,
Mar 24, 2015, 11:32:05 AM3/24/15
to seltzer...@googlegroups.com
A good example of how to do this is the ipn script in the amazon payment module.

Joshua Pritt

unread,
Mar 27, 2015, 11:19:42 PM3/27/15
to seltzer...@googlegroups.com, e...@elplatt.com
OK I just did a commit on the REST stuff.  I changed it to use the crm.inc.php so it would also bring in those nice other function like
$accountData = payment_accounts(array("cid" => $memberID));
which returns an array of arrays like this:
{"2":{"credit":"2","code":"USD","value":5000}}
Which shows member ID 2 has a balance of $50.
This made it easy to change my doorLockCheck() function from checking if the key owner has made any payment in the last 45 days to something that makes more sense of checking if the key owner has a balance less than two times their monthly plan dues.
Take a look and see!
Reply all
Reply to author
Forward
0 new messages