Read through mongoDB cache of JSON web services for later processing
Regulache is a Groovy Maven project.
Maven dependency snippet
<dependency>
<groupId>com.github.concept-not-found</groupId>
<artifactId>regulache</artifactId>
<version>1-SNAPSHOT</version>
</dependency>
Groovy Grape snippet
@Grab(group="com.github.concept-not-found", module="regulache", version="1-SNAPSHOT")
Regulache is based off of Groovy's RESTClient
def regulache = new Regulache("http://base-url.com/context/", monogoDBCollection)
def (json, cached) = regulache.executeGet(
path: "web/service/path/with/{namedParameters}",
"path-parameters": [
namedParameters: "substitutePathParameters"
],
"transient-queries": [
api_key: "do_not_persist"
]
)
// this will make the request: GET http://base-url.com/context/web/service/path/with/substitutePathParameters?api_key=do_not_persist
Subsequent calls will always return the cached value unless ignore-cache
or ignore-cache-if-older-than
parameters are used.
On a successful GET request, the request is available in the provided mongoDB collection.
mongodb> db.monogoDBCollection.findOne({base: "http://base-url.com/context/"})
{
"_id" : ObjectId("1234567890"),
"headers" : {},
"base" : "http://base-url.com/context/",
"path" : "web/service/path/with/{namedParameters}",
"path-parameters" : {
"namedParameters" : "substitutePathParameters"
},
"queries" : {},
"last-retrieved" : NumberLong("1387073116885"),
"data" : {
"the-original" : "json-body"
}
}
Full working example using League of Legends API: example.groovy
For more details, read the source.
Copyright 2013 Ronald Chen Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.