Λόρδος Σπύρος Δεναξάς > WebService-TWFY-API > WebService::TWFY::API

Download:
WebService-TWFY-API-0.07.2.tar.gz

Dependencies

Annotate this POD (1)

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.07   Source  

NAME ^

WebService::TWFY::API - API interface for TheyWorkForYou.com

VERSION ^

Version 0.07

SYNOPSIS ^

  use WebService::TWFY::API ;
  
  my $rh = { key => 'ABC123' }; 
  my $api = WebService::TWFY::API->new( $rh ) ;

  my $rv = $api->query ( 'getConstituency', { 'postcode' => 'W128JL'
                                              'output'   => 'xml',
                                             } ) ;

  if ($rv->{is_success}) {
  
    my $results = $rv->{results} ;
    ### do whatever with results
  
  }

DESCRIPTION ^

This module provides a simple interface to the API of TheyWorkForYou.com.

The actual core class, WebService::TWFY::API is a subsclass of LWP::UserAgent so you are able to tweak all the normal options such as timeout etc. The UserAgent identifier however is hardcoded to "WebService::TWFY::API module". This does not provide any personal information to the API. However, it helps them track and monitor usage of the API service from this module.

METHODS ^

new

The following constructor method creates WebService::TWFY::API object and returns it.

  my $rh = { key => 'ABC123' };

  my $api = WebService::TWFY::API->new( $rh ) ;

The API now requires a key, you can obtain one at http://www.theyworkforyou.com/api/key. The key above will not work, its only used as an example.

In future versions, if needed, it will support specifying the version of the API you wish to use.

execute_query

Internal function which executes a request and blesses the response into a WebService::TWFY::Response object.

query

Creates a new WebService::TWFY::Request request object and executes it with the parameters specified.

  my $rv = $api->query ( 'getConstituency', { 'postcode' => 'W128JL'
                                              'output'   => 'xml',
                                             } ) ;
  
  or

  my $rv = $api->query ( 'getMP', { 'postcode' => 'W128JL'
                                    'output'   => 'js',
                                  } ) ; 
                                            

  abstract :
  
  my $rv = $api->query ( function, { parameter1 => value, 
                                     parameter2 => value,
                                     ...  
                                   } ) ;

For a complete list of functions supported by the API, visit http://www.theyworkforyou.com/api. Current output methods supported at the moment are XML (xml), JS (js), php (php) and RPC over Anything But XML (rabx). This essentially returns a WebService::TWFY::Response object, which is a HTTP::Response subclass with some additional keys in place:

  • is_success : 0 or 1
  • results : results returned from the API
  • error_code : the error code (if any)
  • error_message : the error message (if any)

SUPPORT ^

Please feel free to send any bug reports and suggestions to my email listed below.

For more information and useless facts on my life, you can also check my blog:

  http://ffffruit.com/

AUTHOR ^

    Spiros Denaxas
    CPAN ID: SDEN
    s [dot] denaxas [@] gmail [dot]com
    http://ffffruit.com

SOURCE CODE ^

The source code for his module is now on github https://github.com/spiros/WebService-TWFY-API

COPYRIGHT ^

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO ^

WebService::TWFY::Request, WebService::TWFY::Response, http://www.theyworkforyou.com/api/, http://www.theyworkforyou.com/

syntax highlighting: