First things first
So the first thing you’ll need is the Webservice plugin.
Then you need to load the plugin in your
config/bootstrap.php and tell the
ConnectionManager to consume your config.
Then be sure to add the configuration for your service to the
This means you need to add another array key to your config, it should contain something like the following.
1 2 3 4 5 6 7 8 9 10 11 12 13
I’ll talk through the various config options here.
This is a proxy class which will pass method calls through to your own driver class.
This is your driver class where you’ll write your code and connect to the service.
Any login credentials you need will have to be included.
Creating your driver class
So you need to create a new driver class, which uses the Webservice plugin as a base.
For my example, I’ve created my Twitter driver class in
Muffin\Webservice\AbstractDriver, and I’ve implemented the stub method, which is just
to setup the client you want to use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
There is a gotcha here!
You will need to implement some methods from
your driver class so that DebugKit can interact with your driver. These methods
can be copied and pasted from the Connection class.
Creating your method
So assuming we want to get some tweets, we can create a method for that inside our driver class.
1 2 3 4 5
This will use the CakePHP Http Client to post to a Twitter url and return the response.
Using your new driver
So now we need to actually get the data to play with. In our controller we need to instantiate the connection and call our new method.
1 2 3 4 5 6 7
You must make sure that the name of the connection you give to ConnectionManager matches
the name you used in your
app.php config setup.
Job done! Have a brew.