Skip to content

Commit

Permalink
Merge pull request #6 from Aqua-Ye/master
Browse files Browse the repository at this point in the history
Fixed compilation and run with Opa 1.0.5
  • Loading branch information
hbbio committed Jan 31, 2013
2 parents 1f87ee5 + c544aa2 commit 99b67c7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Makefile
@@ -1,4 +1,4 @@
NAME = webshell.exe NAME = webshell.js


SRC = service.opa editor.opa config.opa login.opa webshell.opa \ SRC = service.opa editor.opa config.opa login.opa webshell.opa \
calc.opa facebook.opa search.opa dropbox.opa twitter.opa calc.opa facebook.opa search.opa dropbox.opa twitter.opa
Expand All @@ -7,7 +7,7 @@ SRCS = $(SRC:%=src/%)
all: $(NAME) all: $(NAME)


$(NAME): $(SRCS) $(NAME): $(SRCS)
opa --parser js-like $(SRCS) -o $(NAME) opa $(SRCS) -o $(NAME)


run: $(NAME) run: $(NAME)
./$(NAME) ./$(NAME)
Expand Down
12 changes: 6 additions & 6 deletions src/config.opa
Expand Up @@ -8,8 +8,8 @@ module Config {


// TODO: abstract away this pattern // TODO: abstract away this pattern
server host = server host =
_ = CommandLine.filter( state = CommandLine.filter(
{ init: void { init: none
, parsers: [{ CommandLine.default_parser with , parsers: [{ CommandLine.default_parser with
names: ["--host"], names: ["--host"],
param_doc: "HOST", param_doc: "HOST",
Expand All @@ -18,8 +18,8 @@ module Config {
parser { parser {
case host=(.*) : case host=(.*) :
{ {
/host <- Text.to_string(host) // /host <- Text.to_string(host)
{no_params: state} {no_params: some(Text.to_string(host))}
} }
} }
} }
Expand All @@ -28,8 +28,8 @@ module Config {
, title: "General options" , title: "General options"
} }
) )
match (?/host) { match (state) {
case {some: host}: host case {some: s}: s
default: default:
Log.error("webshell[config]", "Cannot read host configuration Log.error("webshell[config]", "Cannot read host configuration
Please re-run your application with: --host option") Please re-run your application with: --host option")
Expand Down
13 changes: 7 additions & 6 deletions src/dropbox.opa
Expand Up @@ -16,8 +16,8 @@ type Dropbox.status = {no_credentials}
module DropboxConnect { module DropboxConnect {


private server config = private server config =
_ = CommandLine.filter( state = CommandLine.filter(
{ init: void { init: none
, parsers: [{ CommandLine.default_parser with , parsers: [{ CommandLine.default_parser with
names: ["--dropbox-config"], names: ["--dropbox-config"],
param_doc: "APP_KEY,APP_SECRET", param_doc: "APP_KEY,APP_SECRET",
Expand All @@ -26,8 +26,9 @@ module DropboxConnect {
parser { parser {
case app_key=Rule.alphanum_string [,] app_secret=Rule.alphanum_string : case app_key=Rule.alphanum_string [,] app_secret=Rule.alphanum_string :
{ {
/dropbox_config <- ~{app_key, app_secret} db_config = ~{app_key, app_secret}
{no_params: state} // /dropbox_config <- db_config
{no_params: some(db_config)}
} }
} }
} }
Expand All @@ -36,7 +37,7 @@ module DropboxConnect {
, title: "Dropbox configuration" , title: "Dropbox configuration"
} }
) )
match (?/dropbox_config) { match (state) {
case {some: config}: config case {some: config}: config
default: default:
Log.error("webshell[config]", "Cannot read Dropbox configuration (application key and/or secret key) Log.error("webshell[config]", "Cannot read Dropbox configuration (application key and/or secret key)
Expand Down Expand Up @@ -135,7 +136,7 @@ Please re-run your application with: --dropbox-config option")
match (segs) { match (segs) {
case []: [] case []: []
case ["." | xs]: aux(xs) case ["." | xs]: aux(xs)
case [x, ".." | xs]: aux(xs) case [_x, ".." | xs]: aux(xs)
case [x | xs]: [x | aux(xs)] case [x | xs]: [x | aux(xs)]
} }
} }
Expand Down
13 changes: 7 additions & 6 deletions src/facebook.opa
Expand Up @@ -20,8 +20,8 @@ module FacebookConnect
{ {


server config = server config =
_ = CommandLine.filter( state = CommandLine.filter(
{ init: void { init: none
, parsers: [{ CommandLine.default_parser with , parsers: [{ CommandLine.default_parser with
names: ["--fb-config"], names: ["--fb-config"],
param_doc: "APP_ID,APP_SECRET", param_doc: "APP_ID,APP_SECRET",
Expand All @@ -30,8 +30,9 @@ module FacebookConnect
parser { parser {
case app_id=Rule.alphanum_string [,] app_secret=Rule.alphanum_string: case app_id=Rule.alphanum_string [,] app_secret=Rule.alphanum_string:
{ {
/facebook_config <- {~app_id, api_key: app_id, ~app_secret}; fb_config = {~app_id, api_key: app_id, ~app_secret};
{no_params: state} // /facebook_config <- fb_config
{no_params: some(fb_config)}
} }
} }
} }
Expand All @@ -40,7 +41,7 @@ module FacebookConnect
, title: "Facebook configuration" , title: "Facebook configuration"
} }
) )
match (?/facebook_config) { match (state) {
case {some: config}: config case {some: config}: config
default: default:
Log.error("webshell[config]", "Cannot read Facebook configuration (application id and/or secret key) Log.error("webshell[config]", "Cannot read Facebook configuration (application id and/or secret key)
Expand Down Expand Up @@ -104,7 +105,7 @@ Please re-run your application with: --fb-config option")
outcome = FbGraph.Post.feed(feed, creds.token) outcome = FbGraph.Post.feed(feed, creds.token)
response = response =
match (outcome) { match (outcome) {
case {~success}: <>Successfully published Facebook feed item: «{feed.message}»</> case {success:_}: <>Successfully published Facebook feed item: «{feed.message}»</>
case {~error}: <>Error: <b>{error.error}</b>; {error.error_description}</> case {~error}: <>Error: <b>{error.error}</b>; {error.error_description}</>
} }
Service.respond_with(response) Service.respond_with(response)
Expand Down
20 changes: 9 additions & 11 deletions src/search.opa
@@ -1,7 +1,5 @@

import stdlib.web.client import stdlib.web.client
import stdlib.core.xhtml import stdlib.core.xhtml
import stdlib.core.xmlm


type item = { option(string) title, option(string) link, option(string) guid, option(string) description, option(string) pubDate } type item = { option(string) title, option(string) link, option(string) guid, option(string) description, option(string) pubDate }


Expand Down Expand Up @@ -47,8 +45,8 @@ module SearchParser {
module Search { module Search {


auth = auth =
_ = CommandLine.filter( state = CommandLine.filter(
{ init: void { init: none
, parsers: [{ CommandLine.default_parser with , parsers: [{ CommandLine.default_parser with
names: ["--blekko-config"], names: ["--blekko-config"],
param_doc: "AUTH_KEY", param_doc: "AUTH_KEY",
Expand All @@ -57,8 +55,8 @@ module Search {
parser { parser {
case auth_key=Rule.alphanum_string : case auth_key=Rule.alphanum_string :
{ {
/blekko_auth_key <- auth_key // /blekko_auth_key <- auth_key
{no_params: state} {no_params: some(auth_key)}
} }
} }
} }
Expand All @@ -67,7 +65,7 @@ module Search {
, title: "Blekko configuration" , title: "Blekko configuration"
} }
) )
match (?/blekko_auth_key) { match (state) {
case {some: key}: key case {some: key}: key
default: default:
Log.error("webshell[config]", "Cannot read Blekko configuration (auth_key) Log.error("webshell[config]", "Cannot read Blekko configuration (auth_key)
Expand Down Expand Up @@ -111,7 +109,7 @@ Please re-run your application with: --blekko-config option")
(xhtml) match (WebClient.Get.try_get(uri)) { (xhtml) match (WebClient.Get.try_get(uri)) {
case {failure:f}: <>"{f}"</>; case {failure:f}: <>"{f}"</>;
case {success:result}: case {success:result}:
match (Xmlm.try_parse(result.content)) { match (Xmlns.try_parse(result.content)) {
case {some:xmlm}: case {some:xmlm}:
match (dig(xmlm)) { match (dig(xmlm)) {
case {success:(title,items)}: format_items(title,items); case {success:(title,items)}: format_items(title,items);
Expand Down Expand Up @@ -167,7 +165,7 @@ Please re-run your application with: --blekko-config option")


function get_text(option(xml('a,'b)) xml_) { function get_text(option(xml('a,'b)) xml_) {
match (xml_) { match (xml_) {
case {some:{args:_, content:[{~text}], namespace:_, specific_attributes:_, tag:_}}: {some:text}; case {some:{args:_, content:[{~text}], ...}}: {some:text};
default: none; default: none;
} }
} }
Expand All @@ -190,7 +188,7 @@ Please re-run your application with: --blekko-config option")
case {~content_unsafe}: {failure:content_unsafe}; case {~content_unsafe}: {failure:content_unsafe};
case {fragment:_}: {failure:"fragment"}; case {fragment:_}: {failure:"fragment"};
case {xml_dialect:_}: {failure:"xml_dialect"}; case {xml_dialect:_}: {failure:"xml_dialect"};
case {args:_, ~content, namespace:_, specific_attributes:_, tag:"rss"}: case {~content, tag:"rss", ...}:
match (get_content(single_tag("channel",content))) { match (get_content(single_tag("channel",content))) {
case {some:content}: case {some:content}:
title = get_text(single_tag("title",content)); title = get_text(single_tag("title",content));
Expand Down Expand Up @@ -222,7 +220,7 @@ Please re-run your application with: --blekko-config option")
function get_item(xml('a,'b) xml_) { function get_item(xml('a,'b) xml_) {
//jlog("xml_:{xml_}"); //jlog("xml_:{xml_}");
match (xml_) { match (xml_) {
case {args:_,~content, namespace:_, specific_attributes:_, tag:"item"}: case {~content, tag:"item", ...}:
title = get_text(single_tag("title",content)) title = get_text(single_tag("title",content))
link = get_text(single_tag("link",content)) link = get_text(single_tag("link",content))
guid = get_text(single_tag("guid",content)) guid = get_text(single_tag("guid",content))
Expand Down
19 changes: 10 additions & 9 deletions src/twitter.opa
Expand Up @@ -13,9 +13,9 @@ type Twitter.status = {no_credentials}
module TwitterConnect module TwitterConnect
{ {


server config = config =
_ = CommandLine.filter( state = CommandLine.filter(
{ init: void { init: none
, parsers: [{ CommandLine.default_parser with , parsers: [{ CommandLine.default_parser with
names: ["--twitter-config"], names: ["--twitter-config"],
param_doc: "APP_KEY,APP_SECRET", param_doc: "APP_KEY,APP_SECRET",
Expand All @@ -24,10 +24,11 @@ module TwitterConnect
parser { parser {
case app_key=Rule.alphanum_string [,] app_secret=Rule.alphanum_string: case app_key=Rule.alphanum_string [,] app_secret=Rule.alphanum_string:
{ {
/twitter_config <- { consumer_key: app_key, tw_config = { consumer_key: app_key,
consumer_secret: app_secret consumer_secret: app_secret
} }
{no_params: state} // /twitter_config <- tw_config
{no_params: some(tw_config)}
} }
} }
} }
Expand All @@ -36,7 +37,7 @@ module TwitterConnect
, title: "Twitter configuration" , title: "Twitter configuration"
} }
) )
match (?/twitter_config) { match (state) {
case {some: config}: config case {some: config}: config
default: default:
Log.error("webshell[config]", "Cannot read Twitter configuration (application key and/or secret key) Log.error("webshell[config]", "Cannot read Twitter configuration (application key and/or secret key)
Expand Down Expand Up @@ -80,7 +81,7 @@ Please re-run your application with: --twitter-config option")


private function authenticate() { private function authenticate() {
match (TWA.get_request_token(redirect)) { match (TWA.get_request_token(redirect)) {
case {~error}: case {error:_}:
Service.respond_with(<>Twitter authorization failed</>) Service.respond_with(<>Twitter authorization failed</>)
case {success: token}: case {success: token}:
auth_url = TWA.build_authorize_url(token.token) auth_url = TWA.build_authorize_url(token.token)
Expand Down
2 changes: 1 addition & 1 deletion src/webshell.opa
Expand Up @@ -113,7 +113,7 @@ function page(cmd) {
} }


function connect(connector, raw_data) { function connect(connector, raw_data) {
connector(Text.to_string(raw_data)) _ = connector(Text.to_string(raw_data))
Resource.default_redirection_page("/") Resource.default_redirection_page("/")
} }


Expand Down

0 comments on commit 99b67c7

Please sign in to comment.