curl for MOO?

1 view
Skip to first unread message

J. Kira Hamilton

unread,
Jan 24, 2015, 11:46:14 AM1/24/15
to MOO-...@googlegroups.com
Is there a curl implementation for MOO? Either in-moo or as an add-on function? 

I need to replace our old $network:sendmail code and found a solution that uses curl from the shell. wondering if I can make it work in-moo.

Thanks!

-- Kira

Tim van Dijen

unread,
Jan 24, 2015, 12:16:51 PM1/24/15
to MOO-...@googlegroups.com
J. Kira Hamilton schreef op 24-1-2015 om 17:46:
--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to MOO-talk+u...@googlegroups.com.
To post to this group, send email to MOO-...@googlegroups.com.
Visit this group at http://groups.google.com/group/MOO-talk.
For more options, visit https://groups.google.com/d/optout.

You could use the exec() add-on from Stunt to run curl from the shell.
There is no curl implementation for MOO that I'm aware of, so this would be your easiest approach

- Tim

Michael Munson

unread,
Jan 24, 2015, 5:50:13 PM1/24/15
to Tim van Dijen, MOO-...@googlegroups.com
This is the implementation I use for curl:
 
$curl:"request" this none this
 1:  {options} = args;
 2:  o = options:merge(["method" -> "GET", "url" -> ""]);
 3:  o = (["method" -> "GET", "url" -> "", "data" -> [], "format" -> ""]):merge(options);
 4:  if (o["method"] == "GET")
 5:    methodString = " -G";
 6:  else
 7:    methodString = tostr(" -X ", o["method"]);
 8:  endif
 9:  dataString = "";
10:  for value, key in (o["data"])
11:    dataString = tostr(dataString, " -d ", key, "=", value, "");
12:  endfor
13:  cmd = tostr("curl -s", methodString, dataString, " ", o["url"]);
14:  value = exec(cmd:split());
15:  if (value[1] == 0)
16:    if (o["format"] == "json")
17:      value[2] = strsub(value[2], "~0A", "");
18:      value[2] = strsub(value[2], "~09", "");
19:      return parse_json(value[2]);
20:    else
21:      return value[2]:split("~0A");
22:    endif
23:  endif
And here is an example of how it is used, this verb queries the Steam API:
 
#697:"GetPlayerSummary" this none this
 1:  {id} = args;
 2:  idstr = "";
 3:  if (typeof(id) == LIST)
 4:    for x, k in (id)
 5:      if (k != 1)
 6:        idstr = tostr(idstr, ",", x);
 7:      else
 8:        idstr = tostr(x);
 9:      endif
10:    endfor
11:  else
12:    idstr = id;
13:  endif
14:  req = $curl:request(["data" -> ["key" -> this.apikey, "steamids" -> idstr], "method" -> "GET", "format" -> "json", "url" -> "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/"]);
15:  return req;
Reply all
Reply to author
Forward
0 new messages