Class: BasicAuthHTTP
- Inherits:
-
Object
- Object
- BasicAuthHTTP
- Defined in:
- lib/basic_auth_http.rb
Instance Method Summary collapse
- #get_request(url = nil, extra_fields = nil, auth = true) ⇒ Object
- #get_user ⇒ Object
-
#initialize(user = nil, password = nil) ⇒ BasicAuthHTTP
constructor
A new instance of BasicAuthHTTP.
Constructor Details
#initialize(user = nil, password = nil) ⇒ BasicAuthHTTP
Returns a new instance of BasicAuthHTTP.
8 9 10 11 |
# File 'lib/basic_auth_http.rb', line 8 def initialize user=nil, password=nil @username = user # Rails.application.credentials.github_api_user @password = password # Rails.application.credentials.github_api_token end |
Instance Method Details
#get_request(url = nil, extra_fields = nil, auth = true) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/basic_auth_http.rb', line 17 def get_request url=nil, extra_fields=nil, auth=true if not url.nil? @uri = URI.parse(url) http = Net::HTTP.new(@uri.host, @uri.port) req = Net::HTTP::Get.new(@uri.request_uri) http.use_ssl = (@uri.scheme == "https") if not extra_fields.nil? extra_fields.each do |header| req.add_field(header['field'], header['field_value']) end end if auth req.basic_auth(@username, @password) end res = http.request(req) return res else return nil end end |
#get_user ⇒ Object
13 14 15 |
# File 'lib/basic_auth_http.rb', line 13 def get_user return @username end |