Class: GitHub::Api
Instance Attribute Summary collapse
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
-
#ensure_auth(opts = {}) ⇒ Object
TODO: need to fix it in terms of options and add tests.
- #request(verb, url, data = {}) ⇒ Object
Instance Attribute Details
#auth ⇒ Object
10 11 12 |
# File 'lib/git_hub/api.rb', line 10 def auth @auth || {} end |
Instance Method Details
#authenticated? ⇒ Boolean
14 15 16 |
# File 'lib/git_hub/api.rb', line 14 def authenticated? auth != {} end |
#ensure_auth(opts = {}) ⇒ Object
TODO: need to fix it in terms of options and add tests
19 20 21 22 23 24 25 |
# File 'lib/git_hub/api.rb', line 19 def ensure_auth opts ={} return if authenticated? login = opts[:login] token = opts[:token] raise("Authentication failed") unless login && token @auth = {'login'=>login, 'token'=>token} end |
#request(verb, url, data = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/git_hub/api.rb', line 27 def request verb, url, data = {} method = ('Net::HTTP::' + verb.to_s.capitalize).to_class uri = URI.parse url server = Net::HTTP.new(uri.host, uri.port) server.use_ssl = (uri.scheme == 'https') server.verify_mode = OpenSSL::SSL::VERIFY_NONE if server.use_ssl? server.start do |http| req = method.new(uri.path) req.form_data = data.merge(auth) http.request(req) end end |