Skip to content

Commit

Permalink
Merge pull request #4 from gdubost/feature/19954
Browse files Browse the repository at this point in the history
[FEATURE#19954] Adaptation aux routes sur conversation
  • Loading branch information
SparSio committed Jul 2, 2015
2 parents 40ae361 + e1bf4c0 commit f40b4a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ConversationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function findByQueryString($query, $from = 0, $size = 99999)
$response = $this->fireRequest($request, $this->app["cookies.authenticator"]);

$conversations_array = [];
$conversations = $response["conversations"]["hits"];
$conversations = $response["hits"];
foreach ($conversations as $conversation) {
$conversation_item = new Conversation();
$conversation_item->fromArray($conversation);
Expand Down
25 changes: 25 additions & 0 deletions src/DumbMethodsProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public function connect(Application $app)

$controllers = $app["controllers_factory"];

//Dumb proxy for stats and search
$controllers->get("/conversations/search", [$this, "conversationSearch"]);
$controllers->get("/conversations/stats", [$this, "conversationStats"]);

//Dumb proxy for messages
$controllers->get("/conversations/{conversation}/messages/{message}", [$this, "loadMessage"]);
$controllers->get("/conversations/{conversation}/messages", [$this, "loadConversationMessages"]);
Expand All @@ -40,6 +44,16 @@ public function connect(Application $app)
return $controllers;
}

public function conversationSearch(Application $app, Request $req)
{
return $this->getRequestWithBody($app, $req, "/conversations");
}

public function conversationStats(Application $app, Request $req)
{
return $this->getRequestWithBody($app, $req, "/conversations");
}

public function loadMessage(Application $app, Request $req)
{
return $this->doProxyWithoutDatas($app, $req);
Expand Down Expand Up @@ -114,6 +128,17 @@ public function doProxyWithDatas(Application $app, Request $req)
return $response;
}

public function getRequestWithBody(Application $app, Request $req, $remove_prefix = "")
{
$path_info = $req->getPathInfo();
$path_info = str_replace($remove_prefix, "", $path_info);

$request = $app["conversation_proxy"]
->createRequest("GET", "{$path_info}?{$req->getQueryString()}", [], $req->request->all());
$response = self::requestWithJsonResponse($request, $app, $req->cookies->get("authenticator"));
return $response;
}

public static function requestWithJsonResponse(GuzzleRequest $request, Application $app, $cookie)
{
try {
Expand Down

0 comments on commit f40b4a4

Please sign in to comment.