Changeset 13e2400 in lab.git for Dev/github/GitHubBackup.pm
- Timestamp:
- Aug 21, 2013 4:44:27 PM (11 years ago)
- Branches:
- master
- Children:
- 4351b0c
- Parents:
- f7f894d
- git-author:
- Ken-ichi Mito <mitty@…> (08/21/13 16:38:15)
- git-committer:
- Ken-ichi Mito <mitty@…> (08/21/13 16:44:27)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/github/GitHubBackup.pm
rf7f894d r13e2400 1 package utils;1 package GitHubBackup::API; 2 2 use strict; 3 3 use warnings; … … 8 8 use JSON; 9 9 10 sub new { 11 my $class = shift; 12 my $args = shift; 13 14 return bless $args, $class; 15 } 16 10 17 sub json_api { 11 my $url = shift; 18 my $self = shift; 19 my $url = shift; 12 20 13 21 my $ua = LWP::UserAgent->new; … … 24 32 25 33 sub get { 26 my $url = shift; 34 my $self = shift; 35 my $url = shift; 27 36 my %parameters = @_; 28 37 … … 35 44 my $data = []; 36 45 while(1) { 37 my $result = json_api("$url?per_page=100&page=$page$parameters");46 my $result = $self->json_api("$url?per_page=100&page=$page$parameters"); 38 47 if (ref($result) eq 'ARRAY' && scalar @$result > 0) { 39 48 push @$data, @$result; … … 48 57 } 49 58 59 sub access_token { 60 my $self = shift; 61 62 return $self->{access_token}->(); 63 } 64 65 50 66 package GitHubBackup; 51 67 … … 100 116 } 101 117 118 sub access_token { 119 my $self = shift; 120 my $args = shift; 121 122 if (defined $args) { 123 $self->{access_token} = $args; 124 } 125 126 return $self->{access_token}; 127 } 128 129 sub api { 130 my $self = shift; 131 132 unless ($self->{api}) { 133 $self->{api} = GitHubBackup::API->new({ 134 access_token => sub {$self->access_token}, 135 }); 136 } 137 138 return $self->{api}; 139 } 140 102 141 sub repos { 103 142 my $self = shift; … … 109 148 my $result; 110 149 if (my $repository = $self->repository) { 111 $result = [ utils::json_api("/repos/$account/$repository") ];150 $result = [ $self->api->json_api("/repos/$account/$repository") ]; 112 151 } 113 152 else { 114 $result = utils::get("/users/$account/repos");153 $result = $self->api->get("/users/$account/repos"); 115 154 } 116 155 … … 119 158 GitHubBackup::Repository->new({ 120 159 directory => sub {$self->directory}, 160 api => sub {$self->api}, 121 161 repos => $repos, 122 162 }) … … 194 234 } 195 235 236 sub api { 237 my $self = shift; 238 239 return $self->{api}->(); 240 } 241 196 242 sub message { 197 243 my $self = shift; … … 237 283 return $self->{forks} if ($self->{forks}); 238 284 239 $self->{forks} = utils::get("/repos/" . $self->full_name . "/forks");285 $self->{forks} = $self->api->get("/repos/" . $self->full_name . "/forks"); 240 286 241 287 return $self->{forks}; … … 292 338 return $self->{issues} if ($self->{issues}); 293 339 294 my $open = utils::get("/repos/" . $self->full_name . "/issues");295 my $closed = utils::get("/repos/" . $self->full_name . "/issues", state => 'closed');340 my $open = $self->api->get("/repos/" . $self->full_name . "/issues"); 341 my $closed = $self->api->get("/repos/" . $self->full_name . "/issues", state => 'closed'); 296 342 297 343 if ($open) { push @{$self->{issues}}, @$open }
Note: See TracChangeset
for help on using the changeset viewer.