Module: Veye::API::Github
- Defined in:
- lib/veye/api/github.rb
Overview
Api wrappers for Github endpoint
Constant Summary collapse
- RESOURCE_PATH =
'/github'
Class Method Summary collapse
- .delete_repo(api_key, repo_name, branch = nil) ⇒ Object
- .encode_repo_key(repo_key) ⇒ Object
- .get_list(api_key, page = 1, lang = nil, privat = nil, org = nil, type = nil) ⇒ Object
- .get_repo(api_key, repo_name, branch = nil, file = nil) ⇒ Object
- .import_all(api_key, force = false) ⇒ Object
- .import_repo(api_key, repo_name, branch = nil, filename = nil) ⇒ Object
Class Method Details
.delete_repo(api_key, repo_name, branch = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/veye/api/github.rb', line 65 def self.delete_repo(api_key, repo_name, branch = nil) safe_repo_key = encode_repo_key(repo_name) qparams = { api_key: api_key } qparams[:branch] = branch unless branch.nil? github_api = Resource.new("#{RESOURCE_PATH}/#{safe_repo_key}") github_api.resource.delete({params: qparams}) do |response, request, result| JSONResponse.new(request, result, response) end end |
.encode_repo_key(repo_key) ⇒ Object
6 7 8 |
# File 'lib/veye/api/github.rb', line 6 def self.encode_repo_key(repo_key) repo_key.to_s.gsub(/\//, ':').gsub(/\./, '~') end |
.get_list(api_key, page = 1, lang = nil, privat = nil, org = nil, type = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/veye/api/github.rb', line 10 def self.get_list(api_key, page = 1, lang = nil, privat = nil, org = nil, type = nil) params = { api_key: api_key, page: page || 1 } params[:lang] = lang.to_s.downcase if lang unless private.nil? params[:private] = privat == 'true' || privat == 't' || privat == true end params[:org_name] = org if org params[:org_type] = type if type github_api = Resource.new(RESOURCE_PATH) qparams = { params: params } github_api.resource.get(qparams) do |response, request, result| JSONResponse.new(request, result, response) end end |
.get_repo(api_key, repo_name, branch = nil, file = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/veye/api/github.rb', line 40 def self.get_repo(api_key, repo_name, branch = nil, file = nil) safe_repo_name = encode_repo_key(repo_name) github_api = Resource.new("#{RESOURCE_PATH}/#{safe_repo_name}") qparams = { api_key: api_key } qparams[:branch] = branch unless branch.nil? qparams[:file] = file unless file.nil? github_api.resource.get({ params: qparams }) do |response, request, result| JSONResponse.new(request, result, response) end end |
.import_all(api_key, force = false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/veye/api/github.rb', line 29 def self.import_all(api_key, force = false) params = { api_key: api_key } params[:force] = force || false qparams = { params: params } github_api = Resource.new("#{RESOURCE_PATH}/sync") github_api.resource.get(qparams) do |response, request, result| JSONResponse.new(request, result, response) end end |
.import_repo(api_key, repo_name, branch = nil, filename = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/veye/api/github.rb', line 52 def self.import_repo(api_key, repo_name, branch = nil, filename = nil) safe_repo_name = encode_repo_key(repo_name) github_api = Resource.new("#{RESOURCE_PATH}/#{safe_repo_name}") params = { api_key: api_key } params[:branch] = branch unless branch.nil? params[:file] = filename unless filename.nil? github_api.resource.post(params) do |response, request, result| JSONResponse.new(request, result, response) end end |