Skip to content

Commit

Permalink
knm-GET-phone_numbers: bikeshedding
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp committed Apr 10, 2016
1 parent 0b74fe7 commit fc2354d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
26 changes: 13 additions & 13 deletions applications/crossbar/src/modules_v2/cb_phone_numbers_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ init() ->
-spec populate_phone_numbers(cb_context:context()) -> 'ok'.
populate_phone_numbers(Context) ->
AccountDb = cb_context:account_db(Context),
AccountId = cb_context:account_id(Context),
Now = wh_util:current_tstamp(),
PVTs = [{<<"_id">>, ?KNM_PHONE_NUMBERS_DOC}
,{<<"pvt_account_db">>, AccountDb}
,{<<"pvt_account_id">>, AccountId}
,{<<"pvt_account_id">>, cb_context:account_id()}
,{<<"pvt_vsn">>, <<"1">>}
,{<<"pvt_type">>, ?KNM_PHONE_NUMBERS_DOC}
,{<<"pvt_modified">>, wh_util:current_tstamp()}
,{<<"pvt_created">>, wh_util:current_tstamp()}
,{<<"pvt_modified">>, Now}
,{<<"pvt_created">>, Now}
],
_ = kz_datamgr:save_doc(AccountDb, wh_json:from_list(PVTs)),
'ok'.
Expand Down Expand Up @@ -190,7 +190,7 @@ allowed_methods(?LOCALITY) ->
[?HTTP_POST];
allowed_methods(?CHECK) ->
[?HTTP_POST];
allowed_methods(_) ->
allowed_methods(_PhoneNumber) ->
[?HTTP_GET, ?HTTP_PUT, ?HTTP_POST, ?HTTP_DELETE].

allowed_methods(?COLLECTION, ?ACTIVATE) ->
Expand All @@ -199,9 +199,9 @@ allowed_methods(?CLASSIFIERS, _PhoneNumber) ->
[?HTTP_GET];
allowed_methods(_PhoneNumber, ?ACTIVATE) ->
[?HTTP_PUT];
allowed_methods(_, ?RESERVE) ->
allowed_methods(_PhoneNumber, ?RESERVE) ->
[?HTTP_PUT];
allowed_methods(_, ?IDENTIFY) ->
allowed_methods(_PhoneNumber, ?IDENTIFY) ->
[?HTTP_GET].

%%--------------------------------------------------------------------
Expand All @@ -222,12 +222,12 @@ resource_exists(?PREFIX) -> 'true';
resource_exists(?LOCALITY) -> 'true';
resource_exists(?CHECK) -> 'true';
resource_exists(?CLASSIFIERS) -> 'true';
resource_exists(_) -> 'true'.
resource_exists(_PhoneNumber) -> 'true'.

resource_exists(_, ?ACTIVATE) -> 'true';
resource_exists(_, ?RESERVE) -> 'true';
resource_exists(_, ?IDENTIFY) -> 'true';
resource_exists(?CLASSIFIERS, _) -> 'true';
resource_exists(_PhoneNumber, ?ACTIVATE) -> 'true';
resource_exists(_PhoneNumber, ?RESERVE) -> 'true';
resource_exists(_PhoneNumber, ?IDENTIFY) -> 'true';
resource_exists(?CLASSIFIERS, _PhoneNumber) -> 'true';
resource_exists(_, _) -> 'false'.

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -955,7 +955,7 @@ set_response({'invalid', Reason}, _, Context, _) ->
lager:debug("invalid: ~p", [Reason]),
cb_context:add_validation_error(<<"address">>, <<"invalid">>, Reason, Context);
set_response({Error, Reason}, _, Context, _) ->
lager:debug("~p: ~p", [Error, Reason]),
lager:debug("error ~p: ~p", [Error, Reason]),
cb_context:add_system_error(Error, Reason, Context);
set_response(_Else, _, Context, _) ->
lager:debug("unexpected response: ~p", [_Else]),
Expand Down
9 changes: 3 additions & 6 deletions core/kazoo_number_manager/src/knm_phone_number.erl
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,14 @@ fetch(?BW_EXISTING_DID, Options) ->
handle_fetched_result(?BW_EXISTING_DID, Options);
fetch(_DID, _Options) ->
{'error', 'not_found'}.

-else.
fetch(Num, Options) ->
NormalizedNum = knm_converters:normalize(Num),
NumberDb = knm_converters:to_db(NormalizedNum),
case kz_datamgr:open_cache_doc(NumberDb, NormalizedNum) of
{'error', _R}=E ->
lager:error("failed to open ~s in ~s: ~p"
,[NormalizedNum, NumberDb, _R]
),
E;
{'error', _R}=Error ->
lager:error("failed to open ~s in ~s: ~p", [NormalizedNum, NumberDb, _R]),
Error;
{'ok', JObj} ->
handle_fetched_result(JObj, Options)
end.
Expand Down

0 comments on commit fc2354d

Please sign in to comment.