# encoding: utf-8require'base64'require'addressable/uri'require'multi_json'moduleGithub# Defines HTTP verbsmoduleRequestMETHODS=[:get,:post,:put,:delete,:patch]METHODS_WITH_BODIES=[:post,:put,:patch]TOKEN_REQUIRED_REGEXP=[/repos\/.*\/.*\/comments/,]defget(path,params={},options={})request(:get,path,params,options)enddefpatch(path,params={},options={})request(:patch,path,params,options)enddefpost(path,params={},options={})request(:post,path,params,options)enddefput(path,params={},options={})request(:put,path,params,options)enddefdelete(path,params={},options={})request(:delete,path,params,options)enddefrequest(method,path,params,options)if!METHODS.include?(method)raiseArgumentError,"unkown http method: #{method}"end_extract_mime_type(params,options)puts"EXECUTED: #{method} - #{path} with #{params} and #{options}"ifENV['DEBUG']response=connection(options).send(method)do|request|casemethod.to_symwhen*(METHODS-METHODS_WITH_BODIES)request.url(path,params)when*METHODS_WITH_BODIESrequest.path=pathrequest.body=MultiJson.encode(_process_params(params))unlessparams.empty?endendresponse.bodyendprivatedef_process_params(params)# :nodoc:returnparams['data']ifparams.has_key?('data')&&!params['data'].nil?returnparamsenddef_extract_mime_type(params,options)# :nodoc:options['resource']=params.delete('resource')||''options['mime_type']=params.delete('mime_type')end# no need for this smizzledefformatted_path(path,options={})[path,options.fetch(:format,format)].compact.join('.')enddefbasic_auth(login,password)# :nodoc:auth=Base64.encode("#{login}:#{password}")auth.gsub!("\n","")enddeftoken_authendend# Requestend# Github