| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::Slack::WebApi; | 
| 2 | 4 |  |  | 4 |  | 253942 | use strict; | 
|  | 4 |  |  |  |  | 27 |  | 
|  | 4 |  |  |  |  | 117 |  | 
| 3 | 4 |  |  | 4 |  | 22 | use warnings; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 96 |  | 
| 4 | 4 |  |  | 4 |  | 21 | use utf8; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 29 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 4 |  |  | 4 |  | 2091 | use Class::Load qw/ load_class /; | 
|  | 4 |  |  |  |  | 81447 |  | 
|  | 4 |  |  |  |  | 323 |  | 
| 7 |  |  |  |  |  |  | use Class::Accessor::Lite::Lazy ( | 
| 8 | 4 |  |  |  |  | 42 | new     => 1, | 
| 9 |  |  |  |  |  |  | rw      => [qw/ team_domain token opt /], | 
| 10 |  |  |  |  |  |  | ro_lazy => [qw/ client api auth channels conversations chat dialog emoji files groups im oauth pins reactions rtm search stars team users dnd bots migration /], | 
| 11 | 4 |  |  | 4 |  | 2255 | ); | 
|  | 4 |  |  |  |  | 11302 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 4 |  |  | 4 |  | 3918 | use WebService::Slack::WebApi::Client; | 
|  | 4 |  |  |  |  | 18 |  | 
|  | 4 |  |  |  |  | 577 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | our $VERSION = '0.16'; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub _build_client { | 
| 18 | 6 |  |  | 6 |  | 7568 | my $self = shift; | 
| 19 | 6 |  |  |  |  | 31 | return WebService::Slack::WebApi::Client->new( | 
| 20 |  |  |  |  |  |  | team_domain => $self->team_domain, | 
| 21 |  |  |  |  |  |  | token       => $self->token, | 
| 22 |  |  |  |  |  |  | opt         => $self->opt, | 
| 23 |  |  |  |  |  |  | ); | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | for my $class_name (qw/ api auth channels conversations chat dialog emoji files groups im oauth pins reactions rtm search stars team users dnd bots migration /) { | 
| 27 |  |  |  |  |  |  | my $method = sprintf '%s::_build_%s', __PACKAGE__, $class_name; | 
| 28 |  |  |  |  |  |  | my $class  = sprintf '%s::%s', __PACKAGE__, ucfirst($class_name); | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 4 |  |  | 4 |  | 46 | no strict 'refs'; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 412 |  | 
| 31 |  |  |  |  |  |  | *$method = sub { | 
| 32 | 42 |  |  | 42 |  | 78603 | load_class $class; | 
| 33 | 42 |  |  |  |  | 1486 | return $class->new(client => shift->client) | 
| 34 |  |  |  |  |  |  | }; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | 1; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | __END__ | 
| 40 |  |  |  |  |  |  | =pod | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head1 NAME | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | WebService::Slack::WebApi - a simple wrapper for Slack Web API | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | use WebService::Slack::WebApi; | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # the token is required unless using $slack->oauth->access | 
| 51 |  |  |  |  |  |  | my $slack = WebService::Slack::WebApi->new(token => 'access token'); | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # getting channel's descriptions | 
| 54 |  |  |  |  |  |  | my $channels = $slack->conversations->list; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | # posting message to specified channel and getting message description | 
| 57 |  |  |  |  |  |  | my $posted_message = $slack->chat->post_message( | 
| 58 |  |  |  |  |  |  | channel  => 'channel id', # required | 
| 59 |  |  |  |  |  |  | text     => 'hoge',       # required (not required if 'attachments' argument exists) | 
| 60 |  |  |  |  |  |  | username => 'fuga',       # optional | 
| 61 |  |  |  |  |  |  | # other optional parameters... | 
| 62 |  |  |  |  |  |  | ); | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | WebService::Slack::WebApi is a simple wrapper for Slack Web API (https://api.slack.com/web). | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =head1 Options | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | You can set some options by giving C<opt> parameter to C<new> method. | 
| 71 |  |  |  |  |  |  | Almost values of C<opt> are gived to C<Furl#new>. | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | WebService::Slack::WebApi->new(token => 'access token', opt => {}); | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =head2 Proxy | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | C<opt> can contain C<env_proxy> as boolean value . | 
| 78 |  |  |  |  |  |  | If C<env_proxy> is true then proxy settings are loaded from C<$ENV{HTTP_PROXY}> and C<$ENV{NO_PROXY}> by calling C<Furl#env_proxy> method. | 
| 79 |  |  |  |  |  |  | See also https://metacpan.org/pod/Furl#furl-env_proxy. | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head1 METHODS | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | This module provides all methods declared in the API reference (https://api.slack.com/methods). | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =head2 Basis | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | C<WebService::Slack::WebApi::Namespace::method_name> corresponds to C<namespace.methodName> in Slack Web API. | 
| 88 |  |  |  |  |  |  | For example C<WebService::Slack::WebApi::Chat::post_message> corresponds to C<chat.postMessage>. | 
| 89 |  |  |  |  |  |  | You describe as below to call C<Chat::post_message> method. | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | my $result = $slack->chat->post_message; | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =head2 Return value | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | All methods return HashRef. | 
| 96 |  |  |  |  |  |  | When you want to know what is contained in HashRef, see the API reference. | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =head2 The token parameter | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | The API reference shows C<chat.update> method require 4 parameters: C<token>, C<ts>, C<channel> and C<text>. | 
| 101 |  |  |  |  |  |  | When using this module C<token> parameter is added implicitly except using C<oauth.access> method. | 
| 102 |  |  |  |  |  |  | So you pass the other 3 parameters to C<Chat::update> method as shown below. | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | my $result = $slack->chat->update( | 
| 105 |  |  |  |  |  |  | ts      => '1401383885.000061',  # as Str | 
| 106 |  |  |  |  |  |  | channel => 'channel id', | 
| 107 |  |  |  |  |  |  | text    => 'hoge', | 
| 108 |  |  |  |  |  |  | ); | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head2 Optional parameters | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | Some methods have optional parameters. | 
| 113 |  |  |  |  |  |  | If a parameter is optional in the API reference, it is also optional in this module. | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head2 Not primitive parameters | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | These parameters are not primitive: | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =over | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =item C<files.upload.file>: string of path to local file | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =item C<files.upload.channels>: ArrayRef of channel id string | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =back | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =over | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | =item https://api.slack.com/web | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =item https://api.slack.com/methods | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | =back | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =head1 AUTHOR | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | Mihyaeru/mihyaeru21 E<lt>mihyaeru21@gmail.comE<gt> | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =head1 LICENSE | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | Copyright (C) Mihyaeru/mihyaeru21 | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | Released under the MIT license. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | See C<LICENSE> file. | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =cut | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  |  |