Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removes all trailing whitespace.

  • Loading branch information...
commit 51cfa0a5f1ac55b9be6bc0ecd8849882e61e7ca2 1 parent f3e273f
@m2w authored
View
12 README.md
@@ -4,17 +4,17 @@
## statistics
-Every shortened URL keeps track of visitor counts (non-real time total and unique visit counts) and provides estimates for the geographic location of visitors.
+Every shortened URL keeps track of visitor counts (non-real time total and unique visit counts) and provides estimates for the geographic location of visitors.
## 'nsfw' functionality
-Appending `?landing=true` to a shortened URL, prevents the automatic redirect, instead a landing page, showing the full target URL and an "are you sure you want to proceed" button, is displayed.
+Appending `?landing=true` to a shortened URL, prevents the automatic redirect, instead a landing page, showing the full target URL and an "are you sure you want to proceed" button, is displayed.
Reporting inappropriate URLs is kept extremely simple, just add `/report` to the URL. URLs that reach a certain threshold - this mechanism will be expanded in the future (pull requests are most welcome ;)) - are permanetly banned.
## demo
-Live demo will be up as soon as I get around to it.
+Live demo will be up as soon as I get around to it.
To play around with it on localhost, just clone, `make compile`, `./start.sh` and open [http://localhost:8000](http://localhost:8000).
@@ -46,7 +46,7 @@ code quality:
-----------------
GET /path/stats -> view stats for the path
-----------------
- GET /path/check -> utility URL to facility 'low' overhead
- checking whether a path is already taken
- via ajax (@ W3C please give us an option
+ GET /path/check -> utility URL to facility 'low' overhead
+ checking whether a path is already taken
+ via ajax (@ W3C please give us an option
to disable the automatic redirect on 30x!)
View
4 src/erli.erl
@@ -26,7 +26,7 @@ start_link() ->
ensure_started(mochiweb),
ensure_started(mnesia),
erli_storage:init({}), % initialize mnesia
- application:set_env(webmachine, webmachine_logger_module,
+ application:set_env(webmachine, webmachine_logger_module,
webmachine_logger),
ensure_started(webmachine),
erli_sup:start_link().
@@ -42,7 +42,7 @@ start() ->
ensure_started(mochiweb),
ensure_started(mnesia),
erli_storage:init({}), % initialize mnesia
- application:set_env(webmachine, webmachine_logger_module,
+ application:set_env(webmachine, webmachine_logger_module,
webmachine_logger),
ensure_started(webmachine),
application:start(erli).
View
12 src/erli.hrl
@@ -6,23 +6,23 @@
% @doc The number of reports before Target URLs are banned.
-define(FLAG_LIMIT, 5).
% @doc The maximal number of attempts to generate a unique URL path.
--define(MAX_CONFLICTS, 100).
+-define(MAX_CONFLICTS, 100).
% @doc The number of requests allowed during a set timespan.
--define(REQ_LIMIT, 100000).
+-define(REQ_LIMIT, 100000).
%%%=============================================================================
%%% ERLI RECORDS
%%% @end
%%%=============================================================================
%%------------------------------------------------------------------------------
-%% @type target() = #target{target=binary(),
-%% paths=list(),
+%% @type target() = #target{target=binary(),
+%% paths=list(),
%% reported=interger(),
%% rep_num=integer()}
%%------------------------------------------------------------------------------
-record(target, {target, paths=[], reported=0, rep_num=0}).
%%------------------------------------------------------------------------------
-%% @type timeslots() = #timeslots{night=integer(),
+%% @type timeslots() = #timeslots{night=integer(),
%% morning=integer(),
%% afternoon=integer(),
%% evening=integer()}
@@ -35,7 +35,7 @@
%% country_lst=list(),
%% timeslot_visits=timeslots()}
%%------------------------------------------------------------------------------
--record(path, {path, total_clicks=0, unique_clicks=0, country_lst=[],
+-record(path, {path, total_clicks=0, unique_clicks=0, country_lst=[],
timeslot_visits=#timeslots{}}).
%%------------------------------------------------------------------------------
%% @type visitor_ip = #visitor_ip{visitor_ip=string(), path=list()}
View
2  src/erli_error_handler.erl
@@ -12,7 +12,7 @@ render_error(Code, Req, Reason) ->
case Req:has_response_body() of
{true,_} ->
Req:response_body();
- {false,_} ->
+ {false,_} ->
render_error_body(Code, Req:trim_state(), Reason)
end.
View
36 src/erli_stats.erl
@@ -1,7 +1,7 @@
%% @author Moritz Windelen <moritz@tibidat.com>
%% @copyright 2011-2012 Moritz Windelen.
-%% @doc gen_server that handles periodic parsing of
+%% @doc gen_server that handles periodic parsing of
%% webmachine logfiles to extract usage statistics.
%% @end
@@ -15,11 +15,11 @@
start_link/1]).
%% gen_server callbacks
--export([init/1,
- handle_call/3,
- handle_cast/2,
- handle_info/2,
- terminate/2,
+-export([init/1,
+ handle_call/3,
+ handle_cast/2,
+ handle_info/2,
+ terminate/2,
code_change/3]).
-include("erli.hrl").
@@ -40,12 +40,12 @@ start_link() ->
%% @spec start_link(list()) -> {ok, Pid}
%% @doc Api call to initialize the gen_server with custom values.
%% Notes:
-%% ScriptDir is the relative path of the script containing dir to
+%% ScriptDir is the relative path of the script containing dir to
%% code:priv_dir/1
%% ScriptFile is the filename of the script to parse the logs
-%% Interval represents the amount of time between calls to the
+%% Interval represents the amount of time between calls to the
%% script, in ms. (Note that the current implementation does <b>NOT</b>
-%% prevent calling the parser multiple times during an hour, resulting in
+%% prevent calling the parser multiple times during an hour, resulting in
%% inflated visitor counts.
%% @end
%%------------------------------------------------------------------------------
@@ -66,8 +66,8 @@ handle_cast(_Req, State) ->
handle_info(parse_eval, State) ->
{ok, App} = application:get_application(),
- PyCmd = "python -u " ++ filename:join([code:priv_dir(App),
- State#state.script_dir,
+ PyCmd = "python -u " ++ filename:join([code:priv_dir(App),
+ State#state.script_dir,
State#state.script_file]),
Port = open_port({spawn, PyCmd}, [{packet, 1}, binary, use_stdio]),
case retrieve_path_stats(Port, erli_storage:path_list()) of
@@ -92,7 +92,7 @@ code_change(_OldVsn, State, _Extra) ->
%%%=============================================================================
%%------------------------------------------------------------------------------
%% @private
-%% @spec retrieve_path_stats(Port::port(), list()) ->
+%% @spec retrieve_path_stats(Port::port(), list()) ->
%% {parsing_complete, true} |
%% {reschedule, Time::integer()} |
%% {error, timeout}
@@ -108,20 +108,20 @@ retrieve_path_stats(Port, [Path | RemPaths]) ->
case binary_to_term(RespData) of
{reschedule, Time} ->
retrieve_path_stats(Port, []), % close the port before
- % rescheduling
+ % rescheduling
{reschedule, Time};
{Countries, UniqueIPs, ClickCount, TimeStamp} ->
- erli_storage:update_path_stats(Path,
- Countries,
- UniqueIPs,
- ClickCount,
+ erli_storage:update_path_stats(Path,
+ Countries,
+ UniqueIPs,
+ ClickCount,
TimeStamp),
retrieve_path_stats(Port, RemPaths)
end
after
5000 ->
error_logger:warning_msg("[ERLI] ~s timed out on retrieve_path_stats/2"
- " for path ~s~n",
+ " for path ~s~n",
[?MODULE, Path]),
{error, timeout}
end;
View
112 src/erli_storage.erl
@@ -19,35 +19,35 @@
%%------------------------------------------------------------------------------
%% @spec init(_Config) -> ok
-%% @doc Initializes the mnesia backend, creating the schema and tables if
+%% @doc Initializes the mnesia backend, creating the schema and tables if
%% necessary.
%% @end
%%------------------------------------------------------------------------------
init(_Config) ->
case is_fresh_startup(node()) of
- {is_fresh, true} ->
+ {is_fresh, true} ->
mnesia:stop(),
mnesia:create_schema([node()]),
mnesia:start(),
{atomic, ok} = create_tables(),
ok;
- {is_fresh, Tables} ->
- ok = mnesia:wait_for_tables(Tables, 60000)
+ {is_fresh, Tables} ->
+ ok = mnesia:wait_for_tables(Tables, 60000)
end.
%%------------------------------------------------------------------------------
-%% @spec put(TargetUrl::binary()) -> {ok, target()} |
+%% @spec put(TargetUrl::binary()) -> {ok, target()} |
%% {error, target_banned} |
%% {error, path_generation_failed}
-%% @doc Creates a new entry for the target URL or returns the current shortened
+%% @doc Creates a new entry for the target URL or returns the current shortened
%% path for the URL.
%% @end
%%------------------------------------------------------------------------------
put(TargetUrl) ->
{atomic, MatchingTarget} = mnesia:transaction(
- fun() ->
+ fun() ->
Table = mnesia:table(target),
- QueryHandle = qlc:q([T || T <- Table,
+ QueryHandle = qlc:q([T || T <- Table,
T#target.target =:= TargetUrl]),
qlc:eval(QueryHandle)
end),
@@ -65,11 +65,11 @@ put(TargetUrl, PathS) ->
Path = #path{path=PathS},
case read(PathS) of
{error, not_found} ->
- {atomic, MatchingTarget} =
+ {atomic, MatchingTarget} =
mnesia:transaction(
- fun() ->
+ fun() ->
Table = mnesia:table(target),
- QueryHandle = qlc:q([T || T <- Table,
+ QueryHandle = qlc:q([T || T <- Table,
T#target.target =:= TargetUrl]),
qlc:eval(QueryHandle)
end),
@@ -80,17 +80,17 @@ put(TargetUrl, PathS) ->
NewTarget = T#target{paths=[Path|ExistingPaths]},
{atomic, _Ret} = mnesia:transaction(
fun() ->
- mnesia:write(target,
- NewTarget,
+ mnesia:write(target,
+ NewTarget,
write)
end),
{ok, NewTarget};
- [] ->
+ [] ->
NewTarget = #target{target=TargetUrl, paths=[Path]},
{atomic, _Ret} = mnesia:transaction(
fun() ->
- mnesia:write(target,
- NewTarget,
+ mnesia:write(target,
+ NewTarget,
write)
end),
{ok, NewTarget}
@@ -98,19 +98,19 @@ put(TargetUrl, PathS) ->
_ ->
{error, conflict}
end.
-
+
%%------------------------------------------------------------------------------
%% @spec read(PathS::string()) -> {ok, target()} |
-%% {error, target_banned} |
+%% {error, target_banned} |
%% {error, not_found}
%% @doc Retrieves the complete short_url record for a shortened URL.
%% @end
%%------------------------------------------------------------------------------
read(PathS) ->
{atomic, Result} = mnesia:transaction(
- fun() ->
+ fun() ->
Table = mnesia:table(target),
- QueryHandle = qlc:q([T || T <- Table, path_in_target(T#target.paths,
+ QueryHandle = qlc:q([T || T <- Table, path_in_target(T#target.paths,
PathS)]),
qlc:eval(QueryHandle)
end),
@@ -124,7 +124,7 @@ read(PathS) ->
end.
%%------------------------------------------------------------------------------
-%% @spec delete(PathS::string()) -> {ok, target()} |
+%% @spec delete(PathS::string()) -> {ok, target()} |
%% {error, not_found}
%% @doc Flags the URL linked by Path.
%% @end
@@ -132,7 +132,7 @@ read(PathS) ->
delete(PathS) ->
case read(PathS) of
{_, #target{rep_num = RepNum, _=_} = Target} ->
- NewTarget = Target#target{reported=true,
+ NewTarget = Target#target{reported=true,
rep_num=RepNum+1},
ok = mnesia:dirty_write(target, NewTarget),
{ok, NewTarget};
@@ -146,7 +146,7 @@ delete(PathS) ->
%% @end
%%------------------------------------------------------------------------------
path_list() ->
- PathRecs = mnesia:dirty_select(target,
+ PathRecs = mnesia:dirty_select(target,
[{#target{paths='$1', _='_'}, [], ['$1']}]),
lists:flatten(PathRecs).
@@ -161,11 +161,11 @@ update_path_stats(Path, Countries, UniqueIPs, ClickCount, {_Date, {H, _M, _S}})
% grab the target record
{ok, #target{paths=Paths, _=_} = Target} = read(Path#path.path),
% filter out the important path (not doing this in the read call leaves it 'cheap'
- {[#path{country_lst=CL, total_clicks=TC, unique_clicks=UC, timeslot_visits=TSV, _=_}=ThePath],
- OtherPaths} =
- lists:partition(fun(P) ->
- Path =:= P
- end,
+ {[#path{country_lst=CL, total_clicks=TC, unique_clicks=UC, timeslot_visits=TSV, _=_}=ThePath],
+ OtherPaths} =
+ lists:partition(fun(P) ->
+ Path =:= P
+ end,
Paths),
% check if there is a new ip for this path
@@ -174,13 +174,13 @@ update_path_stats(Path, Countries, UniqueIPs, ClickCount, {_Date, {H, _M, _S}})
% merge old and new country lists
CountryUnion = sets:to_list(
sets:union(
- sets:from_list(CL),
+ sets:from_list(CL),
sets:from_list(Countries)
)
),
-
+
% update the path stats
- NewPath = ThePath#path{country_lst=CountryUnion,
+ NewPath = ThePath#path{country_lst=CountryUnion,
unique_clicks=UC + UniqueClicks,
total_clicks=TC + ClickCount,
timeslot_visits=classify_timeslot(H, ClickCount, TSV)},
@@ -201,8 +201,8 @@ update_path_stats(Path, Countries, UniqueIPs, ClickCount, {_Date, {H, _M, _S}})
%% night (0-6) | morning (6-12) | afternoon (12-18) | evening (18-24)
%% @end
%%------------------------------------------------------------------------------
-classify_timeslot(Hour,
- Clicks,
+classify_timeslot(Hour,
+ Clicks,
#timeslots{night=N, morning=M, afternoon=A, evening=E}=TS) ->
case Hour of
H when H =< 6 ->
@@ -218,7 +218,7 @@ classify_timeslot(Hour,
%%------------------------------------------------------------------------------
%% @private
%% @spec is_ip_unique_for_path(Path::path(), IP::binary()) -> true | false
-%% @doc Returns whether an client with the IP-Address `IP' already visited
+%% @doc Returns whether an client with the IP-Address `IP' already visited
%% `Path'.
%% @end
%%------------------------------------------------------------------------------
@@ -241,14 +241,14 @@ is_ip_unique_for_path(Path, IP) ->
%%------------------------------------------------------------------------------
%% @private
-%% @spec path_in_target(PathList::list(), SearchPath::path()) -> true |
+%% @spec path_in_target(PathList::list(), SearchPath::path()) -> true |
%% false
%% @doc Returns whether the path `SearchPath' is contained in `PathList'.
%% @end
%%------------------------------------------------------------------------------
path_in_target(PathList, SearchPath) ->
Path = lists:filter(
- fun(#path{path=ThePath, _=_}) -> ThePath =:= SearchPath end,
+ fun(#path{path=ThePath, _=_}) -> ThePath =:= SearchPath end,
PathList),
case Path of
[] ->
@@ -259,11 +259,11 @@ path_in_target(PathList, SearchPath) ->
%%------------------------------------------------------------------------------
%% @private
-%% @spec make_path(Url::binary(), MatchingTarget::list())
+%% @spec make_path(Url::binary(), MatchingTarget::list())
%% -> {error, target_banned} |
%% {ok, path()} |
%% {error, path_generation_failed}
-%% @doc Given a URL create a new target record or update an existing one by
+%% @doc Given a URL create a new target record or update an existing one by
%% generating a new path record for it.
%% @end
%%------------------------------------------------------------------------------
@@ -280,13 +280,13 @@ make_path(Url, MatchingTarget) ->
NewTarget = T#target{paths=[Path|ExistingPaths]},
{atomic, _Ret} = mnesia:transaction(
fun() ->
- mnesia:write(target,
- NewTarget,
+ mnesia:write(target,
+ NewTarget,
write)
end),
{ok, Path}
end;
- [] ->
+ [] ->
case make_unique_path(Url) of
{error, path_generation_failed} ->
{error, path_generation_failed};
@@ -295,8 +295,8 @@ make_path(Url, MatchingTarget) ->
T = #target{target=Url, paths=[Path]},
{atomic, _Ret} = mnesia:transaction(
fun() ->
- mnesia:write(target,
- T,
+ mnesia:write(target,
+ T,
write)
end),
{ok, Path}
@@ -307,7 +307,7 @@ make_path(Url, MatchingTarget) ->
%% @private
%% @spec make_unique_path(URL::binary()) -> {ok, string()} |
%% {error, path_generation_failed}
-%% @doc Generate a unique path using the base64 encoded md5 of the URL
+%% @doc Generate a unique path using the base64 encoded md5 of the URL
%% concatenated to the current system time.
%% @end
%%------------------------------------------------------------------------------
@@ -322,7 +322,7 @@ make_unique_path(TargetUrl, NrOfHashConflicts) ->
[] ->
{ok, CleanPath};
_Res ->
- if
+ if
NrOfHashConflicts < ?MAX_CONFLICTS ->
make_unique_path(TargetUrl, NrOfHashConflicts + 1);
true ->
@@ -333,23 +333,23 @@ make_unique_path(TargetUrl, NrOfHashConflicts) ->
%%------------------------------------------------------------------------------
%% @private
-%% spec is_fresh_startup(Node::node()) -> {is_fresh, true} |
+%% spec is_fresh_startup(Node::node()) -> {is_fresh, true} |
%% {is_fresh, list()}
%% @doc Returns whether tables have already been created on the node.
%% Modified from: http://goo.gl/GlpV5
%% @end
%%------------------------------------------------------------------------------
is_fresh_startup(Node) ->
- case mnesia:system_info(tables) of
+ case mnesia:system_info(tables) of
[schema] ->
{is_fresh, true};
- Tables ->
- case mnesia:table_info(schema, cookie) of
- {_, Node} ->
- {is_fresh, Tables};
- _ ->
+ Tables ->
+ case mnesia:table_info(schema, cookie) of
+ {_, Node} ->
+ {is_fresh, Tables};
+ _ ->
{is_fresh, true}
- end
+ end
end.
%%------------------------------------------------------------------------------
@@ -359,10 +359,10 @@ is_fresh_startup(Node) ->
%% @end
%%------------------------------------------------------------------------------
create_tables() ->
- {atomic, ok} = mnesia:create_table(target, [{attributes,
+ {atomic, ok} = mnesia:create_table(target, [{attributes,
record_info(fields, target)},
{disc_copies, [node()]}]),
- {atomic, ok} = mnesia:create_table(visitor_ip, [{attributes,
- record_info(fields,
+ {atomic, ok} = mnesia:create_table(visitor_ip, [{attributes,
+ record_info(fields,
visitor_ip)},
{disc_copies, [node()]}]).
View
2  src/erli_sup.erl
@@ -66,7 +66,7 @@ init([]) ->
Stats = {erli_stats, {erli_stats, start_link, []},
permanent, 5000, worker, [erli_stats]},
% currently supported are "hour" | "day"
- % the throttle interval indicates over which time frame requests are
+ % the throttle interval indicates over which time frame requests are
% throttled => e.g N Requests / ThrottleInterval
ThrottleInterval = "hour",
Throttle = {erli_throttle, {erli_throttle, start_link, [ThrottleInterval]},
View
14 src/erli_throttle.erl
@@ -35,9 +35,9 @@ start_link(Interval) ->
case whereis(erli_throttle) of
undefined ->
{ok, Pid} = gen_server:start_link(?MODULE, [Interval], []),
- %register the name locally since we can't pass dynamic
+ %register the name locally since we can't pass dynamic
%information to our webmachine resource (limited to dispatcher args)
- register(erli_throttle, Pid),
+ register(erli_throttle, Pid),
{ok, Pid};
Pid ->
{ok, Pid}
@@ -61,8 +61,8 @@ init([Interval]) ->
% you're on your own here...
{ok, #state{span=Interval}, 0}.
-handle_call(should_throttle, _From, #state{reqs_handled=RH,
- span=Span,
+handle_call(should_throttle, _From, #state{reqs_handled=RH,
+ span=Span,
last_reset=LR}=State) ->
C = RH + 1,
NewState = State#state{reqs_handled=C},
@@ -80,7 +80,7 @@ handle_cast(_Req, State) ->
% reset the req count after a set timespan
handle_info(reset, State) ->
- error_logger:info_msg("[ERLI] handled a total of ~p requests",
+ error_logger:info_msg("[ERLI] handled a total of ~p requests",
[State#state.reqs_handled]),
{_, T} = calendar:universal_time(),
Time = calendar:time_to_seconds(T),
@@ -113,10 +113,10 @@ initial_offset(Interval, {_H, M, S}=Time) when Interval =:= "hour"->
M2Go = 60 - M,
T = M2Go * 60 + S2Go,
erlang:send_after(T * 1000, self(), reset), % trigger the reset cycle
- {ok, #state{span=3600,
+ {ok, #state{span=3600,
last_reset=calendar:time_to_seconds(Time)-S-M*60}};
initial_offset(Interval, {H, M, S}=Time) when Interval =:= "day" ->
T = 86400 - calendar:time_to_seconds({H, M, S}),
erlang:send_after(T * 1000, self(), reset), % trigger the reset cycle
- {ok, #state{span=86400,
+ {ok, #state{span=86400,
last_reset=86400-calendar:time_to_seconds(Time)}}.
View
2  src/erli_util.erl
@@ -21,7 +21,7 @@ is_valid_url(Url) ->
"(?:(?:[0-9]+\.){3}(?:[0-9]+))|" % IPs
"(?:(?:[a-f0-9]+\:)+(?:[a-f0-9]+)))(?:(?:\s*$)|" % IPv6
"(?:(?:[:\/?]).+$))", % any query/path suffixes
- [dotall]),
+ [dotall]),
case re:run(Url, Re, [{capture, none}]) of
match ->
true;
View
58 src/path_resource.erl
@@ -31,8 +31,8 @@ service_available(RD, Ctx) ->
false ->
{true, RD, Ctx};
{true, RetryAfter}->
- NRD = wrq:set_resp_header("Retry-After",
- integer_to_list(RetryAfter),
+ NRD = wrq:set_resp_header("Retry-After",
+ integer_to_list(RetryAfter),
RD),
{false, NRD, Ctx}
end.
@@ -133,29 +133,29 @@ process_body(Url, RD, Ctx) ->
%% @end
%%------------------------------------------------------------------------------
handle_path(Type, RD, Ctx) ->
- NRD = wrq:set_resp_header("Location",
- binary_to_list(Ctx#target.target),
+ NRD = wrq:set_resp_header("Location",
+ binary_to_list(Ctx#target.target),
RD),
case wrq:get_qs_value("landing", RD) of
- undefined ->
+ undefined ->
{{halt, 302}, NRD, Ctx};
- _Value ->
+ _Value ->
handle_landing_page(Type, NRD, Ctx)
end.
%%------------------------------------------------------------------------------
%% @private
-%% @spec handle_landing_page(ContentType::atom(), RD::wrq:reqdata(),
+%% @spec handle_landing_page(ContentType::atom(), RD::wrq:reqdata(),
%% Ctx::target()) ->
%% {iolist(), wrq:reqdata(), target()}
-%% @doc Renders a HTML landing page or returns json containing the necessary
+%% @doc Renders a HTML landing page or returns json containing the necessary
%% information for a path and its target URL.
%% @end
%%------------------------------------------------------------------------------
handle_landing_page(ContentType, RD, Ctx) when ContentType =:= html ->
- {ok, Content} = landing_dtl:render([{target,
+ {ok, Content} = landing_dtl:render([{target,
Ctx#target.target},
- {path,
+ {path,
wrq:path_info(path)}
]),
{Content, RD, Ctx};
@@ -174,8 +174,8 @@ handle_landing_page(_ContentType, RD, Ctx) ->
%%------------------------------------------------------------------------------
handle_path_subreq(Type, RD, Ctx) ->
Path = wrq:path_info(path, RD),
- {[ThePath], _OtherPaths} =
- lists:partition(fun(#path{path=P, _=_}=_Path) -> Path =:= P end,
+ {[ThePath], _OtherPaths} =
+ lists:partition(fun(#path{path=P, _=_}=_Path) -> Path =:= P end,
Ctx#target.paths),
case wrq:disp_path(RD) of
"stats" ->
@@ -190,36 +190,36 @@ handle_path_subreq(Type, RD, Ctx) ->
%%------------------------------------------------------------------------------
%% @private
-%% @spec handle_stats_subreq(ContentType::atom(), Path::string(),
+%% @spec handle_stats_subreq(ContentType::atom(), Path::string(),
%% RD::wrq:reqdata(), Ctx::target()) ->
%% {iolist(), wrq:reqdata(), target()}
%% @doc Renders the HTML or json response for path statistics.
%% @end
%%------------------------------------------------------------------------------
handle_stats_subreq(ContentType, Path, RD, Ctx) when ContentType =:= html ->
- {ok, Content} = stats_dtl:render([{target, Ctx#target.target},
- {path, list_to_binary(Path#path.path)},
- {total_clicks, Path#path.total_clicks},
- {unique_clicks, Path#path.unique_clicks},
+ {ok, Content} = stats_dtl:render([{target, Ctx#target.target},
+ {path, list_to_binary(Path#path.path)},
+ {total_clicks, Path#path.total_clicks},
+ {unique_clicks, Path#path.unique_clicks},
{country_lst, Path#path.country_lst},
- {timeslots,
+ {timeslots,
mochiweb_util:record_to_proplist(
- Path#path.timeslot_visits,
+ Path#path.timeslot_visits,
record_info(fields, timeslots)
)
}]),
{Content, RD, Ctx};
handle_stats_subreq(ContentType, Path, RD, Ctx) when ContentType =:= json ->
- % TODO: switch from mochijson2 to https://github.com/davisp/eep0018
- Content = mochijson2:encode({struct,
- [{target, Ctx#target.target},
- {path, list_to_binary(Path#path.path)},
- {total_clicks, Path#path.total_clicks},
- {unique_clicks, Path#path.unique_clicks},
+ % TODO: switch from mochijson2 to https://github.com/davisp/eep0018
+ Content = mochijson2:encode({struct,
+ [{target, Ctx#target.target},
+ {path, list_to_binary(Path#path.path)},
+ {total_clicks, Path#path.total_clicks},
+ {unique_clicks, Path#path.unique_clicks},
{country_lst, Path#path.country_lst},
- {timeslots,
+ {timeslots,
mochiweb_util:record_to_proplist(
- Path#path.timeslot_visits,
+ Path#path.timeslot_visits,
record_info(fields, timeslots)
)}
]}),
@@ -229,14 +229,14 @@ handle_stats_subreq(_ContentType, _Path, RD, Ctx) ->
%%------------------------------------------------------------------------------
%% @private
-%% @spec handle_report_subreq(ContentType::atom(), Path::string(),
+%% @spec handle_report_subreq(ContentType::atom(), Path::string(),
%% RD::wrq:reqdata(), Ctx::target()) ->
%% {iolist(), wrq:reqdata(), target()}
%% @doc Renders the HTML or json response for reporting a path.
%% @end
%%------------------------------------------------------------------------------
handle_report_subreq(ContentType, Path, RD, Ctx) when ContentType =:= html ->
- {ok, Content} = report_dtl:render([{target, Ctx#target.target},
+ {ok, Content} = report_dtl:render([{target, Ctx#target.target},
{path, list_to_binary(Path#path.path)}]),
{Content, RD, Ctx};
handle_report_subreq(ContentType, _Path, RD, Ctx) when ContentType =:= json ->
View
6 src/root_resource.erl
@@ -26,8 +26,8 @@ service_available(RD, Ctx) ->
false ->
{true, RD, Ctx};
{true, RetryAfter}->
- NRD = wrq:set_resp_header("Retry-After",
- integer_to_list(RetryAfter),
+ NRD = wrq:set_resp_header("Retry-After",
+ integer_to_list(RetryAfter),
RD),
{false, NRD, Ctx}
end.
@@ -127,7 +127,7 @@ check_url_provided(RD) ->
maybe_store(RD, Ctx) ->
case erli_util:is_valid_url(Ctx#target.target) of
false ->
- % TODO: add request body which contains some kind of info
+ % TODO: add request body which contains some kind of info
% (e.g. needs a schema definition)
{{halt, 400}, RD, Ctx};
true ->
View
14 src/static_resource.erl
@@ -26,8 +26,8 @@ allowed_methods(RD, Ctx) ->
{['GET'], RD, Ctx}.
content_types_provided(RD, Ctx) ->
- {[{webmachine_util:guess_mime(wrq:disp_path(RD)), maybe_provide_content}],
- RD,
+ {[{webmachine_util:guess_mime(wrq:disp_path(RD)), maybe_provide_content}],
+ RD,
Ctx#state{fpath=determine_fpath(RD, Ctx)}}.
%%%=============================================================================
@@ -36,7 +36,7 @@ content_types_provided(RD, Ctx) ->
%%------------------------------------------------------------------------------
%% @spec maybe_provide_content(RD::wrq:reqdata(), Ctx::state()) ->
%% {{halt, 403}, wrq:reqdata(), state()} |
-%% {binary(), wrq:reqdata(), state()} |
+%% {binary(), wrq:reqdata(), state()} |
%% {{halt, 404}, wrq:reqdata(), state()}
%% @doc Determines whether to provide the requested resource, based on whether
%% it exists and is 'safe'.
@@ -57,9 +57,9 @@ maybe_provide_content(RD, #state{fpath=Path, _=_}=Ctx) ->
%%------------------------------------------------------------------------------
%% @private
%% @spec maybe_fetch_content(FPath::string(), RD::wrq:reqdata(), Ctx::state())
-%% -> {binary(), wrq:reqdata(), state()} |
+%% -> {binary(), wrq:reqdata(), state()} |
%% {{halt, 404}, wrq:reqdata(), state()}
-%% @doc Determines whether the request should be processed further based on
+%% @doc Determines whether the request should be processed further based on
%% whether the requested resource exists or not.
%% @end
%%------------------------------------------------------------------------------
@@ -88,11 +88,11 @@ determine_fpath(RD, Ctx) ->
%%------------------------------------------------------------------------------
%% @private
-%% @spec fetch_content(RD::wrq:reqdata(), Ctx::state()) ->
+%% @spec fetch_content(RD::wrq:reqdata(), Ctx::state()) ->
%% {binary(), wrq:reqdata(), state()}
%% @doc Returns the resource contents.
%% @end
%%------------------------------------------------------------------------------
-fetch_content(RD, Ctx) ->
+fetch_content(RD, Ctx) ->
{ok, Content} = file:read_file(Ctx#state.fpath),
{Content, RD, Ctx}.
Please sign in to comment.
Something went wrong with that request. Please try again.