| 1 | package Net::OneSky; | ||||||||||||||||||||
| 2 | 8 | $Net::OneSky::VERSION = '0.0.1'; | |||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 8 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 8 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 8 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 8 | ▶ | use HTTP::Request::Common qw(GET POST); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 8 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 8 | ▶ | use Net::OneSky::Project; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 8 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 8 | ▶ | use Time::Local; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # Do not specify version in the base URL, to allow clients to specify as needed | ||||||||||||||||||||
| 20 | 8 | ▶ | use constant BASE_URL => URI->new('https://platform.api.onesky.io/'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 8 | has 'api_key' => ( | |||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||
| 24 | isa => 'Str', | ||||||||||||||||||||
| 25 | required => 1 | ||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 8 | has 'api_secret' => ( | |||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||
| 30 | isa => 'Str', | ||||||||||||||||||||
| 31 | required => 1 | ||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | has 'base_url' => ( | ||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||
| 36 | isa => 'URI', | ||||||||||||||||||||
| 37 | required => 1, | ||||||||||||||||||||
| 38 | 6 | ▶ | default => sub { BASE_URL } # must be a sub even though it is a constant | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | 8 | ); | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | sub project { | ||||||||||||||||||||
| 43 | 3 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
project: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 44 | 3 | my $id = shift; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 3 | return new Net::OneSky::Project(id => $id, client => $self); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | sub get { | ||||||||||||||||||||
| 51 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 52 | 2 | my $uri = shift; | |||||||||||||||||||
| 53 | 2 | ▶ | my $data = shift || []; | ||||||||||||||||||
|
Condition50%1/2
shift() || []
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 2 | $data = $self->authenticate($data); | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 2 | $uri = URI->new_abs($uri, $self->{base_url}); | |||||||||||||||||||
| 58 | 2 | $uri->query_form(@$data); | |||||||||||||||||||
| 59 | 2 | my $req = GET($uri); | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 2 | return $self->user_agent->request($req); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | sub file_upload { | ||||||||||||||||||||
| 66 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
file_upload: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 67 | 1 | my $uri = shift; | |||||||||||||||||||
| 68 | 1 | my $data = shift; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 1 | $data = $self->authenticate($data); | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 1 | my $req = POST(URI->new_abs($uri, $self->{base_url}), | |||||||||||||||||||
| 73 | Content_Type => 'form-data', | ||||||||||||||||||||
| 74 | Content => $data); | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 1 | return $self->user_agent->request($req); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | sub user_agent { | ||||||||||||||||||||
| 81 | 3 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
user_agent: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 3 | ▶ | $self->{_user_agent} ||= LWP::UserAgent->new; | ||||||||||||||||||
|
Condition33%1/3
$self->{"_user_agent"} ||= "LWP::UserAgent"->new
MC/DC0%0/2
$self->{"_user_agent"} ||= "LWP::UserAgent"->new
$self->{"_user_agent"}
"LWP::UserAgent"->new
Truth table33%1/3
A ||= B
A= $self->{"_user_agent"}B= "LWP::UserAgent"->new
| |||||||||||||||||||||
| 84 | 3 | my $v = $self->version_string; | |||||||||||||||||||
| 85 | 3 | $self->{_user_agent}->agent("Net::OneSky [$v] "); | |||||||||||||||||||
| 86 | 3 | return $self->{_user_agent}; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | sub version_string { | ||||||||||||||||||||
| 91 | 3 | ▶ | return $Net::OneSky::VERSION || `git rev-parse --short HEAD` | ||||||||||||||||||
|
Subroutine
version_string: called CC=2 SCAR=9.2
Pod
undocumented
Condition33%1/3
$Net::OneSky::VERSION || `git rev-parse --short HEAD`
MC/DC0%0/2
$Net::OneSky::VERSION || `git rev-parse --short HEAD`
$Net::OneSky::VERSION
`git rev-parse --short HEAD`
Truth table33%1/3
A || B
A= $Net::OneSky::VERSIONB= `git rev-parse --short HEAD`
| |||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | sub authenticate { | ||||||||||||||||||||
| 96 | 3 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
authenticate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 97 | 3 | my $data = shift; | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | # copy it | ||||||||||||||||||||
| 100 | 3 | $data = [@$data]; | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 3 | my $timestamp = timegm(gmtime(time)); | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 3 | push(@$data, | |||||||||||||||||||
| 105 | api_key => $self->api_key, | ||||||||||||||||||||
| 106 | timestamp => $timestamp, | ||||||||||||||||||||
| 107 | dev_hash => md5_hex($timestamp . $self->api_secret) | ||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 3 | return $data; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 8 | __PACKAGE__->meta->make_immutable(inline_constructor => 0); | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | # ABSTRACT: Simple interface to the OneSky API: http://developer.oneskyapp.com/ | ||||||||||||||||||||
| 116 | 8 | 1; | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =pod | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =encoding UTF-8 | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =head1 NAME | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | Net::OneSky - Simple interface to the OneSky API: http://developer.oneskyapp.com/ | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =head1 VERSION | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | version 0.0.1 | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =head1 SYNOPSIS | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | use Net::OneSky; | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | my $client = Net::OneSky->new(api_key => $key, api_secret => $secret); | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | my $response = $client->get('/1/locales'); | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | my $project = $client->project($project_id); | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | my @languages = $project->locales | ||||||||||||||||||||
| 143 | my @files = $project->list_files | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | $project->upload_file($filename, $file_format, $locale); | ||||||||||||||||||||
| 146 | my $file = $project->export_file($locale, $remote_file, $local_file_name, $block_until_finished) | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =head1 METHODS | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =head2 project($project_id) | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | Returns a Net::OneSky::Project object for the given $project_id | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | =head2 get($uri, $query_data) | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | GET an authenticated API request. | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | =head2 file_upload($uri, $post_data) | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | POST an authenticated File upload request. $post_data should be a standard | ||||||||||||||||||||
| 161 | format for a file-upload. More information | ||||||||||||||||||||
| 162 | L<in the LWP Cookbook|http://search.cpan.org/~ether/HTTP-Message-6.11/lib/HTTP/Request/Common.pm#POST> | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | =head2 authenticate($data) | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | Returns a new data object with authentication params added. | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | =head1 AUTHOR | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | Erik Ogan <erik@change.org> | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | This software is copyright (c) 2016-2018 by Change.org. | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 177 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | =cut | ||||||||||||||||||||