Skip to content
Browse files

cleaned up readme, specs, and config to uniformly use binary instead …

…of string
  • Loading branch information...
1 parent fb21210 commit 9a88a403d4a235cd496eee160101f190a63e7f3b @jwilberding jwilberding committed Feb 19, 2013
Showing with 42 additions and 52 deletions.
  1. +22 −32 README.md
  2. +3 −3 config/sys.config
  3. +17 −17 src/epubnub.erl
View
54 README.md
@@ -8,45 +8,35 @@ Version: 0.0.4
Quick Start
-----------
-.Dependencies
-
-Install agner (http://erlagner.org/):
+* Dependencies
```bash
-$ curl https://raw.github.com/agner/agner/master/scripts/oneliner | sh
+$ ./rebar get-deps
```
+* Compile
+
```bash
-$ ./deps
+$ ./rebar compile
```
+* Test
+
```bash
- $ ./sinan shell
- Erlang R14B01 (erts-5.8.2) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]
-
- Eshell V5.8.2 (abort with ^G)
- 1> starting: depends
- starting: build
- Building /Users/tristan/Devel/epubnub/src/epubnub.erl
- Building /Users/tristan/Devel/epubnub/src/epubnub_sup.erl
- Building /Users/tristan/Devel/epubnub/src/epubnub_app.erl
- starting: shell
- Eshell V5.8.2 (abort with ^G)
- 1> epubnub_app:start_deps().
- ok
- 2> epubnub:publish("hello_world", <<"hello">>).
- [1,<<"D">>]
- 3> epubnub:history("hello_world", 10).
- [<<"hello">>,<<"hello">>,<<"hello">>,<<"hello">>,
- <<"hello">>,<<"hello">>,<<"hello">>,<<"hello">>,<<"hello">>,
- <<"hello">>]
- 3> epubnub:time().
- 3588286186558
- 4> epubnub:subscribe("chat", fun(X) -> io:format("~p~n", [X]) end).
- ....
- BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
- (v)ersion (k)ill (D)b-tables (d)istribution
- a
+$ erl +K true +A30 -pa ebin -env ERL_LIBS lib:deps -config config/sys.config
+Erlang R15B03 (erts-5.9.3.1) [source] [smp:4:4] [async-threads:30] [hipe] [kernel-poll:true]
+
+Eshell V5.9.3.1 (abort with ^G)
+1> epubnub_app:start_deps().
+ok
+2> epubnub:publish(<<"hello_world">>, <<"hello">>).
+{[1,<<"Sent">>,<<"13612809348896246">>],
+ {client,hackney_tcp_transport,"pubsub.pubnub.com",80,netloc,
+ [],#Port<0.2131>,infinity,false,5,false,nil,undefined,
+ connected,done,nil,normal,#Fun<hackney_request.send.2>,done,
+ 4096,<<>>,
+ {1,1},
+ 30,nil,<<"keep-ali"...>>,<<"text"...>>}}
```
Examples
@@ -59,7 +49,7 @@ self() function so new messages are sent to this process.
```erlang
init([EPN]) ->
- {ok, PID} = epubnub_sup:subscribe(EPN, "hello_world", self()),
+ {ok, PID} = epubnub_sup:subscribe(EPN, <<"hello_world">>, self()),
{ok, #state{pid=PID}}.
```
View
6 config/sys.config
@@ -1,7 +1,7 @@
%%% -*- mode:erlang -*-
-[ {epubnub, [{origin, "pubsub.pubnub.com"},
- {pubkey, "demo"},
- {subkey, "demo"},
+[ {epubnub, [{origin, <<"pubsub.pubnub.com">>},
+ {pubkey, <<"demo">>},
+ {subkey, <<"demo">>},
{is_ssl, false}]}
].
View
34 src/epubnub.erl
@@ -20,10 +20,10 @@
unsubscribe/1,
subscribe/2,
subscribe/3,
- presence/2,
+ presence/2,
presence/3,
here_now/1,
- here_now/2,
+ here_now/2,
history/2,
history/3,
time/0,
@@ -66,19 +66,19 @@ new() ->
{ok, SSL} = ?WITH_DEFAULT(application:get_env(epubnub, ssl), ?DEFAULT_SSL),
#epn{origin=Origin, pubkey=PubKey, subkey=SubKey, secretkey=SecretKey, is_ssl=SSL}.
--spec new(string()) -> record(epn).
+-spec new(binary()) -> record(epn).
new(Origin) ->
#epn{origin=Origin}.
--spec new(string(), string()) -> record(epn).
+-spec new(binary(), binary()) -> record(epn).
new(PubKey, SubKey) ->
#epn{pubkey=PubKey, subkey=SubKey}.
--spec new(string(), string(), string()) -> record(epn).
+-spec new(binary(), binary(), binary()) -> record(epn).
new(PubKey, SubKey, SecretKey) ->
#epn{pubkey=PubKey, subkey=SubKey, secretkey=SecretKey}.
--spec new(string(), string(), string(), string()) -> record(epn).
+-spec new(binary(), binary(), binary(), binary()) -> record(epn).
new(Origin, PubKey, SubKey, SecretKey) ->
#epn{origin=Origin, pubkey=PubKey, subkey=SubKey, secretkey=SecretKey}.
@@ -122,17 +122,17 @@ unsubscribe(PID) when is_pid(PID) ->
%%% Subscribe functions
%%%===================================================================
--spec subscribe(string(), pid() | fun()) -> ok.
+-spec subscribe(binary(), pid() | fun()) -> ok.
subscribe(Channel, Callback) ->
subscribe(new(), Channel, Callback).
--spec subscribe(record(epn), string(), pid() | fun()) -> ok.
+-spec subscribe(record(epn), binary(), pid() | fun()) -> ok.
subscribe(EPN, Channel, PID) when is_pid(PID) ->
subscribe(EPN, Channel, fun(X) -> PID ! {message, X} end, <<"0">>);
subscribe(EPN, Channel, Callback) ->
subscribe(EPN, Channel, Callback, <<"0">>).
--spec subscribe(record(epn), string(), fun(), string()) -> ok.
+-spec subscribe(record(epn), binary(), fun(), binary()) -> ok.
subscribe(EPN, Channel, Function, TimeToken) ->
try
{[_, NewTimeToken], Client} = case request(EPN#epn.client, [EPN#epn.origin, <<"subscribe">>,
@@ -161,23 +161,23 @@ subscribe(EPN, Channel, Function, TimeToken) ->
%%% Presence functions
%%%===================================================================
--spec presence(string(), pid() | fun()) -> json_term().
+-spec presence(binary(), pid() | fun()) -> json_term().
presence(Channel, Callback) ->
presence(new(), Channel, Callback).
--spec presence(record(epn), string(), pid() | fun()) -> json_term().
+-spec presence(record(epn), binary(), pid() | fun()) -> json_term().
presence(EPN, Channel, Callback) ->
subscribe(EPN, [Channel, <<"-pnpres">>], Callback).
%%%===================================================================
%%% Here Now functions
%%%===================================================================
--spec here_now(string()) -> json_term().
+-spec here_now(binary()) -> json_term().
here_now(Channel) ->
here_now(new(), Channel).
--spec here_now(record(epn), string()) -> json_term().
+-spec here_now(record(epn), binary()) -> json_term().
here_now(EPN, Channel) ->
request(EPN#epn.client, [EPN#epn.origin, <<"v2">>, <<"presence">>, <<"sub-key">>,
EPN#epn.subkey, <<"channel">>, Channel],
@@ -187,11 +187,11 @@ here_now(EPN, Channel) ->
%%% History functions
%%%===================================================================
--spec history(string(), integer() | string()) -> json_term().
+-spec history(binary(), integer() | binary()) -> json_term().
history(Channel, Limit) ->
history(new(), Channel, Limit).
--spec history(record(epn), string(), integer() | string()) -> json_term().
+-spec history(record(epn), binary(), integer() | binary()) -> json_term().
history(EPN, Channel, Limit) when is_integer(Limit) ->
history(EPN, Channel, integer_to_list(Limit));
history(EPN, Channel, Limit) when is_list(Limit) ->
@@ -228,7 +228,7 @@ uuid(EPN) ->
%%% Internal functions
%%%===================================================================
--spec request(tuple(), list(string()), boolean()) -> json_term().
+-spec request(tuple(), list(binary()), boolean()) -> json_term().
request(Client, URLList, IsSSL) ->
case Client of
undefined ->
@@ -248,5 +248,5 @@ request(Client, URLList, IsSSL) ->
{ok, Body, Client2} = hackney:body(Client1),
{jsx:decode(Body), Client2}.
-bin_join([H | Rest], BinString) ->
+bin_join([H | Rest], BinString) ->
<< H/binary, << <<BinString/binary, B/binary>> || B <- Rest >>/binary >>.

0 comments on commit 9a88a40

Please sign in to comment.
Something went wrong with that request. Please try again.