<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>elib/rfc4627/rfc4627.erl</filename>
    </added>
    <added>
      <filename>elib/twitter_client/twitter_client.erl</filename>
    </added>
    <added>
      <filename>elib/twitter_client/twitter_client.hrl</filename>
    </added>
    <added>
      <filename>src/components/stats_controller.erl</filename>
    </added>
    <added>
      <filename>src/components/stats_view.et</filename>
    </added>
    <added>
      <filename>src/twoorl_stats.erl</filename>
    </added>
    <added>
      <filename>src/twoorl_twitter.erl</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -6,3 +6,5 @@ Mnesia.nonode@nohost/
 #*#
 .#*
 .DS_Store
+twoorl.mnesia/
+twoorl_stats</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,6 @@
 {&quot;src/twoorl.erl&quot;, [{outdir, &quot;./ebin&quot;}]}.
+{&quot;src/twoorl_sup.erl&quot;, [{outdir, &quot;./ebin&quot;}]}.
+{&quot;src/twoorl_server.erl&quot;, [{outdir, &quot;./ebin&quot;}]}.
 {&quot;src/twoorl_util.erl&quot;, [{outdir, &quot;./ebin&quot;}]}.
-{&quot;elib/*.erl&quot;, [{outdir, &quot;./ebin&quot;}]}.
\ No newline at end of file
+{&quot;elib/rfc4627/*&quot;, [{outdir, &quot;./ebin&quot;}]}.
+{&quot;elib/twitter_client/*&quot;, [{outdir, &quot;./ebin&quot;}]}.
\ No newline at end of file</diff>
      <filename>Emakefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 all: code
 
 code: clean
-	erl -s make all load -run twoorl init_mysql -run twoorl compile -s init stop
+	erl -s make all load -s init stop
 
 clean:
 	rm -fv ebin/*.beam twoorl.rel twoorl.script twoorl.boot erl_crash.dump *.log *.access</diff>
      <filename>Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -10,3 +10,12 @@ To run Twoorl follow the following steps:
 
 Cheers!
 Yariv
+
+To run in embedded mode:
+
+$ make clean &amp;&amp; make
+$ erl -sname twoorlapp -setcookie twoorl -mnesia dir &quot;'twoorl.mnesia'&quot; -yaws embedded true -pa ebin -boot start_sasl
+1&gt; [application:start(X) || X &lt;- [inets, crypto, mnesia, twoorl]].
+[ok, ok, ok, ok]
+
+# Nick Gerakines</diff>
      <filename>README.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,14 +1,19 @@
 {application, twoorl, [
   {description, &quot;Twoorl is an open-source Twitter clone.&quot;},
   {vsn, &quot;0.3&quot;},
-  {modules, [
-    twoorl,
-    twoorl_server,
-    twoorl_sup
-  ]},
+  {modules, [twoorl, twoorl_server, twoorl_sup]},
   {registered, [twoorl]},
-  {env, []},
   {applications, [kernel, stdlib, sasl, crypto, inets, mnesia]},
   {mod, {twoorl, []}},
-  {start_phases, []}
+  {env, [
+    {dbconns, [
+        {&quot;localhost&quot;, &quot;root&quot;, &quot;password&quot;, &quot;twoorl&quot;, 3}
+    ]},
+    {tables, [session]}
+  ]},
+  {start_phases, [
+    {mysql, []},
+    {mnesia, []},
+    {compile, []}
+  ]}
 ]}.</diff>
      <filename>ebin/twoorl.app</filename>
    </modified>
    <modified>
      <diff>@@ -63,23 +63,18 @@ send(A) -&gt;
 					   Usr:gravatar_enabled()},
 					  {twitter_status, TwitterStatus}]),
 		      Msg1 = Msg:save(),
+		      spawn(twoorl_stats, call, [{record, twoot}]),
 
 		      if TwitterEnabled andalso RecipientNames == [] -&gt;
-			      %% yey concurrency
-			      spawn(
-				fun() -&gt;
-					send_tweet(Usr, Msg1)
-				end);
+			      spawn(twoorl_twitter, send_tweet, [Usr, Msg1]); %% yey concurrency
 			 true -&gt;
 			      ok
 		      end,
 
 		      %% yey concurrency
-		      spawn(
-			fun() -&gt;
-				save_replies(Msg1:id(), RecipientNames)
-			end),
-		      
+              RecipientIds =  usr:find({username, in, lists:usort([Name || Name &lt;- RecipientNames])}),
+		      spawn(reply, save_replies, [Msg1:id(), RecipientIds]),
+
 		      case proplists:get_value(&quot;get_html&quot;, Params) of
 			  &quot;true&quot; -&gt;
 			      Msg2 = msg:created_on(
@@ -95,14 +90,6 @@ send(A) -&gt;
 	      end
       end).
 
-save_replies(MsgId, RecipientNames) -&gt;
-    RecipientNames1 = [Name || Name &lt;- RecipientNames],
-    Recipients = 
-	usr:find({username, in, lists:usort(RecipientNames1)}),
-    RecipientIds =
-	[Recipient:id() || Recipient &lt;- Recipients],
-    reply:save_replies(MsgId, RecipientIds).
-
 follow(A) -&gt;
     twoorl_util:auth(
       A,
@@ -162,24 +149,3 @@ follow(A) -&gt;
 		      exit(Errs2)
 	      end
       end).
-
-	      
-send_tweet(Usr, Msg) -&gt;
-    Username = Usr:twitter_username(),
-    Password = Usr:twitter_password(),
-    
-    Res = twitter:update(Username, Password, Msg:body_raw()),
-
-    UpdateFun = fun(Status) -&gt;
-			msg:update([{twitter_status, Status}],
-				   {id,'=',Msg:id()})
-		end,
-    case Res of
-	{ok, {{_Protocol, 200, _},_Headers, _Body}} -&gt;
-	    UpdateFun(?TWITTER_SENT_OK);
-	_ -&gt;
-	    ?Warn(&quot;error sending tweet ~p ~p&quot;, [Msg:id(), Res]),
-	    UpdateFun(?TWITTER_SENT_ERR)
-    end.
-
-    </diff>
      <filename>src/components/api_controller.erl</filename>
    </modified>
    <modified>
      <diff>@@ -54,7 +54,8 @@ index(A) -&gt;
 			Errs
 		end,
 	    if Errs1 == [] -&gt;
-		    do_login(A, Usr);
+		    %% spawn(twoorl_stats, call, [{record, site_login}]),
+		    do_login(Usr);
 	       true -&gt;
 		    [?Data(A, undefined),
 		     {ewc, ui_msgs, [A, Errs1]}]</diff>
      <filename>src/components/login_controller.erl</filename>
    </modified>
    <modified>
      <diff>@@ -42,6 +42,7 @@ index(A) -&gt;
 	       true -&gt;
 		    %% todo set cookie
 		    Usr = register_usr(Username, Email, Password),
+		    spawn(twoorl_stats, call, [{record, registration}]),
 		    login_controller:do_login(Usr)
 	    end;
 	_ -&gt;</diff>
      <filename>src/components/register_controller.erl</filename>
    </modified>
    <modified>
      <diff>@@ -21,11 +21,7 @@
 -module(reply).
 -compile(export_all).
 
-
-save_replies(MsgId, RecipientIds) -&gt;    
-    Replies =
-	[reply:new_with(
-	   [{usr_id, RecipientId},
-	    {msg_id, MsgId}]) || RecipientId &lt;-
-				     RecipientIds],
+save_replies(MsgId, Recipients) -&gt;
+    Replies = [reply:new_with([{usr_id, Recipient:id()}, {msg_id, MsgId}])
+	       || Recipient &lt;- Recipients],
     reply:insert(Replies).</diff>
      <filename>src/components/reply.erl</filename>
    </modified>
    <modified>
      <diff>@@ -78,7 +78,7 @@ get_validation_fun(true) -&gt;
 		    FName = case Field of
 				&quot;twitter_username&quot; -&gt;
 				    &quot;Twitter username&quot;;
-					&quot;twitter_password&quot; -&gt;
+				&quot;twitter_password&quot; -&gt;
 				    &quot;Twitter password&quot;
 			    end,
 		    {error, {missing_field, FName}};
@@ -91,24 +91,14 @@ get_validation_fun(_) -&gt;
 	    ok
     end.
 
-verify_twitter_credentials(TwitterEnabled, TwitterUsername, TwitterPassword) -&gt;
-    if (TwitterEnabled andalso not (TwitterUsername == [])
-	andalso not (TwitterPassword == [])) -&gt;
-	    case twitter:verify_credentials(
-		   TwitterUsername, TwitterPassword) of
-		ok -&gt;
-		    [];
-		{error, unauthorized} -&gt;
-		    [twitter_unauthorized];
-		{error, Err} -&gt;
-		    ?Error(&quot;twitter authorization error: ~p ~p ~p&quot;,
-			   [TwitterUsername, TwitterPassword,
-			    Err]),
-		    [twitter_authorization_error]
-	    end;
-       true -&gt;
-	    []
-    end.
+verify_twitter_credentials(_, [], _) -&gt; [];
+verify_twitter_credentials(_, _, []) -&gt; [];
+verify_twitter_credentials(1, Username, Password) -&gt;
+    case twitter_client:account_verify_credentials(Username, Password, []) of
+        true -&gt; [];
+        false -&gt; [twitter_unauthorized]
+    end;
+verify_twitter_credentials(_, _, _) -&gt; [].
 
 update_settings(Usr, TwitterUsername, TwitterPassword, TwitterEnabled,
 	  GravatarEnabled, Background, Language) -&gt;</diff>
      <filename>src/components/settings_controller.erl</filename>
    </modified>
    <modified>
      <diff>@@ -26,13 +26,54 @@
 start(_Type, _Args) -&gt;
     twoorl_sup:start_link([]).
 
-start() -&gt;
-    application:start(inets),
-    init_mnesia(),
-    TablesInfo = [{session, [{attributes, record_info(fields, session)}]}],
-    create_mnesia_tables(TablesInfo),
-    init_mysql(),
-    compile().
+start_phase(mysql, _, _) -&gt;
+    {ok, DBConfig} = application:get_env(twoorl, dbconns),
+    [begin
+        mysql_connect(PoolSize, Hostname, User, Password, Database, true)
+    end || {Hostname, User, Password, Database, PoolSize} &lt;- DBConfig],
+    ok;
+
+start_phase(compile, _, _) -&gt;
+    twoorl:compile(),
+    ok;
+
+%% Having the mnesia store on a separate but connected node with a module
+%% to handle its maintenance would move a lot of this foo out of the
+%% application stack. Eventually that really needs to happen. -- nkg
+start_phase(mnesia, _, _) -&gt;
+    %% Mnesia should have been started already, because of that the schema
+    %% is in memory if the schema doesn't already exist on disc. If so we
+    %% change the type so that it writes to the mnesia dir we set. -- nkg
+    case mnesia:table_info(schema, storage_type) of
+        ram_copies -&gt; 
+            mnesia:change_table_copy_type(schema, node(), disc_copies);
+        _ -&gt;
+            ok
+    end,
+    ExistingTables = mnesia:system_info(tables) -- [schema],
+    {ok, Tables} = application:get_env(twoorl, tables),
+    [begin
+        create_table(session)
+    end || Table &lt;- Tables, not lists:member(Table, ExistingTables)],
+    ok.
+
+create_table(session) -&gt;
+    mnesia:create_table(session, [{attributes, record_info(fields, session)}]),
+    ok.
+
+mysql_connect(0, _, _, _, _, _) -&gt; ok;
+mysql_connect(PoolSize, Hostname, User, Password, Database, true) -&gt;
+    erlydb:start(mysql, [
+        {hostname, Hostname},
+        {username, User},
+        {password, Password},
+        {database, Database},
+        {logfun, fun twoorl_util:log/4}
+    ]),
+	mysql_connect(PoolSize - 1, Hostname, User, Password, Database, false);
+mysql_connect(PoolSize, Hostname, User, Password, Database, false) -&gt;
+    mysql:connect(erlydb_mysql, Hostname, undefined, User, Password, Database, true),
+    mysql_connect(PoolSize - 1, Hostname, User, Password, Database, false).
 
 compile() -&gt;
     compile([]).
@@ -47,12 +88,25 @@ compile(Opts) -&gt;
     erlyweb:compile(compile_dir(default),
 		    [{erlydb_driver, mysql}, {erlydb_timeout, 20000} | Opts]).
 
+compile_dir(auto) -&gt;
+    {ok, CWD} = file:get_cwd(), CWD;
+compile_dir(default) -&gt;
+    ?APP_PATH;
+compile_dir(appconfig) -&gt;
+    {ok, CDir} = application:get_env(twoorl, compile_dir),
+    CDir;
 compile_dir(Dir) -&gt;
-    case Dir of
-        auto -&gt; {ok, CWD} = file:get_cwd(), CWD;
-        default -&gt; ?APP_PATH;
-        _ -&gt; Dir
-    end.
+    Dir.
+
+%% --- The rest of these functions will be deprecated --- %%
+
+start() -&gt;
+    application:start(inets),
+    init_mnesia(),
+    TablesInfo = [{session, [{attributes, record_info(fields, session)}]}],
+    create_mnesia_tables(TablesInfo),
+    init_mysql(),
+    compile().
 
 init_mnesia() -&gt;
     ?L(&quot;creating schema&quot;),
@@ -98,7 +152,6 @@ create_table(Table, Def) -&gt;
             exit(Err2)
     end.
 
-
 init_mysql() -&gt;
     erlydb:start(mysql,
 		 [{hostname, ?DB_HOSTNAME},</diff>
      <filename>src/twoorl.erl</filename>
    </modified>
    <modified>
      <diff>@@ -28,5 +28,5 @@ start_link(Args) -&gt;
 
 init(Args) -&gt;
     {ok, {{one_for_one, 10, 10}, [
-        {twoorl_yaws, {twoorl_server, start_link, [Args]}, permanent, 2000, worker, [twoorl_server]}
+        {twoorl_yaws, {twoorl_server, start_link, [Args]}, permanent, 20000, worker, [twoorl_server]}
     ]}}.</diff>
      <filename>src/twoorl_sup.erl</filename>
    </modified>
    <modified>
      <diff>@@ -376,7 +376,7 @@ get_bundle(A) -&gt;
 	    Usr -&gt;
 		Lang = Usr:language(),
 		case lists:keysearch(Lang, 1, bundles()) of
-		    none -&gt;
+		    false -&gt;
 			?Warn(&quot;undefined language: ~p ~p&quot;, 
 			      [Usr:username(), Lang]),
 			twoorl_eng;</diff>
      <filename>src/twoorl_util.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>fe7f92ea1eff9de6f22a50880fdbac1cb7768521</id>
    </parent>
  </parents>
  <author>
    <name>Yariv Sadan</name>
    <email>yarivvv@gmail.com</email>
  </author>
  <url>http://github.com/yariv/twoorl/commit/ede429e2dab0ac2c552349d5220fbc8f08510b52</url>
  <id>ede429e2dab0ac2c552349d5220fbc8f08510b52</id>
  <committed-date>2008-06-17T20:58:12-07:00</committed-date>
  <authored-date>2008-06-17T20:58:12-07:00</authored-date>
  <message>Merge branch 'my-ngerakines'

Conflicts:

	.gitignore
	src/components/login_controller.erl
	src/components/settings_controller.erl
	src/twitter.erl</message>
  <tree>a3d71b1a0331e5abb62bdc2298c0f94ce5c7b0b8</tree>
  <committer>
    <name>Yariv Sadan</name>
    <email>yarivvv@gmail.com</email>
  </committer>
</commit>
