Skip to content

Instantly share code, notes, and snippets.

@neilellis
Created October 20, 2014 14:26
Show Gist options
  • Save neilellis/d30512d27d2e133a13d2 to your computer and use it in GitHub Desktop.
Save neilellis/d30512d27d2e133a13d2 to your computer and use it in GitHub Desktop.
$GET("/v2/webshot/:key", (http) ->
$($("params", http.params()), $("query", http.queryParams()))
.$pipe(new ParamValidator())
.$pipe(new KeyValidator())
.$void(() -> $().$error(
"Sorry your key is not recognized, maybe you need to check http://app.snapito.io/#/account",
var.ErrorType.VALIDATION))
.$pipe((v) -> {
if (v.$match("userStatus", "over_free")) {
http.status(302);
http.redirect(
"https://s3.amazonaws.com/snapito-images/error_images/free_plan_out_of_credit.png",
302);
return $();
} else {
return v;
}
})
.$pipe($jsResource("/build_request.js"))
.$pipe(cacheCheck)
.$post(P2I_ADDRESS)
.$pipe((v) -> {
return v;
}));
@neilellis
Copy link
Author

In this example you can see a typical pipe flow:

create-> pipe -> pipe-> (empty check) -> pipe-> JS pipe -> pipe -> post to API, take response -> pipe

@neilellis
Copy link
Author

And a typical state log from the above (the above example is not fully working code yet hence the errors in the state log):

[api]:CREATE[java.lang.String]: -> 192.168.0.26
[api]:PUBLISH[snapito.api.welcome]: 192.168.0.26 -> 192.168.0.26
[api]:SET[server, 192.168.0.26]: {} -> {"server":"192.168.0.26"}
[api]:SET[timestamp, 1413815500178]: {"server":"192.168.0.26"} -> {"server":"192.168.0.26","timestamp":1413815500178}
[api]:SAVE[]: {"server":"192.168.0.26","timestamp":1413815500178} -> {"server":"192.168.0.26","timestamp":1413815500178}
[api, get:/v2/webshot/:key]:SET[params, {":key":"123"}]: {} -> {"params":{":key":"123"}}
[api, get:/v2/webshot/:key]:SET[query, {"url":"google.com"}]: {} -> {"query":{"url":"google.com"}}
[api, get:/v2/webshot/:key]:Validating {"params":{":key":"123"},"query":{"url":"google.com"}}
[api, get:/v2/webshot/:key]:EVAL[anon, io.snapito.pipeline.ParamValidator]: {"params":{":key":"123"},"query":{"url":"google.com"}} -> {"params":{":key":"123"},"query":{"url":"google.com"}}
[api, get:/v2/webshot/:key]:LOAD[in_cdn:]: -> in_progress
[api, get:/v2/webshot/:key]:EVAL[anon, io.snapito.pipeline.CacheCheck]: {"p2i_key":null,"p2i_url":"http://google.com","p2i_wait":0,"p2i_size":"1024x0","p2i_fullpage":1,"p2i_imageformat":"png","p2i_screen":"1280x800","p2i_refresh":0,"p2i_device":null,"cache":2592000.0} -> {"p2i_key":null,"p2i_url":"http://google.com","p2i_wait":0,"p2i_size":"1024x0","p2i_fullpage":1,"p2i_imageformat":"png","p2i_screen":"1280x800","p2i_refresh":0,"p2i_device":null,"cache":2592000.0}*ERROR*
[api, get:/v2/webshot/:key]:EVAL[http://api.page2images.com/restfullink]: {"p2i_key":null,"p2i_url":"http://google.com","p2i_wait":0,"p2i_size":"1024x0","p2i_fullpage":1,"p2i_imageformat":"png","p2i_screen":"1280x800","p2i_refresh":0,"p2i_device":null,"cache":2592000.0}*ERROR* -> {"status":"error","msg":"You must pass a API key to us.","errno":403,"ori_url":"http://google.com"}*ERROR*
[api, get:/v2/webshot/:key]:EVAL[anon, io.snapito.NewAPI$$Lambda$19/659217]: {"status":"error","msg":"You must pass a API key to us.","errno":403,"ori_url":"http://google.com"}*ERROR* -> {"status":"error","msg":"You must pass a API key to us.","errno":403,"ori_url":"http://google.com"}*ERROR*
[api, get:/v2/webshot/:key]:HTTP_RESPONSE[get, /v2/webshot/:key]: -> {"status":"error","msg":"You must pass a API key to us.","errno":403,"ori_url":"http://google.com"}*ERROR*
[]:CREATE[java.lang.Integer]: -> 500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment