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