Skip to content

Commit e36597b

Browse files
feat(hackathon): Add Clockwork API functionality, still buggy though
1 parent 42d8fc5 commit e36597b

File tree

7 files changed

+186
-13
lines changed

7 files changed

+186
-13
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
use App\Http\Requests;
8+
use App\Http\Controllers\Controller;
9+
use MJErwin\Clockwork\ClockworkClient;
10+
use MJErwin\Clockwork\Message;
11+
12+
class ClockworkController extends Controller
13+
{
14+
15+
protected $apiKey;
16+
protected $client;
17+
18+
public function __construct()
19+
{
20+
$this->apiKey = env('CLOCKWORK_API_KEY');
21+
$this->client = new ClockworkClient($this->apiKey);
22+
$this->message = new Message();
23+
$this->message->setNumber('07700900123');
24+
$this->message->setContent('Check out this message!');
25+
26+
}
27+
/**
28+
* Return all data to the Clockwork API dashboard
29+
* @return mixed
30+
*/
31+
public function getPage()
32+
{
33+
return view('api.clockwork');
34+
}
35+
36+
/**
37+
* Send a Text Message
38+
* @param Request $request
39+
* @return string
40+
*/
41+
public function sendTextMessage(Request $request)
42+
{
43+
$this->validate($request, [
44+
'telephone' => 'required'
45+
]);
46+
47+
$number = $request->input('number');
48+
$message = 'Testing Clockwork SMS #LaravelHackathonStarter';
49+
50+
$response = $this->client->sendMessage($this->message);
51+
dd($response);
52+
53+
//return redirect()->back()->with('info','Your Message has been sent successfully');
54+
}
55+
}

app/Http/routes.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@
9898
'middleware' => ['auth']
9999
]);
100100

101+
Route::get('/api/clockwork', [
102+
'uses' => 'ClockworkController@getPage',
103+
'as' => 'api.clockwork',
104+
'middleware' => ['auth']
105+
]);
106+
107+
Route::post('/api/clockwork', [
108+
'uses' => 'ClockworkController@sendTextMessage',
109+
'middleware' => ['auth']
110+
]);
111+
101112
Route::post('/tweet/new', [
102113
'uses' => 'TwitterController@sendTweet',
103114
'as' => 'tweet.new',

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"thujohn/twitter": "^2.1",
1616
"metalmatze/lastfm-api-wrapper": "dev-master",
1717
"aloha/twilio": "^2.0",
18-
"fabpot/goutte": "^3.1"
18+
"fabpot/goutte": "^3.1",
19+
"mjerwin/clockwork-sms": "^0.9.1"
1920
},
2021
"require-dev": {
2122
"fzaninotto/faker": "~1.4",

composer.lock

Lines changed: 74 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@extends('layouts.master')
2+
3+
@section('content')
4+
<div class="main-container">
5+
@include('layouts.partials.alerts')
6+
7+
<div class="page-header">
8+
<h2><i class="fa fa-phone"></i> Clockwork SMS API</h2>
9+
</div>
10+
11+
<div class="btn-group btn-group-justified">
12+
<a href="http://github.com/mediaburst/node-clockwork" target="_blank" class="btn btn-primary">
13+
<i class="fa fa-check-square-o"></i> Clockwork Node
14+
</a>
15+
<a href="http://www.clockworksms.com/doc/clever-stuff/xml-interface/send-sms/" target="_blank" class="btn btn-primary">
16+
<i class="fa fa-code-fork"></i> XML API
17+
</a>
18+
</div>
19+
20+
<h4>Send a text message</h4>
21+
22+
<div class="row">
23+
<div class="col-sm-6">
24+
<form role="form" method="POST" action="{{ route('api.clockwork') }}">
25+
{!! csrf_field() !!}
26+
<div class="form-group{{ $errors->has('telephone') ? ' has-error' : '' }}">
27+
<div class="input-group">
28+
<input type="text" name="telephone" placeholder="Phone Number (international format)" class="form-control">
29+
<span class="input-group-btn">
30+
<button type="submit" class="btn btn-success">Send</button>
31+
</span>
32+
</div>
33+
@if ($errors->has('telephone'))
34+
<span class="help-block">{{ $errors->first('telephone') }}</span>
35+
@endif
36+
</div>
37+
</form>
38+
</div>
39+
</div>
40+
41+
<br>
42+
</div>
43+
@stop

resources/views/api/twilio.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<div class="form-group{{ $errors->has('number') ? ' has-error' : '' }}">
3030
<label class="control-label">Number to text</label>
3131
<input type="text" name="number" autofocus="" class="form-control">
32-
@if ($errors->has('number'))
32+
@if ($errors->has('number'))
3333
<span class="help-block">{{ $errors->first('number') }}</span>
3434
@endif
3535
</div>

resources/views/apidashboard.blade.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@
133133
</div>
134134
</a>
135135
</div>
136-
<div class="col-sm-4">
137-
<a href="/api/venmo" style="color: #fff">
138-
<div style="background-color: #1f93cf" class="panel panel-default">
139-
<div class="panel-body">
140-
<img src="http://i.imgur.com/90tl9C8.gif" height="40"> Venmo
141-
</div>
142-
</div>
143-
</a>
144-
</div>
145136
<div class="col-sm-4">
146137
<a href="/api/yahoo" style="color: #fff">
147138
<div style="background-color: #3d048b" class="panel panel-default">

0 commit comments

Comments
 (0)