Skip to content

Commit

Permalink
[TASK|FUNCTION|IMPROVE] Save Keywords page Change - Access the email …
Browse files Browse the repository at this point in the history
…server throgh http API

Resolves: #34
Related: #35
Releases: 2.1.x
  • Loading branch information
dud3 committed Nov 24, 2014
1 parent 4584d56 commit de2434b
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/config/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
|
*/

'driver' => 'smtp',
'driver' => 'mandrill',

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
),

'mandrill' => array(
'secret' => '',
'secret' => 'Y43YmTMvJAFJTg8OFKJFBA',
),

'stripe' => array(
Expand Down
37 changes: 32 additions & 5 deletions app/controllers/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,36 @@
class ListController extends internalCtrl {

public $user;
public $ketwords;
public $lists;
public $keywords;
public $emails;

/**
* [__construct description]
*/
public function __construct(EloquentKeywordsRepositoryInterface $keywords) {
public function __construct(EloquentListRepositoryInterface $lists, EloquentKeywordsRepositoryInterface $keywords, EloquentEmailsRepository $emails) {
$this->lists = $lists;
$this->keywords = $keywords;
$this->emails = $emails;
}


/**
* [view_emails description]
* view keywords list.
* @return [type] [description]
*/
public function view_k_list() {

$view = View::make('list.keywords');

return $view;
}

/**
* view emails list.
* @return [type] [description]
*/
public function view_e_list() {
$view = View::make('list.emails');
return $view;
}

/**
Expand All @@ -42,4 +52,21 @@ public function get_all_keywords() {
return Response::json(['keywords' => $this->keywords->get_all()], 200);
}

/**
* Create keywords list
* @return [array] [array of objects]
*/
public function create_keywords_list() {

$input = Input::all();
$ret = $this->lists->create_keywords_list($input);

if(!$ret->error) {
$ret = Response::json(["ketwordsList" => $ret], 200);
} else {
$ret = Response::json([$ret->error], 401);
}

}

}
17 changes: 8 additions & 9 deletions app/repositories/EloquentKeywordsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function get_by_id($id = null) {
*/
public function store($data = null) {

$ret = [];

try {

if($data != null) {
Expand All @@ -74,7 +76,8 @@ public function store($data = null) {

if(self::validate($data)) {

return keywords_list::create($data);
$ret = keywords_list::create($data);
return $ret;

} else {
throw new RuntimeException("Error Processing Request", 1);
Expand Down Expand Up @@ -114,15 +117,11 @@ public function update($data = null) {

if(!empty($data)) {

if(self::validate($data)) {

$k = keywords_list::fill($data);
$k->save();
return $k;

} else {
throw new RuntimeException("Error Processing Request", 1);
}
$k = keywords_list::fill($data);
$k->save();
$k->error = false;
return $k;

} else {
throw new RuntimeException("Error, The array can not be empty", 0.2);
Expand Down
70 changes: 51 additions & 19 deletions app/repositories/EloquentListRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;


class EloquentListRepository implements EloquentListRepositoryInterface {

protected $main_sql = null;
protected $list_type;

protected $keywords;
protected $emails;

/**
* Main Constructor.
*/
public function __construct() {

public function __construct(EloquentKeywordsRepositoryInterface $keywords, EloquentEmailsRepository $emails) {
$this->keywords = $keywords;
$this->emails = $emails;
}

/**
Expand All @@ -29,44 +31,74 @@ public function __call_list($type) {

switch ($this->list_type) {

case 'get_list_by_keyword':
$this->get_list_by_keyword();
case 'get_email_list':
$this->get_email_list();
break;

case 'get_list_by_email':
$this->get_list_by_email();
case 'get_keyword_list':
$this->get_keyword_list();
break;

}

}


/**
* Main query gues here
* Get list by keywords.
* @return [type] [description]
*/
public function mainQuery() {

public function get_email_list() {
return $this->keywords->get_all();
}


/**
* Get list by keywords.
* Get list by emails.
* @return [type] [description]
*/
public function get_list_by_keyword() {
public function get_keyword_list() {

}


/**
* Get list by emails.
* Create Keyword list.
* @return [type] [description]
*/
public function get_list_by_email() {
public function create_keywords_list($data) {

}
$ret = [];

try {

if($data != null) {

if(!empty($data)) {

$keywords = $this->keywords->store($data["keywords"]);
$recipients = $this->emails->store($data["recipients"]);

$ret = ["id" => $keywords['id'], "keywords" => $keywords["keywords"], "email" => $recipients["emails"]];
return $ret;

} else {
throw new RuntimeException("Error, The array can not be empty", 0.2);

}

} else {
throw new RuntimeException("Errorm The array can not be null", 0.1);
}

} catch(RuntimeException $e) {

$error = new stdClass();
$error->message = $e->getMessage();
$error->code = $e->getCode();
$error->error = true;

return $error;

}

}

}
17 changes: 9 additions & 8 deletions app/repositories/EloquentListRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ interface EloquentListRepositoryInterface {
* @return [type] [description]
*/
public function __call_list($type);

/**
* Main query gues here
* Get list by keywords.
* @return [type] [description]
*/
public function mainQuery();
public function get_email_list();

/**
* Get list by keywords.
* Get list by emails.
* @return [type] [description]
*/
public function get_list_by_keyword();
public function get_keyword_list();

/**
* Get list by emails.
* @return [type] [description]
* Create keywords list
* @param [array] $data [array of objects]
* @return [array] [array of objects]
*/
public function get_list_by_email();
public function create_keywords_list($data);

}
13 changes: 10 additions & 3 deletions app/repositories/EmailsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function sendMails($fwd_from = null, $test_user_only = false) {
FROM mails m
LEFT OUTER JOIN email_address_list e_a_l
LEFT JOIN email_address_list e_a_l
ON m.email_address_id = e_a_l.id
WHERE m.sent = 0
Expand Down Expand Up @@ -271,6 +271,15 @@ public function sendMails($fwd_from = null, $test_user_only = false) {
"message_body" => $message_body,
"message_subject" => $message_subject];

// Error handling
foreach ($data as $inputs) {
if($inputs == null || empty($inputs)) {
var_dump($data);
throw new Exception("Some data is missing", 1);
exit;
}
}

//
// Basically what we're doing here is that
// -> whenever we see a text that says 'Click here'
Expand Down Expand Up @@ -436,8 +445,6 @@ public function getEmailKeywords($data) {

if(count($k_arr_diff) == 0) {

var_dump("we're in...");

$e_add_list = email_address_list::where("keyword_id", "=", $k_id)->get()->toArray();

if($e_add_list !== null) {
Expand Down
5 changes: 4 additions & 1 deletion app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
Route::group(array('prefix' => 'api/v1'), function()
{

Route::get('getAllKeywords', 'ListController@get_all_keywords');
Route::group(array('prefix' => 'keywords'), function(){
Route::get('get', 'ListController@get_all_keywords');
Route::get('create', 'ListController@create_keywords_list');
});

Route::group(array('prefix' => 'emails'), function()
{
Expand Down
5 changes: 4 additions & 1 deletion app/start/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
$app['Cartalyst\Sentry\Sentry'] = $app['sentry'];

App::bind('UserRepositoryInterface', 'SentryUserRepository');

App::bind('EloquentListRepositoryInterface', 'EloquentListRepository');

App::bind('EmailsRepositoryInterface', 'EmailsRepository');
App::bind('EloquentListRepository', 'EloquentListRepositoryInterface');
App::bind('EloquentEmailsRepositoryInterface', 'EloquentEmailsRepository');
App::bind('EloquentKeywordsRepositoryInterface', 'EloquentKeywordsRepository');

Expand All @@ -30,6 +32,7 @@
app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/repositories',
app_path().'/database/seeds',

));
Expand Down
2 changes: 1 addition & 1 deletion app/views/__modals__/keywords_list/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" ng-click="close()"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Create Keyworkds List</h4>
<h4 class="modal-title text-muted" id="myModalLabel">Create Keyworkds List</h4>
</div>
<div class="modal-body">
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"require": {
"laravel/framework": "4.2.*",
"cartalyst/sentry": "2.1.*",
"tedivm/fetch": "0.5.*"
"tedivm/fetch": "0.5.*",
"guzzlehttp/guzzle": "~4.0"
},
"autoload": {
"classmap": [
Expand Down
2 changes: 1 addition & 1 deletion public/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ $provide.factory('MyHttpInterceptor', function ($q, $log) {
if(response.status == 200) {

// Only this routes for now
if(response.config.url == "/api/v1/getAllKeywords" || response.config.url == "/api/v1/emails/get_all") {
if(response.config.url == "/api/v1/keywords/get" || response.config.url == "/api/v1/emails/get_all") {

// Just a little awesomenes
// -> To let users know what's going on the background
Expand Down
Loading

0 comments on commit de2434b

Please sign in to comment.