Skip to content

Commit

Permalink
removed paramterized modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tholschuh committed Mar 15, 2013
1 parent 3e97f30 commit 45b897a
Show file tree
Hide file tree
Showing 9 changed files with 474 additions and 380 deletions.
28 changes: 25 additions & 3 deletions include/cferl.hrl
Expand Up @@ -6,19 +6,41 @@
%%% Copyright (c) 2010 David Dossot %%% Copyright (c) 2010 David Dossot
%%% %%%


-define(API_BASE_URL, "auth.api.rackspacecloud.com"). -define(US_API_BASE_URL, "identity.api.rackspacecloud.com").
-define(UK_API_BASE_URL, "lon.identity.api.rackspacecloud.com").
-define(VERSION_PATH, "/v1.0"). -define(VERSION_PATH, "/v1.0").


-define(DEFAULT_REQUEST_TIMEOUT, 30000). -define(DEFAULT_REQUEST_TIMEOUT, 30000).
-define(OBJECT_META_HEADER_PREFIX, "X-Object-Meta-"). -define(OBJECT_META_HEADER_PREFIX, "X-Object-Meta-").
-define(DIRECTORY_OBJECT_CONTENT_TYPE, <<"application/directory">>). -define(DIRECTORY_OBJECT_CONTENT_TYPE, <<"application/directory">>).


-define(IS_CONNECTION(C), is_record(C, cf_connection)).
-define(IS_CONTAINER(C), is_record(C, cf_container)).
-define(IS_OBJECT(O), is_record(O, cf_object)).

-record(cf_connection, {version :: string(),
auth_token :: string(),
storage_url :: string(),
cdn_management_url :: string()
}).

-record(cf_account_info, {bytes_used, container_count}). -record(cf_account_info, {bytes_used, container_count}).


-record(cf_container_query_args, {marker, limit}).
-record(cf_container_details, {name, bytes, count}). -record(cf_container_details, {name, bytes, count}).
-record(cf_container, {container_details :: #cf_container_details{},
container_path :: string(),
cdn_details :: [{atom(), term()}]
}).

-record(cf_container_query_args, {marker, limit}).
-record(cf_container_cdn_config, {ttl = 86400, user_agent_acl, referrer_acl}). -record(cf_container_cdn_config, {ttl = 86400, user_agent_acl, referrer_acl}).


-record(cf_object_query_args, {marker, limit, prefix, path}).
-record(cf_object_details, {name, bytes = 0, last_modified, content_type, etag}). -record(cf_object_details, {name, bytes = 0, last_modified, content_type, etag}).
-record(cf_object, {container :: #cf_container{},
object_details :: #cf_object_details{},
object_path :: string(),
http_headers :: [{string(), string()}]
}).

-record(cf_object_query_args, {marker, limit, prefix, path}).


4 changes: 2 additions & 2 deletions rebar.config
@@ -1,7 +1,7 @@
{erl_opts, [{src_dirs, ["src", "lib"]}]}. {erl_opts, [debug_info, {src_dirs, ["src", "lib"]}]}.


{edoc_opts, [{application, ["cferl"]}]}. {edoc_opts, [{application, ["cferl"]}]}.


{deps_dir, ["deps"]}. {deps_dir, ["deps"]}.


{deps, [{ibrowse, ".*", {git, "git://github.com/cmullaparthi/ibrowse.git", {branch, master}}}]}. {deps, [{ibrowse, ".*", {git, "git://github.com/cmullaparthi/ibrowse.git", {tag, "v4.0.1"}}}]}.
2 changes: 1 addition & 1 deletion src/cferl.app.src
@@ -1,7 +1,7 @@
{application, {application,
cferl, cferl,
[{description, "Rackspace Cloud Files client application"}, [{description, "Rackspace Cloud Files client application"},
{vsn, "1.3.1"}, {vsn, "2.0.0"},
{modules, [ {modules, [
cferl, cferl,
cferl_connection, cferl_connection,
Expand Down
56 changes: 27 additions & 29 deletions src/cferl.erl
Expand Up @@ -5,8 +5,6 @@
%%% See LICENSE for license information. %%% See LICENSE for license information.
%%% Copyright (c) 2010 David Dossot %%% Copyright (c) 2010 David Dossot
%%% %%%
%%% @type cferl_connection() = term(). Reference to the cferl_connection parameterized module.
%%% @type cferl_error() = {error, not_found} | {error, unauthorized} | {error, {unexpected_response, Other}}.


-module(cferl). -module(cferl).
-author('David Dossot <david@dossot.net>'). -author('David Dossot <david@dossot.net>').
Expand All @@ -15,30 +13,28 @@
-export([connect/2, connect/3]). -export([connect/2, connect/3]).
-define(APPLICATION, cferl). -define(APPLICATION, cferl).


%% @doc Authenticate and open connection. -type(username() :: string() | binary()).
%% @spec connect(Username, ApiKey) -> {ok, CloudFiles} | Error -type(api_key() :: string() | binary()).
%% Username = string() | binary() -type(auth_service() :: string() | binary() | us | uk).
%% ApiKey = string() | binary()
%% CloudFiles = cferl_connection() %% @doc Authenticate and open connection (US).
%% Error = cferl_error() -spec connect(username(), api_key()) -> {ok, #cf_connection{}} | cferl_lib:cferl_error().
connect(Username, ApiKey) when is_binary(Username), is_binary(ApiKey) -> connect(Username, ApiKey) when is_binary(Username), is_binary(ApiKey) ->
connect(binary_to_list(Username), connect(binary_to_list(Username),
binary_to_list(ApiKey)); binary_to_list(ApiKey));
connect(Username, ApiKey) when is_list(Username), is_list(ApiKey) -> connect(Username, ApiKey) when is_list(Username), is_list(ApiKey) ->
AuthUrl = "https://" ++ ?API_BASE_URL ++ ":443" ++ ?VERSION_PATH, connect(Username, ApiKey, us).
connect(Username, ApiKey, AuthUrl).


%% @doc Authenticate and open connection. %% @doc Authenticate and open connection.
%% @spec connect(Username, ApiKey, AuthUrl) -> {ok, CloudFiles} | Error -spec connect(username(), api_key(), auth_service()) -> {ok, #cf_connection{}} | cferl_lib:cferl_error().
%% Username = string() | binary() connect(Username, ApiKey, us) ->
%% ApiKey = string() | binary() AuthUrl = "https://" ++ ?US_API_BASE_URL ++ ":443" ++ ?VERSION_PATH,
%% AuthUrl = string() | binary() connect(Username, ApiKey, AuthUrl);
%% CloudFiles = cferl_connection() connect(Username, ApiKey, uk) ->
%% Error = cferl_error() AuthUrl = "https://" ++ ?UK_API_BASE_URL ++ ":443" ++ ?VERSION_PATH,
connect(Username, ApiKey, AuthUrl);
connect(Username, ApiKey, AuthUrl) when is_binary(Username), is_binary(ApiKey), is_binary(AuthUrl) -> connect(Username, ApiKey, AuthUrl) when is_binary(Username), is_binary(ApiKey), is_binary(AuthUrl) ->
connect(binary_to_list(Username), connect(binary_to_list(Username), binary_to_list(ApiKey), binary_to_list(AuthUrl));
binary_to_list(ApiKey),
binary_to_list(AuthUrl));
connect(Username, ApiKey, AuthUrl) when is_list(Username), is_list(ApiKey), is_list(AuthUrl) -> connect(Username, ApiKey, AuthUrl) when is_list(Username), is_list(ApiKey), is_list(AuthUrl) ->
ensure_started(), ensure_started(),


Expand All @@ -53,16 +49,18 @@ connect(Username, ApiKey, AuthUrl) when is_list(Username), is_list(ApiKey), is_l


%% @doc Ensure started for the sake of verifying that required applications are running. %% @doc Ensure started for the sake of verifying that required applications are running.
ensure_started() -> ensure_started() ->
ensure_started( ensure_started(?APPLICATION).
lists:any(fun({Application, _Description, _Vsn}) ->
Application == ?APPLICATION ensure_started(App) ->
end, ensure_started(App, application:start(App)).
application:which_applications())).

ensure_started(_App, ok ) -> ok;
ensure_started(true) -> ensure_started(_App, {error, {already_started, _App}}) -> ok;
ok; ensure_started(App, {error, {not_started, Dep}}) ->
ensure_started(false) -> ok = ensure_started(Dep),
application:start(?APPLICATION). ensure_started(App);
ensure_started(App, {error, Reason}) ->
erlang:error({app_start_failed, App, Reason}).


connect_result({ok, "204", ResponseHeaders, _ResponseBody}) -> connect_result({ok, "204", ResponseHeaders, _ResponseBody}) ->
{ok, Version} = application:get_key(?APPLICATION, vsn), {ok, Version} = application:get_key(?APPLICATION, vsn),
Expand Down

0 comments on commit 45b897a

Please sign in to comment.