ghgem 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/github_api.rb +136 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 07c571c0a4f7a32744e1ee28600785d89efdf1a27c23023efd847e3c437a9b77
|
4
|
+
data.tar.gz: 03f4b2a12f40851d6aa60dc292b61ffddb71da74fcdfba7e5453742ee72241d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a32f7ebdcfbf3ba556cbf734f9bc9b7acdd021f186db3b2791e93fc5bfdfb2c7cad1108be1c95327812b66bfe1865add332774db10210f006f18c00747f44c5f
|
7
|
+
data.tar.gz: b43991fd05ecd951932ec5e04073b124a81f6a750c77aa018fad9aa4fa8f90ded4260816ccd1127692a9855b3e36336c9380fcffe1d82e4b7a8bbeecb1b01edd
|
data/lib/github_api.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
require "json"
|
4
|
+
require "awesome_print"
|
5
|
+
require "rdoc/rdoc"
|
6
|
+
|
7
|
+
options = RDoc::Options.new
|
8
|
+
|
9
|
+
module GitHub_Gem
|
10
|
+
##
|
11
|
+
# -
|
12
|
+
# **GitHub Gem** main class that provides ***self*** methods.
|
13
|
+
#
|
14
|
+
class GitHubber
|
15
|
+
attr_accessor :token, :nickname
|
16
|
+
|
17
|
+
##
|
18
|
+
# -
|
19
|
+
# Add your **github token** to access GitHub API.
|
20
|
+
#
|
21
|
+
def self.add_access_token(token)
|
22
|
+
@token = token
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# -
|
27
|
+
# Get info about user. ***Requires*** nickname and password.
|
28
|
+
#
|
29
|
+
def self.get_info_about_user(name, password)
|
30
|
+
uri = URI.parse("https://api.github.com/users/#{name}")
|
31
|
+
request = Net::HTTP::Get.new(uri)
|
32
|
+
request.basic_auth(name, password)
|
33
|
+
|
34
|
+
req_options = {
|
35
|
+
use_ssl: uri.scheme == "https",
|
36
|
+
}
|
37
|
+
|
38
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
39
|
+
http.request(request)
|
40
|
+
end
|
41
|
+
|
42
|
+
ap(JSON.parse(response.body))
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# -
|
47
|
+
# List all private repoistories for **authenticated user**
|
48
|
+
#
|
49
|
+
def self.get_all_private_repositories(name, password)
|
50
|
+
uri = URI.parse("https://api.github.com/user/repos?visibility=private")
|
51
|
+
request = Net::HTTP::Get.new(uri)
|
52
|
+
request.basic_auth(name, password)
|
53
|
+
|
54
|
+
req_options = {
|
55
|
+
use_ssl: uri.scheme == "https",
|
56
|
+
}
|
57
|
+
|
58
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
59
|
+
http.request(request)
|
60
|
+
end
|
61
|
+
|
62
|
+
ap(JSON.parse(response.body))
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# -
|
67
|
+
# List public repositories for a **user**.
|
68
|
+
#
|
69
|
+
def self.get_public_repositories(nickname)
|
70
|
+
@nickname = nickname
|
71
|
+
|
72
|
+
uri = URI.parse("https://api.github.com/users/#{@nickname}/repos")
|
73
|
+
request = Net::HTTP::Get.new(uri)
|
74
|
+
request.basic_auth("#{@nickname}", "#{@token}")
|
75
|
+
|
76
|
+
req_options = {
|
77
|
+
use_ssl: uri.scheme == "https",
|
78
|
+
}
|
79
|
+
|
80
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
81
|
+
http.request(request)
|
82
|
+
end
|
83
|
+
|
84
|
+
ap(JSON.parse(response.body))
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
#
|
89
|
+
# -
|
90
|
+
#
|
91
|
+
# Create a repository for the **authenticated** user.
|
92
|
+
#
|
93
|
+
# **Params**:
|
94
|
+
#
|
95
|
+
# **Name**: The way that your repoistory will be called. That parameter is ***required***.
|
96
|
+
#
|
97
|
+
# **Description**: Description of your repository. Default: ***empty***.
|
98
|
+
#
|
99
|
+
# **Homepage**: Homepage of your repository. Default: ***empty***.
|
100
|
+
#
|
101
|
+
# **Private**: *Boolean* value. Default: ***false***. || ***false***: public || ***true***: private ||
|
102
|
+
#
|
103
|
+
# **Auto init**: Pass ***true*** to create an initial commit with empty README. Default: ***false***.
|
104
|
+
#
|
105
|
+
# **Has issues**: Either ***true*** to enable issues for this repository or ***false*** to disable them. Default: ***true***.
|
106
|
+
#
|
107
|
+
# **Has Projects**: Either ***true*** to enable projects for this repository or ***false*** to disable them. Default: ***true***.
|
108
|
+
#
|
109
|
+
# **Has Wiki**: Either ***true*** to enable the wiki for this repository or ***false*** to disable it. Default: ***true***.
|
110
|
+
#
|
111
|
+
def self.create_repository(repository_name, repository_description = "", homepage = "", private_repository = false, auto_init = false, has_issues = false, has_projects = false, has_wiki = false)
|
112
|
+
uri = URI.parse("https://api.github.com/user/repos")
|
113
|
+
request = Net::HTTP::Post.new(uri)
|
114
|
+
request.basic_auth(@nickname, @token)
|
115
|
+
request.body = JSON.dump({
|
116
|
+
"name" => repository_name,
|
117
|
+
"description" => repository_name,
|
118
|
+
"homepage" => homepage,
|
119
|
+
"private" => private_repository,
|
120
|
+
"has_issues" => has_issues,
|
121
|
+
"has_projects" => has_projects,
|
122
|
+
"has_wiki" => has_wiki,
|
123
|
+
})
|
124
|
+
|
125
|
+
req_options = {
|
126
|
+
use_ssl: uri.scheme == "https",
|
127
|
+
}
|
128
|
+
|
129
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
130
|
+
http.request(request)
|
131
|
+
end
|
132
|
+
|
133
|
+
ap(JSON.parse(response.body))
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghgem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ismail Chukmaev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/github_api.rb
|
20
|
+
homepage:
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubygems_version: 3.0.3
|
39
|
+
signing_key:
|
40
|
+
specification_version: 4
|
41
|
+
summary: 'Created for easily use github api. Required Gem - "awesome_print". GitHub
|
42
|
+
repository: "https://github.com/klautu/ghgem"'
|
43
|
+
test_files: []
|