Sha256: 8ab0b65e7f8aa98a198c9a93ff26080fe6cba96dc0e414d519d851babb0ace0e

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

-module(tinderl).
-export([start/4, stop/0, speak/1, paste/1]).

start(Domain, Email, Password, Room) -> 
  spawn(fun() -> 
    register(tinderl, self()), 
    process_flag(trap_exit, true), 
    Cmd = lists:flatten(io_lib:format("ruby ./tinderl.rb ~s ~s ~s ~s", [Domain, Email, Password, Room])),
    Port = open_port({spawn, Cmd}, [{packet, 4}, use_stdio, exit_status, binary]), 
    port_loop(Port) 
  end). 

stop() -> tinderl ! stop. 


speak(String) when is_list(String) -> speak(list_to_binary(String));
speak(String) when is_binary(String) -> tinderl ! {speak, self(), String}.

paste(String) when is_list(String) -> speak(list_to_binary(String));
paste(String) when is_binary(String) -> tinderl ! {paste, self(), String}.

port_loop(Port) ->
  receive
    {speak, _Caller, String} ->
      Data = term_to_binary({speak, String}),
      Port ! {self(), {command, Data}}, 

      port_loop(Port);
    
    {paste, _Caller, String} ->
        Data = term_to_binary({paste, String}),
        Port ! {self(), {command, Data}}, 

        port_loop(Port);
        
    stop -> 
      Port ! {self(), close}, 
      receive 
        {Port, closed} -> exit(normal) 
      end; 
    
    {'EXIT', Port, Reason} ->
      exit({port_terminated,Reason})
  end.

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
mojombo-erlectricity-0.2.1 examples/tinderl/tinderl.erl
tmm1-erlectricity-0.2.1 examples/tinderl/tinderl.erl
erlectricity-0.2.0 examples/tinderl/tinderl.erl
erlectricity-0.2.1 examples/tinderl/tinderl.erl