Weenect-API

 view release on metacpan or  search on metacpan

lib/Weenect/API.pm  view on Meta::CPAN


=cut

method login( $user = "", $pass = "" ) {
    $api = Weenect::Connect->new;
    $api->debug = $debug;
    my $acct = $self->get_acct( $user, $pass );
    my $res = $api->request( "user/login",
			     Content => $acct->json );
    return unless $res;
    $api->auth = Weenect::Auth->create($res);
}

method get_acct( $user, $pass ) {
    return $acct if $acct;
    if ( $user && $pass ) {
	return $acct =
	  Weenect::Login->new( username => $user, password => $pass );
    }

    require ResInfo;
    my $passwd = { password => 'ddjc8c*@!eqe6' };
    $acct = Weenect::Login->new
      ( username => ResInfo::resinfo( "weenect.username", $passwd ),
	password => ResInfo::resinfo( "weenect.password", $passwd ),
      );
}

=head2 get_trackers

Returns a list of trackers associated with this account, in the form
of Weenect::Tracker objects

=cut

method get_trackers {
    require Weenect::Tracker;

    my $res = $api->request("mytracker"); # same as "mytracker-userspace"?
    return unless $res;

    return Weenect::Trackers->create_with_api( $res, $api );
}

=head2 get_preferences

Returns the current set of preferences in the form of a
Weenect::Preferences object.

=cut

method get_preferences {
    require Weenect::Preferences;

    my $res = $api->request("myuser");
    return unless $res;

    return Weenect::Preferences->create($res);
}

=head2 set_preferences( %prefs )

Sets one or more preferences.

E.g.

    language => "nl"
    preferred_metric_system => "km"
    option => 0
    mail_pref => { offers => 0,
                   company_news => 0,
                   new_features => 0,
                   surveys_and_tests => 0 }

Returns the current set of preferences in the form of a
Weenect::Preferences object.

=cut

method set_preferences( %prefs ) {
    require Weenect::Preferences;
    my $res = $api->request( "myuser", Content => \%prefs );
    return unless $res;

    return Weenect::Preferences->create($res);
}

=head2 get_animals( $imei )

Returns a list of animals associated with a given tracked, identified by its IMEI number (as a string).

The animals info is in the form of a Weenect::Animal object.

=cut

method get_animals( $imei ) {
    require Weenect::Animal;
    my $res = $api->request( sprintf("animal?imei=%s", $imei) );
    return unless $res;

    my $animals = Weenect::Animals->create($res);

    return $animals->items;
}

=head2 logout

Disconnect.

=cut

method logout {
    return $api->request("logout");
}

=head2 kindex

Get the planetary magnetic field disturbance.

Mostly returns nothing.

=cut

method kindex {
    return $api->request("kindex");
}

=head2 wifi-zone( $zid )

Returns a WiFiZone object for the requested wifi zone.

=cut

method wifi_zone( $zid ) {
    return $api->request( sprintf("wifi-zone/%d", $zid ) );
}

=head2 wifi_zone_active( $zid, $active )

Enables/disables a WiFi zone.

=cut



( run in 0.358 second using v1.01-cache-2.11-cpan-2aafcb1aa8b )