old_test.pl untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod n/a totaltotal 0.0% 0 / 61 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/perl
2  
3 use lib './lib';
4 use Furl::HTTP::OAuth;
5 use URI;
6 use Encode;
7 use JSON::XS;
8  
9 my $client = Furl::HTTP::OAuth->new(
10 consumer_key => "vgyYVbu7yljXXd2MZTfDmw",
11 consumer_secret => "QnS5arFmnmeQQ-iB_Zbi9MuocY0",
12 signature_method => "HMAC-SHA1",
13 token => "9AkV-RywDkMD5JTZUUYeCltl2rbhCR2p",
14 token_secret => "PRMLwzaY17Zb8fsPR9aMx7LQzbI"
15 );
16  
17 my ($version, $code, $msg, $headers, $body) = $client->get('https://api.yelp.com/v2/search?term=Food&location=San+Francisco');
18  
19 use Data::Dumper;
20 warn Dumper({
21 version => $version,
22 code => $code,
23 message => $msg,
24 headers => $headers,
25 body => decode_json($body)
26 });
27  
28  
29 # consumer_key => "9djdj82h48djs9d2",
30 # consumer_secret => "consumersecret",
31 # signature_method => "HMAC-SHA1",
32 # token => "kkk9d7dh3k39sjv7",
33 # token_secret => "tokensecret"
34 # $url, $method, $content, $headers, $write_file, $write_code
35  
36 exit;
37  
38  
39 my $url = 'http://google.com/blah';
40 my $uri = URI->new($url);
41 $uri->query_form(
42 b5 => '=%3D',
43 a3 => 'a',
44 'c@' => '',
45 a2 => 'r b',
46 c2 => '',
47 a3 => '2 q'
48 );
49  
50 warn "url: " . $uri->as_string;
51  
52 warn "string: " . $client->request(
53 method => 'GET',
54 url => $uri->as_string
55 );
56  
57 exit;
58  
59 # "137131201" - timestamp
60 # "7d8f3e4a"- nonce
61  
62 #sub decode_param {
63 # my $param = shift;
64 # URI::Escape::uri_unescape($param);
65 #}
66  
67 # oauth_consumer_key
68 # oauth_consumer_secret
69 # oauth_nonce
70 # oauth_signature_method
71 # oauth_timestamp
72 # oauth_token
73 # oauth_token_secret
74  
75 # FURL HANDLES THESE INPUT TYPES TO ->REQUEST
76 # potential input types
77 # - HTTP::Request (see HTTP::Message)
78 # - filehandle for binary?
79 # - hashref of parameters and/or parameters in the URL
80 # - arrayref of parameters and/or parameters in the URL
81  
82 # OAUTH REQUIRES HANDLING OF THESE PARAMETERS (SIG GENERATION)
83 # - query component of URI
84 # - The OAuth HTTP "Authorization" header field (Section 3.5.1) if
85 # present. The header's content is parsed into a list of name/value
86 # pairs excluding the "realm" parameter if present. The parameter
87 # values are decoded as defined by Section 3.5.1.
88 # - the request body IF
89 # 1. body is single part
90 # 2. body is application/x-www-form-urlencoded
91 # 3. body Content-Type is application/x-www-form-urlencoded
92 # - EXCLUDE "oauth_signature" parameter from sig generation IF PRESENT
93  
94 # SIGNATURE GENERATION
95 # Parts:
96 # - HTTP METHOD
97 # - authority as declared by http "Host" header field
98 # - The path and query components of the request resource URI.
99 # - The protocol parameters excluding the "oauth_signature".
100 # - Parameters included in the request entity-body SEE ABOVE
101  
102 # Process, Join:
103 # 1. HTTP req method in uppercase
104 # 2. An "&" character
105 # 3. URI string - scheme, authority, path, all in lowercase. include port if not 80. see URI STRING EXAMPLE below. - PERCENT ENCODED
106 # 4. An "&" character
107 # 5. normalized request parameters - PERCENT ENCODED THEN SORTED
108  
109 # URI STRING EXAMPLE
110 # GET /r%20v/X?id=123 HTTP/1.1
111 # Host: EXAMPLE.COM:80
112  
113 # is represented by the base string URI: "http://example.com/r%20v/X".
114  
115 # In another example, the HTTPS request:
116  
117 # GET /?q=1 HTTP/1.1
118 # Host: www.example.net:8080
119  
120 # is represented by the base string URI:
121 # "https://www.example.net:8080/".
122  
123 # Make OAuth 1.0a signed requests with Furl
124  
125 # docs:
126 # - https://www.yelp.com/developers/documentation/v2/authentication
127 # - https://www.yelp.com/developers/manage_api_keys
128 # - http://nouncer.com/oauth/authentication.html
129 # - http://tools.ietf.org/html/rfc5849#section-3.1
130  
131 # examples
132 # - http://cpansearch.perl.org/src/IKEBE/Furl-S3-0.02/lib/Furl/S3.pm
133 # - http://search.cpan.org/~tokuhirom/Furl-3.08/lib/Furl/HTTP.pm
134 # - http://search.cpan.org/~mathias/OAuth-Consumer-0.03/lib/OAuth/Consumer.pm
135 # - http://blog.kazuhooku.com/2011/02/5x-performance-switching-from-lwp-to.html
136  
137 # http://cpansearch.perl.org/src/LYOKATO/OAuth-Lite-1.34/lib/OAuth/Lite/Util.pm
138 # http://search.cpan.org/~gaas/Digest-HMAC-1.03/lib/Digest/HMAC_SHA1.pm
139 # https://www.yelp.com/developers/manage_api_keys
140 # http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4
141  
142 # http://tools.ietf.org/html/rfc5849#section-3.4.1.3.2
143 # http://tools.ietf.org/html/rfc5849#section-3.4.1.3.1
144 # http://tools.ietf.org/html/rfc5849#section-3.6 - percent encoding
145 # http://tools.ietf.org/html/rfc5849#section-3.5.2
146 # http://stackoverflow.com/questions/4113934/how-is-oauth-2-different-from-oauth-1
147  
148 # -------------------------------------------------------------------
149 # END OF NOTES
150  
151  
152 # my @foo = ('foo', '1', 'bar', '2', 'baz', '3', 'blah', undef);
153  
154 # for (my $i = 0; $i <= (@foo - 1); $i += 2) {
155 # my $key = $foo[$i];
156 # my $val = $foo[$i + 1];
157  
158 # warn "key: $key | val: $val";
159 # }
160  
161 #exit;
162 my ($scheme, $host, $path, $query, undef) = $url =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
163  
164 my $port;
165  
166 ($host, $port) = split /:/, $host
167 if ($host =~ m!:!);
168  
169 warn "host: $host | port: $port |";
170  
171 if ($port) {
172 warn "port: $port";
173 }
174 use Data::Dumper;
175 warn Dumper(\@parts);
176  
177 use URI;
178 my $uri = URI->new($url);
179 my @q = $uri->query_form;
180  
181 warn Dumper(\@q);
182  
183 warn $uri->scheme;
184 warn $uri->host;
185 warn $uri->path;
186 warn $uri->port;