public
Created

automate api action invoke

  • Download Gist
auto-api.json
JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
"
name, com.patch.kickass.actions.EmailPreferenceActions$SetOptOut
parameters: UserRef
param values: 1
"
 
"
output:
action name, param types, return type, case class, implementation(needed to invoke the action)
"
 
"inspect:"
{
"actions":[
{
"action_name": "com.patch.kickass.actions.EmailPreferenceActions$SetOptOut",
"parameters" : [
{ "type": "com.patch.kickass.models.UserRef" }
],
"return_type" : "Unit"
},
{
"action_name": "com.patch.kickass.actions.EmailPreferenceActions$SetSubscribedVars",
"parameters": [
{ "type": "com.patch.kickass.models.UserRef" },
{ "type": "scala.collection.immutable.Map[String, AnyRef]" }
],
"return_type": "?"
},
{
"action_name": "com.patch.kickass.actions.EmailPreferenceActions$SetSubscribedTemplates",
"parameters": [
{ "type": "com.patch.kickass.models.UserRef" },
{ "type": "scala.collection.immutable.Set[Template]" }
],
"return_type": "?"
}
]
}
 
"invoke:"
{
"input": {
"action_name": "com.patch.kickass.actions.EmailPreferenceActions$SetOptOut",
"parameters": [
{
"position": 1,
"type": "com.patch.kickass.models.UserRefs.ById",
"value": 123
}
]
},
"output":
"json of the return data structure"
}
 
to expose store actions
/*
object ApiEmailPreferenceActions {
val SetOptOut = EmailPreferenceActions.SetOptOut
val GetSailthruEmail = EmailPreferenceActions.GetSailthruEmail
...
// leave out the other members
}
*/
 
type Json = Map[String, Any]
// get the object with the given class name
// getSingletonInstance("com.patch.kickass.actions.EmailPreferenceActions")
def getSingletonInstance(cls:String):Object
 
// getMethod("com.patch.kickass.actions.EmailPreferenceActions", "GetSailthruEmail")
def getMethod(cls:String, methodName:String):Method
 
// get a serializer that is capable for the return type of this method
def getSerializer(m:Method): (?=>Json) // controls serialization
def getDeserializer(m:Method, paramPosition:Int): (Json=>Object) // controls serialization
OR
def getSerializer(cls:Class): (?=>Json) // controls serialization
def getDeserializer(cls:Class): (Json=>Object) // controls serialization
 
// invoke the method with params, get the data back
// val inst = getSingletonInstance("com.patch.kickass.actions.EmailPreferenceActions")
// val m = getMethod("com.patch.kickass.actions.EmailPreferenceActions", "GetSailthruEmail")
// val ser = getSerializer(m)
// val json = call(inst, m, ser)
def call(driver:Driver, instance:Object, method:Method, params:Json, serializer: Any=>Json):Json
 
format/layout of the returned data is controlled manually.
 
POST:http://api-server-host/genetic-end-point?input={json payload here}
 
 
code snippet
val singleton = Class.forName("com.patch.kickass.actions.ApiEmailPreferenceActions$").getDeclaredFields()(0).get(null)
Class.forName("com.patch.kickass.actions.ApiEmailPreferenceActions$").getDeclaredMethods()(0).invoke(singleton)
Class.forName("com.patch.kickass.actions.EmailPreferenceActions").getClasses()(0).getMethods.filter{m=>m.getName=="implementation"}(0).getParameterTypes

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.