Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

modify add_query

  • Loading branch information...
commit f4df30bd8eab4c41f9051286d348337290b87874 1 parent 77f3dfd
@memememomo authored
View
7 lib/WebService/Simple/ATND/Query/Events.pm
@@ -25,7 +25,12 @@ no strict 'refs';
for my $name (@query_names) {
*{ "add_$name" } = sub {
my ($self, $value) = @_;
- push @{ $self->{$name} }, $value;
+ $self->{$name} = [] if ref $self->{$name} ne 'ARRAY';
+ if (ref $value eq 'ARRAY') {
+ push @{ $self->{$name} }, @$value;
+ } else {
+ push @{ $self->{$name} }, $value;
+ }
return $self;
};
}
View
6 lib/WebService/Simple/ATND/Query/Users.pm
@@ -23,7 +23,11 @@ for my $name (@query_names) {
*{ "add_$name" } = sub {
my ($self, $value) = @_;
$self->{$name} = [] if ref $self->{$name} ne 'ARRAY';
- push @{ $self->{$name} }, $value;
+ if (ref $value eq 'ARRAY') {
+ push @{ $self->{$name} }, @$value;
+ } else {
+ push @{ $self->{$name} }, $value;
+ }
return $self;
};
}
View
78 t/01_query.t
@@ -9,45 +9,63 @@ my $atnd = WebService::Simple::ATND->new;
#$atnd->{debug} = 1;
{
- my $test_date = Time::Piece->strptime('2011-01-01 00:00:00', '%Y-%m-%d %H:%M:%S');
- my $query = WebService::Simple::ATND->query_events();
- $query->add_ym($test_date->strftime('%Y%m'));
+ my $test_date = Time::Piece->strptime('2011-01-01 00:00:00', '%Y-%m-%d %H:%M:%S');
+ my $query = WebService::Simple::ATND->query_events();
+ $query->add_ym($test_date->strftime('%Y%m'));
- my $res = $atnd->get($query);
+ my $res = $atnd->get($query);
- for my $event (@{ $res->events }) {
- my $started_at = $event->{started_at};
- $started_at =~ s/\+.+$//;
+ for my $event (@{ $res->events }) {
+ my $started_at = $event->{started_at};
+ $started_at =~ s/\+.+$//;
- my $ended_at = $event->{ended_at};
- $ended_at =~ s/\+.+$//;
+ my $ended_at = $event->{ended_at};
+ $ended_at =~ s/\+.+$//;
- $started_at = Time::Piece->strptime($started_at, '%Y-%m-%dT%H:%M:%S')->strftime('%Y%m');
- $ended_at = Time::Piece->strptime($ended_at, '%Y-%m-%dT%H:%M:%S')->strftime('%Y%m');
+ $started_at = Time::Piece->strptime($started_at, '%Y-%m-%dT%H:%M:%S')->strftime('%Y%m');
+ $ended_at = Time::Piece->strptime($ended_at, '%Y-%m-%dT%H:%M:%S')->strftime('%Y%m');
- ok($started_at <= $test_date->strftime('%Y%m') && $test_date->strftime('%Y%m') <= $ended_at, "$started_at, $ended_at");
- }
+ ok($started_at <= $test_date->strftime('%Y%m') && $test_date->strftime('%Y%m') <= $ended_at, "$started_at, $ended_at");
+ }
}
+{
+ my $query = WebService::Simple::ATND->query_events();
+ $query->add_keyword(['perl', 'php']);
+
+ my $res = $atnd->get($query);
+
+ my $count = @{ $res->events };
+ ok($count > 0, "count");
+
+ for my $event (@{ $res->events }) {
+ my $text = join('', $event->{title},
+ $event->{description},
+ $event->{catch},
+ $event->{address});
+ like($text, qr/perl/i, "not found keyword(perl)");
+ like($text, qr/php/i, "not found keyword(php)");
+ }
+}
{
- my $query = WebService::Simple::ATND->query_events();
- $query->add_keyword('perl');
- $query->add_keyword('php');
-
- my $res = $atnd->get($query);
-
- my $count = @{ $res->events };
- ok($count > 0, "count");
-
- for my $event (@{ $res->events }) {
- my $text = join('', $event->{title},
- $event->{description},
- $event->{catch},
- $event->{address});
- like($text, qr/perl/i, "not found keyword(perl)");
- like($text, qr/php/i, "not found keyword(php)");
- }
+ my $query = WebService::Simple::ATND->query_events();
+ $query->add_keyword('perl');
+ $query->add_keyword('php');
+
+ my $res = $atnd->get($query);
+
+ my $count = @{ $res->events };
+ ok($count > 0, "count");
+
+ for my $event (@{ $res->events }) {
+ my $text = join('', $event->{title},
+ $event->{description},
+ $event->{catch},
+ $event->{address});
+ like($text, qr/perl/i, "not found keyword(perl)");
+ like($text, qr/php/i, "not found keyword(php)");
+ }
}
{
Please sign in to comment.
Something went wrong with that request. Please try again.