Skip to content
This repository has been archived by the owner. It is now read-only.
Browse files
Add Google contacts example.
  • Loading branch information
Tim Fletcher committed Nov 7, 2008
1 parent 60c906f commit 44de303f49175d0dafe4a28e45b30d2f4194581c
Showing 2 changed files with 46 additions and 4 deletions.
@@ -2,7 +2,7 @@ SOURCE_FILES := $(wildcard src/*.erl)

ERLC := erlc -W +debug_info -o ebin

ERL := erl -pa ebin -pa ../erlang-fmt/ebin -s crypto
ERL := erl -pa ebin -pa ../erlang-fmt/ebin -s crypto -s inets -s ssl

all: beam_files
@@ -19,20 +19,26 @@ ebin/oauth_unit.beam: test/oauth_unit.erl
ebin/oauth_termie.beam: test/oauth_termie.erl
$(ERLC) test/oauth_termie.erl

ebin/oauth_google.beam: test/oauth_google.erl
$(ERLC) test/oauth_google.erl

rm -rf ebin/*.beam erl_crash.dump

test: beam_files ebin/oauth_unit.beam
@$(ERL) -noshell -s oauth_unit test -s init stop

termie_hmac: beam_files ebin/oauth_termie.beam
@$(ERL) -noshell -s inets -s oauth_termie test_hmac -s init stop
@$(ERL) -noshell -s oauth_termie test_hmac -s init stop

termie_rsa: beam_files ebin/oauth_termie.beam
@$(ERL) -noshell -s inets -s oauth_termie test_rsa -s init stop
@$(ERL) -noshell -s oauth_termie test_rsa -s init stop

google: beam_files ebin/oauth_google.beam
@$(ERL) -noshell -s oauth_google test -s init stop

shell: beam_files
@$(ERL) -s inets

dialyzer --no_check_plt --src -c src/
@@ -0,0 +1,36 @@



% cf.

test() ->
SignatureMethod = {"RSA-SHA1", "test/rsa_private_key.pem"},
get_request_token(oauth_consumer:new("", "x", SignatureMethod)).

get_request_token(Consumer) ->
RequestTokenURL = "",
Params = [{scope, ""}],
Response = oauth:get(RequestTokenURL, Consumer, Params),
authorize_token(Consumer, tee("RequestTokenPair: ", oauth_token_pair:new(Response))).

authorize_token(Consumer, RequestTokenPair={RequestToken, _}) ->
AuthorizeTokenURL = "",
Params = [{oauth_token, RequestToken}],
Prompt = fmt:sprintf("Please authorize at %s?%s~n", [AuthorizeTokenURL, oauth_params:to_string(Params)]),
get_access_token(Consumer, RequestTokenPair).

get_access_token(Consumer, RequestTokenPair) ->
AccessTokenURL = "",
AccessTokenPair = tee("AccessTokenPair: ", oauth_token_pair:new(oauth:get(AccessTokenURL, Consumer, RequestTokenPair))),
{ok, {_, _, Data}} = oauth:get("", Consumer, AccessTokenPair),
{XML, _} = xmerl_scan:string(Data),
Titles = [Node#xmlText.value || Node <- xmerl_xpath:string("//feed/entry/title/text()", XML)],
lists:foreach(fun(Title) -> io:format("~s~n", [Title]) end, Titles).

tee(Tag, X) ->
io:format("~s: ~p~n~n", [Tag, X]), X.

0 comments on commit 44de303

Please sign in to comment.