Permalink
Browse files

create reference added

  • Loading branch information...
1 parent f2005c8 commit 4eb8a96edfe85c87b356e5912d729bb216d8a81d @0xAX 0xAX committed Sep 8, 2011
Showing with 52 additions and 1 deletion.
  1. +1 −0 README.markdown
  2. +18 −1 src/messages.erl
  3. +33 −0 src/reference.erl
View
@@ -13,6 +13,7 @@ The erlang-github-api project in very very early stage, it's only started to be
* define.hrl - github api urls
* gist.erl - github gist api -> progress 90% (implemented star, unstar, createe new gist, delete, get author, get content ...)
* messages.erl - make message to json format
+ * refs.erl - references -> progress 50% (implemented create ref)
* user.erl - github user api -> progress 90% (implmenented get user, get user data: email, login, bio, location and etc ...)
* utils.erl - utils functions
View
@@ -15,6 +15,7 @@
-export([make_add_email_message/1]).
-export([make_create_gist_message/4]).
-export([make_blob_message/2]).
+-export([make_ref_message/2]).
%%
%% API Functions
@@ -83,4 +84,20 @@ make_blob_message(_, []) ->
error;
make_blob_message(Content, Encoding) ->
"{" ++ "\"content\":" ++ "\"" ++ Content ++ "\"," ++
- "\"encoding\":" ++ "\"" ++ Encoding ++ "\"}".
+ "\"encoding\":" ++ "\"" ++ Encoding ++ "\"}".
+
+%%
+%% @spec make_ref_message(Ref, Sha) -> Json
+%% @doc - Create new ref
+%% @type - Ref = String()
+%% @type - Sha = String()
+%% @type - Json = String()
+%% @type - error = atom()
+%%
+make_ref_message([], _) ->
+ error;
+make_ref_message(_, []) ->
+ error;
+make_ref_message(Ref, Sha) ->
+ "{" ++ "\"ref\":" ++ "\"" ++ Ref ++ "\"," ++
+ "\"sha\":" ++ "\"" ++ Sha ++ "\"}".
View
@@ -0,0 +1,33 @@
+%%
+%%Copyright (c) <2011>, Kuleshov Alexander <kuleshovmail@gmail.com>
+%%All rights reserved.
+%%
+
+-module(reference).
+
+-export([create_ref/6]).
+
+-include("define.hrl").
+
+%%==============================================
+%% Git reference
+%%==============================================
+
+%%
+%% @spec create_ref(UserName, Password, User, Repo, Ref, Sha) -> ok
+%% @doc - Create ref
+%% @type - UserName = String()
+%% @type - Password = String()
+%% @type - User = String()
+%% @type - Repo = String()
+%% @type - Ref = String()
+%% @type - Sha = String()
+%% @type - ok = atom()
+%%
+create_ref(UserName, Password, User, Repo, Ref, Sha) ->
+ github:init(),
+ MakeMessage = messages:make_ref_message(Ref, Sha),
+ ibrowse:send_req(?REPOS ++ User ++ "/" ++ Repo ++ "/git/refs" , [], post, MakeMessage,
+ [{basic_auth, {UserName, Password}},{stream_to, self()},
+ {ssl_options, [{verify,verify_none}, {depth, 3}]}]),
+ ok.

0 comments on commit 4eb8a96

Please sign in to comment.