Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 70 lines (48 sloc) 1.647 kb
3c2b299 @tsloughter added README
authored
1 README
2 ======
daf5714 update hackney and jsx and switch to rebar3 by default
Tristan Sloughter authored
3 Author: Tristan Sloughter t@crashfast.com
ee8ff83 @tsloughter typo
authored
4 website: http://blog.erlware.org
6934d16 @tsloughter version 0.0.2
authored
5
daf5714 update hackney and jsx and switch to rebar3 by default
Tristan Sloughter authored
6 Version: 0.1.0
3c2b299 @tsloughter added README
authored
7
8 Quick Start
9 -----------
10
daf5714 update hackney and jsx and switch to rebar3 by default
Tristan Sloughter authored
11 * Build
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
12
13 ```bash
daf5714 update hackney and jsx and switch to rebar3 by default
Tristan Sloughter authored
14 $ ./rebar3 compile
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
15 ```
16
9a88a40 @jwilberding cleaned up readme, specs, and config to uniformly use binary instead of ...
jwilberding authored
17 * Test
18
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
19 ```bash
daf5714 update hackney and jsx and switch to rebar3 by default
Tristan Sloughter authored
20 $ ./rebar3 shell
21 1> application:ensure_all_started(epubnub).
9a88a40 @jwilberding cleaned up readme, specs, and config to uniformly use binary instead of ...
jwilberding authored
22 ok
23 2> epubnub:publish(<<"hello_world">>, <<"hello">>).
4d797d5 fix README example
Tristan Sloughter authored
24 {[1,<<"Sent">>,<<"13612809348896246">>]}
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
25 ```
ff2e595 @tsloughter added ssl options but does not work for me yet
authored
26
27 Examples
778ee31 @tsloughter updated README
authored
28 --------
29
30 src/epn_example_client has a simple example of a gen_server subscribing to a channel. The init function takes an EPN record,
31 created with epubsub:new() in start_link and requests to subscribe to the "hello_world" channel and sends its PID with the
32 self() function so new messages are sent to this process.
ff2e595 @tsloughter added ssl options but does not work for me yet
authored
33
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
34 ```erlang
ff2e595 @tsloughter added ssl options but does not work for me yet
authored
35
778ee31 @tsloughter updated README
authored
36 init([EPN]) ->
9a88a40 @jwilberding cleaned up readme, specs, and config to uniformly use binary instead of ...
jwilberding authored
37 {ok, PID} = epubnub_sup:subscribe(EPN, <<"hello_world">>, self()),
2ae8df5 @tsloughter added unsubscrube
authored
38 {ok, #state{pid=PID}}.
778ee31 @tsloughter updated README
authored
39
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
40 ```
ff2e595 @tsloughter added ssl options but does not work for me yet
authored
41
778ee31 @tsloughter updated README
authored
42 Since currently the subscribe loop sends the message with the bang (!) the gen_server will handle the new message in handle_info.
43 The example simply prints out the contents of the message:
ff2e595 @tsloughter added ssl options but does not work for me yet
authored
44
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
45 ```erlang
778ee31 @tsloughter updated README
authored
46
47 handle_info({message, Message}, State) ->
48 io:format("~p~n", [Message]),
49 {noreply, State}.
50
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
51 ```
778ee31 @tsloughter updated README
authored
52
2ae8df5 @tsloughter added unsubscrube
authored
53 To unscribe we call the module stop function that sends an async stop message to the process. The handle_cast function handles this
54 message and return stop telling the gen_server to go to terminate. In terminate we take the PID of the subscribed process to the
55 epubnub unsubscribe function which sends it a terminate message and it exits.
56
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
57 ```erlang
2ae8df5 @tsloughter added unsubscrube
authored
58
59 stop() ->
60 gen_server:cast(?SERVER, stop).
61
62 handle_cast(stop, State) ->
63 {stop, normal, State}.
64
65 terminate(_Reason, #state{pid=PID}) ->
66 epubnub:unsubscribe(PID),
67 ok.
68
29420b8 @tsloughter added support for config file, set with defaults and updated to new sina...
authored
69 ```
Something went wrong with that request. Please try again.