class Codingapi::Giteeinterface
Your code goes hereā¦
Attributes
token[RW]
Gets or sets the path that the Faraday libs are loaded from. @return [String]
username[RW]
Public Class Methods
new(username: nil, token: nil)
click to toggle source
# File lib/codingapi/giteeinterface.rb, line 19 def initialize(username: nil, token: nil) @username = username @token = token puts "username = #{@username}" puts "token = #{@token}" return self end
Public Instance Methods
create_repo(owner:nil, repo_name:nil)
click to toggle source
# File lib/codingapi/giteeinterface.rb, line 28 def create_repo(owner:nil, repo_name:nil) base_url = "https://gitee.com" con = Faraday.new token_str = %Q{"access_token": "#{@token}",} name_str = %Q{"name": "#{repo_name}",} body_str = '{ ' + token_str + name_str + '"has_issues": true, "has_wiki": true, "private": "true", "auto_init":false' + '}' url = base_url + "/api/v5/orgs/#{owner}/repos" puts "#{body_str}" puts "#{url}" res = con.post do |req| req.url url req.headers['Content-Type'] = 'application/json' req.body = body_str end if res.body['error'].nil? && res.status == 200 puts "Create success !!!" elsif res.status == 422 puts "Already exist !!!" else puts "failed !!!" end return res.status end
get_orgs_repo_list(org:nil, page: 1, per_page:20, type:"all")
click to toggle source
# File lib/codingapi/giteeinterface.rb, line 81 def get_orgs_repo_list(org:nil, page: 1, per_page:20, type:"all") base_url = "https://gitee.com" con = Faraday.new url = base_url + "/api/v5/orgs/#{org}/repos" puts "#{url}" res = con.get do |req| req.url url req.headers['Content-Type'] = 'application/json' req.params['access_token'] = @token req.params['org'] = org req.params['page'] = page req.params['per_page'] = per_page req.params['type'] = type end if res.status == 200 response = JSON.parse(res.body) return response else return nil end end
get_repo_breanch_info(owner:nil, repo_name:nil)
click to toggle source
# File lib/codingapi/giteeinterface.rb, line 107 def get_repo_breanch_info(owner:nil, repo_name:nil) base_url = "https://gitee.com" con = Faraday.new url = base_url + "/api/v5/repos/#{owner}/#{repo_name}/branches" puts "#{url}" res = con.get do |req| req.url url req.headers['Content-Type'] = 'application/json' req.params['access_token'] = @token end puts res.status puts res.body if res.status == 200 response = JSON.parse(res.body) return response else return nil end end
get_repo_info(owner:nil, repo_name:nil)
click to toggle source
# File lib/codingapi/giteeinterface.rb, line 60 def get_repo_info(owner:nil, repo_name:nil) base_url = "https://gitee.com" con = Faraday.new url = base_url + "/api/v5/repos/#{owner}/#{repo_name}" puts "#{url}" res = con.get do |req| req.url url req.headers['Content-Type'] = 'application/json' req.params['access_token'] = @token end if res.status == 200 response = JSON.parse(res.body) return response else return nil end end