-
Notifications
You must be signed in to change notification settings - Fork 2
/
JSON.pm
101 lines (65 loc) · 1.95 KB
/
JSON.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package YellowBot::API::Request::Json;
use Moose;
use HTTP::Request;
use JSON qw(encode_json);
use namespace::clean -except => 'meta';
extends 'YellowBot::API::Request';
has '+args' => (
isa => 'HashRef[Any]',
);
sub _signed_args {
my $self = shift;
my $all_args = $self->args;
my %args;
for my $p (qw(api_ts api_user_identifier)) {
$args{$p} = $all_args->{$p} if exists $all_args->{$p};
}
return \%args;
}
sub _more_args {
my $self = shift;
my %args = %{ $self->args };
delete @args{qw(api_ts api_key api_user_identifier api_sig api_secret auth_token)};
return %args;
}
sub _build_request {
my $self = shift;
my $uri = $self->_build_uri;
my %query = $self->_signed_query_form;
$uri->query_form(%query);
my %extra = $self->_more_args;
# JSON POST request
my $req = HTTP::Request->new('POST', $uri, ['Content-Type' => 'application/json; charset=utf-8']);
my $req_content = encode_json(\%extra);
$req->content($req_content);
return $req;
}
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=encoding utf8
=head1 NAME
YellowBot::API::Request::Json - Request object for YellowBot::API (JSON POST)
=head1 SYNOPSIS
This class manages setting up JSON POST requests for the YellowBot::API.
No user servicable parts inside. This part of the API is subject to change.
my $req = YellowBot::API::Request::Json->new
(api => $yellowbot_api,
method => 'location/detail',
args => { foo => 'bar',
fob => 123,
},
);
my $http_request = $req->http_request;
=head1 METHODS
=head2 api
=head2 http_request
Returns a HTTP::Request version of the request.
=head1 AUTHOR
Ask Bjørn Hansen, C<< <ask at develooper.com> >>
=head1 COPYRIGHT & LICENSE
Copyright 2009–2011 Solfo Inc, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut