Skip to content
This repository
  • 4 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
Jan 12, 2012
Adriano Ferreira Remove generated code included by mistake 9ffb1ac
Jan 13, 2012
Adriano Ferreira Rename file name for consistency: JSON, not Json d96b138
Feb 23, 2012
Adriano Ferreira Fix signing for parameters which are file uploads
The rule is to use the "filename" as the parameter value
in this case. This is coherent with the server side behavior.

To use empty filenames is forbidden, because this
won't work at the server side.
d8318ee
Adriano Ferreira Update dist files for 0.96 release e030c63
3  Changes
@@ -2,6 +2,9 @@ Revision history for YellowBot-API
2 2
3 3 {{$NEXT}}
4 4
  5 +0.96 February 23, 2012
  6 + Fix signing of file uploads as parameters
  7 +
5 8 0.95 January 11, 2012
6 9 Support JSON POST requests
7 10
2  lib/YellowBot/API.pm
@@ -49,7 +49,7 @@ sub _build_ua {
49 49
50 50 my %REQ_CLASS = (
51 51 'post' => 'YellowBot::API::Request',
52   - 'j-post' => 'YellowBot::API::Request::Json',
  52 + 'j-post' => 'YellowBot::API::Request::JSON',
53 53 );
54 54
55 55 sub _request {
22 lib/YellowBot/API/Request.pm
... ... @@ -1,6 +1,7 @@
1 1 package YellowBot::API::Request;
2 2 use Moose;
3 3 use URI ();
  4 +use Carp qw(croak);
4 5 use Digest::SHA qw(hmac_sha256_hex);
5 6 use HTTP::Request::Common qw(POST);
6 7 use namespace::clean -except => 'meta';
@@ -83,13 +84,32 @@ sub http_request {
83 84 return $request;
84 85 }
85 86
  87 +sub _file_as_value {
  88 + my $v = shift;
  89 + my $fn = $v->[1];
  90 + unless (defined $fn) { # Infer from local file name
  91 + $fn = $v->[0];
  92 + $fn =~ s,.*/,, if defined $fn;
  93 + }
  94 + unless ($fn) {
  95 + croak "File uploads must have file names";
  96 + }
  97 + return $fn;
  98 +}
  99 +# Based on HTTP::Request::form_data() handling of uploads
  100 +# according to the specification [ $file, $usename, @headers ]
  101 +
86 102 sub _get_parameter_string {
87 103 my $args = shift;
88 104
89 105 my $str = "";
90 106 for my $key (sort {$a cmp $b} keys %{$args}) {
91 107 next if $key eq 'api_sig';
92   - my $value = (defined($args->{$key})) ? $args->{$key} : "";
  108 + my $v = $args->{$key};
  109 + my $value =
  110 + defined($v)
  111 + ? (ref($v) ? _file_as_value($v) : $v)
  112 + : "";
93 113 $str .= $key . $value;
94 114 }
95 115 return $str;
9 lib/YellowBot/API/Request/Json.pm → lib/YellowBot/API/Request/JSON.pm
... ... @@ -1,7 +1,4 @@
1 1 package YellowBot::API::Request::Json;
2   -{
3   - $YellowBot::API::Request::Json::VERSION = '0.94';
4   -}
5 2
6 3 use Moose;
7 4
@@ -35,7 +32,7 @@ sub _more_args {
35 32
36 33 sub _build_request {
37 34 my $self = shift;
38   -
  35 +
39 36 my $uri = $self->_build_uri;
40 37 my %query = $self->_signed_query_form;
41 38 $uri->query_form(%query);
@@ -77,8 +74,8 @@ No user servicable parts inside. This part of the API is subject to change.
77 74 fob => 123,
78 75 },
79 76 );
80   -
81   - my $http_request = $req->http_request;
  77 +
  78 + my $http_request = $req->http_request;
82 79
83 80
84 81 =head1 METHODS

No commit comments for this range

Something went wrong with that request. Please try again.