Permalink
Browse files

removed paramterized modules

  • Loading branch information...
1 parent 3e97f30 commit 45b897a47b0de5ea7c5660b6ce59e90b56cc20b5 @tholschuh tholschuh committed Mar 15, 2013
Showing with 474 additions and 380 deletions.
  1. +25 −3 include/cferl.hrl
  2. +2 −2 rebar.config
  3. +1 −1 src/cferl.app.src
  4. +27 −29 src/cferl.erl
  5. +107 −81 src/cferl_connection.erl
  6. +133 −106 src/cferl_container.erl
  7. +6 −0 src/cferl_lib.erl
  8. +104 −89 src/cferl_object.erl
  9. +69 −69 test/cferl_integration_tests.erl
View
@@ -6,19 +6,41 @@
%%% 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(DEFAULT_REQUEST_TIMEOUT, 30000).
-define(OBJECT_META_HEADER_PREFIX, "X-Object-Meta-").
-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_container_query_args, {marker, limit}).
-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_object_query_args, {marker, limit, prefix, path}).
-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}).
View
@@ -1,7 +1,7 @@
-{erl_opts, [{src_dirs, ["src", "lib"]}]}.
+{erl_opts, [debug_info, {src_dirs, ["src", "lib"]}]}.
{edoc_opts, [{application, ["cferl"]}]}.
{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"}}}]}.
View
@@ -1,7 +1,7 @@
{application,
cferl,
[{description, "Rackspace Cloud Files client application"},
- {vsn, "1.3.1"},
+ {vsn, "2.0.0"},
{modules, [
cferl,
cferl_connection,
View
@@ -5,8 +5,6 @@
%%% See LICENSE for license information.
%%% 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).
-author('David Dossot <david@dossot.net>').
@@ -15,30 +13,28 @@
-export([connect/2, connect/3]).
-define(APPLICATION, cferl).
-%% @doc Authenticate and open connection.
-%% @spec connect(Username, ApiKey) -> {ok, CloudFiles} | Error
-%% Username = string() | binary()
-%% ApiKey = string() | binary()
-%% CloudFiles = cferl_connection()
-%% Error = cferl_error()
+-type(username() :: string() | binary()).
+-type(api_key() :: string() | binary()).
+-type(auth_service() :: string() | binary() | us | uk).
+
+%% @doc Authenticate and open connection (US).
+-spec connect(username(), api_key()) -> {ok, #cf_connection{}} | cferl_lib:cferl_error().
connect(Username, ApiKey) when is_binary(Username), is_binary(ApiKey) ->
connect(binary_to_list(Username),
binary_to_list(ApiKey));
connect(Username, ApiKey) when is_list(Username), is_list(ApiKey) ->
- AuthUrl = "https://" ++ ?API_BASE_URL ++ ":443" ++ ?VERSION_PATH,
- connect(Username, ApiKey, AuthUrl).
+ connect(Username, ApiKey, us).
%% @doc Authenticate and open connection.
-%% @spec connect(Username, ApiKey, AuthUrl) -> {ok, CloudFiles} | Error
-%% Username = string() | binary()
-%% ApiKey = string() | binary()
-%% AuthUrl = string() | binary()
-%% CloudFiles = cferl_connection()
-%% Error = cferl_error()
+-spec connect(username(), api_key(), auth_service()) -> {ok, #cf_connection{}} | cferl_lib:cferl_error().
+connect(Username, ApiKey, us) ->
+ AuthUrl = "https://" ++ ?US_API_BASE_URL ++ ":443" ++ ?VERSION_PATH,
+ connect(Username, ApiKey, AuthUrl);
+connect(Username, ApiKey, uk) ->
+ 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(binary_to_list(Username),
- binary_to_list(ApiKey),
- binary_to_list(AuthUrl));
+ connect(binary_to_list(Username), binary_to_list(ApiKey), binary_to_list(AuthUrl));
connect(Username, ApiKey, AuthUrl) when is_list(Username), is_list(ApiKey), is_list(AuthUrl) ->
ensure_started(),
@@ -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.
ensure_started() ->
- ensure_started(
- lists:any(fun({Application, _Description, _Vsn}) ->
- Application == ?APPLICATION
- end,
- application:which_applications())).
-
-ensure_started(true) ->
- ok;
-ensure_started(false) ->
- application:start(?APPLICATION).
+ ensure_started(?APPLICATION).
+
+ensure_started(App) ->
+ ensure_started(App, application:start(App)).
+
+ensure_started(_App, ok ) -> ok;
+ensure_started(_App, {error, {already_started, _App}}) -> ok;
+ensure_started(App, {error, {not_started, Dep}}) ->
+ ok = ensure_started(Dep),
+ ensure_started(App);
+ensure_started(App, {error, Reason}) ->
+ erlang:error({app_start_failed, App, Reason}).
connect_result({ok, "204", ResponseHeaders, _ResponseBody}) ->
{ok, Version} = application:get_key(?APPLICATION, vsn),
Oops, something went wrong.

0 comments on commit 45b897a

Please sign in to comment.