summaryrefslogtreecommitdiff
path: root/lib/Net/GitHub/V3/GitData.pm
blob: f2c87b3907157b62ed67e04e4b821841322db2ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package Net::GitHub::V3::GitData;

use Moo;

our $VERSION = '0.99';
our $AUTHORITY = 'cpan:FAYLAND';

use URI::Escape;

with 'Net::GitHub::V3::Query';

## build methods on fly
my %__methods = (
    blob => { url => "/repos/%s/%s/git/blobs/%s" },
    create_blob => { url => "/repos/%s/%s/git/blobs", method => 'POST', args => 1 },

    commit => { url => "/repos/%s/%s/git/commits/%s" },
    create_commit => { url => "/repos/%s/%s/git/commits", method => 'POST', args => 1 },

    tree => { url => "/repos/%s/%s/git/trees/%s" },
    trees => { url => "/repos/%s/%s/git/trees/%s?recursive=1" },
    create_tree => { url => "/repos/%s/%s/git/trees", method => 'POST', args => 1 },

    refs => { url => "/repos/%s/%s/git/refs" },
    ref  => { url => "/repos/%s/%s/git/refs/%s" },
    create_ref => { url => "/repos/%s/%s/git/refs", method => 'POST', args => 1 },
    update_ref => { url => "/repos/%s/%s/git/refs/%s", method => 'PATCH', args => 1 },

    tag => { url => "/repos/%s/%s/git/tags/%s" },
    create_tag => { url => "/repos/%s/%s/git/tags", method => 'POST', args => 1 },

);
__build_methods(__PACKAGE__, %__methods);

no Moo;

1;
__END__

=head1 NAME

Net::GitHub::V3::GitData - GitHub Git DB API

=head1 SYNOPSIS

    use Net::GitHub::V3;

    my $gh = Net::GitHub::V3->new; # read L<Net::GitHub::V3> to set right authentication info
    my $git_data = $gh->git_data;

=head1 DESCRIPTION

B<To ease the keyboard, we provied two ways to call any method which starts with :user/:repo>

1. SET user/repos before call methods below

    $gh->set_default_user_repo('fayland', 'perl-net-github'); # take effects for all $gh->
    $git_data->set_default_user_repo('fayland', 'perl-net-github'); # only take effect to $gh->pull_request
    my $blob = $git_data->blob($sha);

2. If it is just for once, we can pass :user, :repo before any arguments

    my $blob = $git_data->blob($user, $repo, $sha);

=head2 METHODS

=head3 Git Data

L<http://developer.github.com/v3/git/>

=head3 Blob

=over 4

=item blob

    my $blob = $git_data->blob('5a1faac3ad54da26be60970ddbbdfbf6b08fdc57');

=item create_blob

    my $result = $git_data->create_blob( {
        content => $content,
        encoding => 'utf-8',
    } );

=back

=head3 Commits

L<http://developer.github.com/v3/git/commits/>

=over 4

=item commit

    my $commit = $git_data->commit('5a1faac3ad54da26be60970ddbbdfbf6b08fdc57');

=item create_commit

=back

=head3 Refs

L<http://developer.github.com/v3/git/refs/>

=over 4

=item refs

=item ref

=item create_ref

=item update_ref

    my @refs = $git_data->refs;
    my $ref  = $git_data->ref($ref_id);
    my $ref  = $git_data->create_ref($ref_data);
    my $ref  = $git_data->update_ref($ref_id, $ref_data);

=back

=head3 Tags

L<http://developer.github.com/v3/git/tags/>

=over 4

=item tag

=item create_tag

    my $tag = $git_data->tag($sha);
    my $tag = $git_data->create_tag($tag_data);

=back

=head3

L<http://developer.github.com/v3/git/trees/>

=over 4

=item tree

=item trees

=item create_tree

    my $tree = $git_data->tree($sha);
    my $trees = $git_data->trees($sha);
    my $tree = $git_data->create_tree($tree_data);

=back

=head1 AUTHOR & COPYRIGHT & LICENSE

Refer L<Net::GitHub>