Skip to content

Commit

Permalink
add code to delete a subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
lukec committed Jan 10, 2011
1 parent 673f301 commit 33f6e4e
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions lib/Net/Recurly.pm
Expand Up @@ -4,8 +4,6 @@ use LWP::UserAgent;
use HTTP::Request;
use XML::Simple;

our $VERSION = '0.001';

has 'subdomain' => (is => 'ro', isa => 'Str', required => 1);
has 'username' => (is => 'ro', isa => 'Str', required => 1);
has 'password' => (is => 'ro', isa => 'Str', required => 1);
Expand Down Expand Up @@ -49,6 +47,13 @@ sub get_subscription {
return $self->get("/accounts/$acct_code/subscription");
}

sub delete_subscription {
my $self = shift;
my $acct_code = shift;
return $self->delete("/accounts/$acct_code/subscription");
}


sub get_subscription_plan {
my $self = shift;
my $plan_code = shift;
Expand Down Expand Up @@ -85,7 +90,7 @@ sub get {
my $self = shift;
my $path = shift;

my $url = 'https://' . $self->api_host . $path;
my $url = $self->_build_url($path);
my $req = HTTP::Request->new(GET => $url);
$req->authorization_basic($self->username, $self->password);
$req->header('Accept' => 'application/xml');
Expand All @@ -98,6 +103,26 @@ sub get {
die "GET $url failed ($code - " . $resp->content . ")\n";
}

sub delete {
my $self = shift;
my $path = shift;

my $url = $self->_build_url($path);
my $req = HTTP::Request->new(DELETE => $url);
$req->authorization_basic($self->username, $self->password);
my $resp = $self->ua->request($req);
my $code = $resp->code;
return if $code =~ m/^2??$/;
return if $code == 404;
die "GET $url failed ($code - " . $resp->content . ")\n";
}

sub _build_url {
my $self = shift;
my $path = shift;
return 'https://' . $self->api_host . $path;
}

sub _build_ua {
my $self = shift;
my $ua = LWP::UserAgent->new(agent => "Net::Recurly - $VERSION");
Expand Down

0 comments on commit 33f6e4e

Please sign in to comment.