forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblobs.rb
More file actions
54 lines (45 loc) · 1.58 KB
/
Copy pathblobs.rb
File metadata and controls
54 lines (45 loc) · 1.58 KB
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
# encoding: utf-8
module Github
class GitData::Blobs < API
# Since blobs can be any arbitrary binary data, the input and responses for
# the blob api takes an encoding parameter that can be either utf-8 or base64.
# If your data cannot be losslessly sent as a UTF-8 string, you can base64 encode it.
VALID_BLOB_PARAM_NAMES = %w[ content encoding ].freeze
# Creates new GitData::Blobs API
def initialize(options = {})
super(options)
end
# Get a blob
#
# = Examples
# github = Github.new
# github.git_data.blobs.get 'user-name', 'repo-name', 'sha'
#
def get(user_name, repo_name, sha, params={})
set :user => user_name, :repo => repo_name
assert_presence_of user, repo, sha
normalize! params
get_request("/repos/#{user}/#{repo}/git/blobs/#{sha}", params)
end
alias :find :get
# Create a blob
#
# = Inputs
# * <tt>:content</tt> - String of content
# * <tt>:encoding</tt> - String containing encoding<tt>utf-8</tt> or <tt>base64</tt>
# = Examples
# github = Github.new
# github.git_data.blobs.create 'user-name', 'repo-name',
# "content" => "Content of the blob",
# "encoding" => "utf-8"
#
def create(user_name, repo_name, params={})
set :user => user_name, :repo => repo_name
assert_presence_of user, repo
normalize! params
filter! VALID_BLOB_PARAM_NAMES, params
assert_required_keys(VALID_BLOB_PARAM_NAMES, params)
post_request("/repos/#{user}/#{repo}/git/blobs", params)
end
end # GitData::Blobs
end # Github