line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::CallFire; |
2
|
1
|
|
|
1
|
|
331406
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
123
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has base_url => 'https://api.callfire.com/v2'; |
9
|
|
|
|
|
|
|
has password => sub { die 'missing password' }; |
10
|
|
|
|
|
|
|
has username => sub { die 'missing username' }; |
11
|
|
|
|
|
|
|
has _ua => sub { Mojo::UserAgent->new }; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
1
|
1501
|
sub get { shift->_tx(get => @_) } |
14
|
1
|
|
|
1
|
1
|
5408
|
sub post { shift->_tx(post => @_) } |
15
|
0
|
|
|
0
|
1
|
0
|
sub put { shift->_tx(put => @_) } |
16
|
0
|
|
|
0
|
1
|
0
|
sub del { shift->_tx(delete => @_) } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _tx { |
19
|
2
|
50
|
|
2
|
|
11
|
my ($self, $method, $cb) = (shift, shift, ref $_[-1] eq 'CODE' ? pop @_ : ()); |
20
|
2
|
|
|
|
|
6
|
my $path = shift; |
21
|
2
|
50
|
|
|
|
5
|
if ( $cb ) { |
22
|
|
|
|
|
|
|
$self->_ua->$method($self->_url($path) => @_ => sub { |
23
|
0
|
|
|
0
|
|
0
|
my ($ua, $tx) = @_; |
24
|
0
|
|
|
|
|
0
|
$cb->($ua, $tx); |
25
|
0
|
|
|
|
|
0
|
}); |
26
|
|
|
|
|
|
|
} else { |
27
|
2
|
|
|
|
|
8
|
my $tx = $self->_ua->$method($self->_url($path) => @_); |
28
|
2
|
|
|
|
|
17226
|
return $tx; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _url { |
33
|
2
|
|
|
2
|
|
12
|
my ($self, $path) = @_; |
34
|
2
|
|
|
|
|
6
|
my $url = Mojo::URL->new($self->base_url); |
35
|
2
|
|
|
|
|
395
|
$url->userinfo(join ':', $self->username, $self->password)->path($path); |
36
|
2
|
|
|
|
|
72
|
return $url; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=encoding utf8 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Mojo::CallFire - A simple interface to the CallFire API |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use Mojo::CallFire; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $cf = Mojo::CallFire->new(username => '...', password => '...'); |
52
|
|
|
|
|
|
|
say $cf->get('/calls')->result->json('/items/0/id'); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
A simple interface to the CallFire API. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Currently only L, L, L, and L methods are available, |
59
|
|
|
|
|
|
|
and they offer no data validation or error handling. No built-in support for |
60
|
|
|
|
|
|
|
paging. Pull requests welcome! |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
The API reference guide is available at L |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
So what does this module do? It makes building the API URL easier and includes |
65
|
|
|
|
|
|
|
the username and password on all requests. So, not much. But it does offer a |
66
|
|
|
|
|
|
|
little bit of sugar, and, hopefully eventually, some data validation, error |
67
|
|
|
|
|
|
|
handling, and built-in support for paging. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L implements the following attributes. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 base_url |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $base_url = $cf->base_url; |
76
|
|
|
|
|
|
|
$cf = $cf->base_url($url); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The base URL for the CallFire API, defaults to https://api.callfire.com/v2. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 password |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $password = $cf->password; |
83
|
|
|
|
|
|
|
$cf = $cf->password($password); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The password for the CallFire API. Generate a password API credential on |
86
|
|
|
|
|
|
|
CallFire's API access page. Read more at the Authentication section of the |
87
|
|
|
|
|
|
|
API Reference at L. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 username |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $username = $cf->username; |
92
|
|
|
|
|
|
|
$cf = $cf->username($username); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The username for the CallFire API. Generate a username API credential on |
96
|
|
|
|
|
|
|
CallFire's API access page. Read more at the Authentication section of the |
97
|
|
|
|
|
|
|
API Reference at L. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 METHODS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L inherits all methods from L and implements the |
102
|
|
|
|
|
|
|
following new ones. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 del |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Blocking |
107
|
|
|
|
|
|
|
my $tx = $cf->del('/rest/endpoint', %args); |
108
|
|
|
|
|
|
|
say $tx->result->body; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Non-blocking |
111
|
|
|
|
|
|
|
$cf->del('/rest/endpoint', %args => sub { |
112
|
|
|
|
|
|
|
my ($ua, $tx) = @_; |
113
|
|
|
|
|
|
|
say $tx->result->body; |
114
|
|
|
|
|
|
|
}); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
A RESTful DELETE method. Accepts the same arguments as L with |
117
|
|
|
|
|
|
|
the exception that the URL is built starting from the L and the |
118
|
|
|
|
|
|
|
Basic HTTP Athorization of the username and password are automatically applied |
119
|
|
|
|
|
|
|
on each request. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
See the CallFire API Reference at L |
122
|
|
|
|
|
|
|
for the HTTP methods, URL path, and parameters to supply for each desired |
123
|
|
|
|
|
|
|
action. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 get |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Blocking |
128
|
|
|
|
|
|
|
my $tx = $cf->get('/rest/endpoint', %args); |
129
|
|
|
|
|
|
|
say $tx->result->body; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Non-blocking |
132
|
|
|
|
|
|
|
$cf->get('/rest/endpoint', %args => sub { |
133
|
|
|
|
|
|
|
my ($ua, $tx) = @_; |
134
|
|
|
|
|
|
|
say $tx->result->body; |
135
|
|
|
|
|
|
|
}); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
A RESTful GET method. Accepts the same arguments as L with |
138
|
|
|
|
|
|
|
the exception that the URL is built starting from the L and the |
139
|
|
|
|
|
|
|
Basic HTTP Athorization of the username and password are automatically applied |
140
|
|
|
|
|
|
|
on each request. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
See the CallFire API Reference at L |
143
|
|
|
|
|
|
|
for the HTTP methods, URL path, and parameters to supply for each desired |
144
|
|
|
|
|
|
|
action. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 post |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# Blocking |
149
|
|
|
|
|
|
|
my $tx = $cf->post('/rest/endpoint', %args); |
150
|
|
|
|
|
|
|
say $tx->result->body; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Non-blocking |
153
|
|
|
|
|
|
|
$cf->post('/rest/endpoint', %args => sub { |
154
|
|
|
|
|
|
|
my ($ua, $tx) = @_; |
155
|
|
|
|
|
|
|
say $tx->result->body; |
156
|
|
|
|
|
|
|
}); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
A RESTful POST method. Accepts the same arguments as L with |
159
|
|
|
|
|
|
|
the exception that the URL is built starting from the L and the |
160
|
|
|
|
|
|
|
Basic HTTP Athorization of the username and password are automatically applied |
161
|
|
|
|
|
|
|
on each request. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
See the CallFire API Reference at L |
164
|
|
|
|
|
|
|
for the HTTP methods, URL path, and parameters to supply for each desired |
165
|
|
|
|
|
|
|
action. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 put |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# Blocking |
170
|
|
|
|
|
|
|
my $tx = $cf->put('/rest/endpoint', %args); |
171
|
|
|
|
|
|
|
say $tx->result->body; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Non-blocking |
174
|
|
|
|
|
|
|
$cf->put('/rest/endpoint', %args => sub { |
175
|
|
|
|
|
|
|
my ($ua, $tx) = @_; |
176
|
|
|
|
|
|
|
say $tx->result->body; |
177
|
|
|
|
|
|
|
}); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
A RESTful PUT method. Accepts the same arguments as L with |
180
|
|
|
|
|
|
|
the exception that the URL is built starting from the L and the |
181
|
|
|
|
|
|
|
Basic HTTP Athorization of the username and password are automatically applied |
182
|
|
|
|
|
|
|
on each request. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
See the CallFire API Reference at L |
185
|
|
|
|
|
|
|
for the HTTP methods, URL path, and parameters to supply for each desired |
186
|
|
|
|
|
|
|
action. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SEE ALSO |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |