Skip to content

Commit

Permalink
Use URIs and coercions.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Jun 5, 2015
1 parent 00fd65f commit 97a3246
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/Hive.pm
@@ -1,14 +1,23 @@
package Hive;

use Moose;
use Moose::Util::TypeConstraints;
use strict;
use warnings;

use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Request::Common;
use URI;
use JSON;

subtype 'HiveURI'
=> as 'URI';

coerce 'HiveURI'
=> from 'Str'
=> via { URI->new($_) };

has username => (
is => 'ro',
isa => 'Str',
Expand Down Expand Up @@ -37,19 +46,21 @@ sub _build_ua {

has base_url => (
is => 'ro',
isa => 'Str',
isa => 'HiveURI',
default => 'https://api.hivehome.com/v5/',
coerce => 1,
);

has user_url => (
is => 'ro',
isa => 'Str',
isa => 'HiveURI',
lazy_build => 1,
coerce => 1,
);

sub _build_user_url {
my $self = shift;
return $self->base_url . '/users/' . $self->username;
return $self->base_url->as_string . '/users/' . $self->username;
}


Expand Down

0 comments on commit 97a3246

Please sign in to comment.