File Coverage

blib/lib/Mojo/WebService/Twitter/Util.pm
Criterion Covered Total %
statement 19 20 95.0
branch n/a
condition n/a
subroutine 9 10 90.0
pod 2 2 100.0
total 30 32 93.7


line stmt bran cond sub pod time code
1             package Mojo::WebService::Twitter::Util;
2              
3 3     3   68444 use strict;
  3         14  
  3         86  
4 3     3   16 use warnings;
  3         5  
  3         76  
5 3     3   15 use Exporter 'import';
  3         7  
  3         99  
6 3     3   499 use Mojo::URL;
  3         197147  
  3         22  
7 3     3   592 use Time::Piece ();
  3         9389  
  3         675  
8              
9             our $VERSION = '1.001';
10              
11             our @EXPORT_OK = qw(parse_twitter_timestamp twitter_authorize_url);
12              
13             our $API_BASE_URL = 'https://api.twitter.com/1.1/';
14             our $OAUTH_BASE_URL = 'https://api.twitter.com/oauth/';
15             our $OAUTH2_BASE_URL = 'https://api.twitter.com/oauth2/';
16              
17 44     44 1 261 sub parse_twitter_timestamp { Time::Piece->strptime(shift, '%a %b %d %H:%M:%S %z %Y') }
18              
19 0     0 1 0 sub twitter_authorize_url { _oauth_url('authorize')->query(oauth_token => shift) }
20              
21 9     9   49 sub _api_url { Mojo::URL->new($API_BASE_URL)->path(shift) }
22 2     2   13 sub _oauth_url { Mojo::URL->new($OAUTH_BASE_URL)->path(shift) }
23 1     1   4 sub _oauth2_url { Mojo::URL->new($OAUTH2_BASE_URL)->path(shift) }
24              
25             1;
26              
27             =head1 NAME
28              
29             Mojo::WebService::Twitter::Util - Utility functions for Twitter client
30              
31             =head1 SYNOPSIS
32              
33             use Mojo::WebService::Twitter::Util 'parse_twitter_timestamp';
34              
35             my $epoch = parse_twitter_timestamp('Fri Oct 23 17:18:19 +0100 2015')->epoch;
36              
37             =head1 DESCRIPTION
38              
39             L contains utility functions used by
40             L for interacting with the L
41             API. All functions are exportable on demand.
42              
43             =head1 FUNCTIONS
44              
45             =head2 parse_twitter_timestamp
46              
47             my $time = parse_twitter_timestamp($ts);
48              
49             Takes a timestamp string in the format returned by Twitter and returns a
50             corresponding L object in UTC.
51              
52             =head2 twitter_authorize_url
53              
54             my $url = twitter_authorize_url($token);
55              
56             Takes an OAuth 1.0 request token and returns a L for manual user
57             authorization.
58              
59             =head1 BUGS
60              
61             Report any issues on the public bugtracker.
62              
63             =head1 AUTHOR
64              
65             Dan Book
66              
67             =head1 COPYRIGHT AND LICENSE
68              
69             This software is Copyright (c) 2015 by Dan Book.
70              
71             This is free software, licensed under:
72              
73             The Artistic License 2.0 (GPL Compatible)
74              
75             =head1 SEE ALSO
76              
77             L