| 1 | package Switchvox::API; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use LWP::UserAgent; | ||
| 6 | use Crypt::SSLeay; #- required for LWP to use https: | ||
| 7 | use Switchvox::API::Request; | ||
| 8 | use Switchvox::API::Response; | ||
| 9 | |||
| 10 | use base 'LWP::UserAgent'; | ||
| 11 | |||
| 12 | our $VERSION = '1.02'; | ||
| 13 | |||
| 14 | sub new | ||
| 15 | { | ||
| 16 | my ($class,%in) = @_; | ||
| 17 | warn "Missing hostname in call to constructor" unless defined $in{hostname}; | ||
| 18 | warn "Missing username in call to constructor" unless defined $in{username}; | ||
| 19 | warn "Missing password in call to constructor" unless defined $in{password}; | ||
| 20 | |||
| 21 | my $self = new LWP::UserAgent; | ||
| 22 | $self->{_sv_hostname} = $in{hostname}; | ||
| 23 | $self->{_sv_username} = $in{username}; | ||
| 24 | $self->{_sv_password} = $in{password}; | ||
| 25 | bless $self, $class; | ||
| 26 | return $self; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub api_request | ||
| 30 | { | ||
| 31 | my ($self,%in) = @_; | ||
| 32 | $in{hostname} = $self->{_sv_hostname}; | ||
| 33 | my $request = new Switchvox::API::Request(%in); | ||
| 34 | return $self->_execute_request($request); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub _execute_request | ||
| 38 | { | ||
| 39 | my ($self,$request) = @_; | ||
| 40 | $self->credentials($self->{_sv_hostname}.':443', 'switchvox_api_auth', $self->{_sv_username},$self->{_sv_password}); | ||
| 41 | my $response = $self->request($request); | ||
| 42 | my $api_response = new Switchvox::API::Response(response => $response); | ||
| 43 | $api_response->process(); | ||
| 44 | return $api_response; | ||
| 45 | } | ||
| 46 | |||
| 47 | 1; #- Switchvox rules! | ||
| 48 | |||
| 49 | __END__ |