Sha256: 0a44dc7f7a5c916b89c65c5ed58111b351b346fd815b15803f20291abe48ca2d
Contents?: true
Size: 1.82 KB
Versions: 4
Compression:
Stored size: 1.82 KB
Contents
require 'net/https' require 'uri' # @return [Net::HTTPResponse] # @params [String] uri_string URI string # @params [String] authtoken def https_get(uri_string, authtoken) uri = URI.parse uri_string https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true req = Net::HTTP::Get.new(uri.path) req['Content-Type'] = 'application/json' req['Accept'] = 'application/json' req['X-Auth-Token'] = authtoken https.request(req) end # @return [Net::HTTPResponse] # @params [String] uri_string URI string # @params [Hash] payload HTTP request body # @params [String|nil] authtoken # Authtoken string or `nil`. # Can pass `nil` only on authenticating with username and password. def https_post(uri_string, payload, authtoken) uri = URI.parse uri_string https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true req = Net::HTTP::Post.new(uri.request_uri) req['Content-Type'] = 'application/json' req['Accept'] = 'application/json' req['X-Auth-Token'] = authtoken req.body = payload.to_json https.request(req) end # @return [Net::HTTPResponse] # @params [String] uri_string URI string # @params [String] authtoken def https_delete(uri_string, authtoken) uri = URI.parse uri_string https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true req = Net::HTTP::Delete.new(uri.request_uri) req['Content-Type'] = 'application/json' req['Accept'] = 'application/json' req['X-Auth-Token'] = authtoken https.request(req) end # @params [Array<String>] # The return value of `ip_address_of` method. It is either # # ["111.111.111.111", "1111:1111:1111:1111:1111:1111:1111:1111"] # # or # # ["1111:1111:1111:1111:1111:1111:1111:1111", "111.111.111.111"] # # @return [String] IPv4 address (e.g. "111.111.111.111") def ipv4(ip_address) ip_address.select { |e| e =~ /\d+\.\d+\.\d+\.\d+/ }.first end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
conoha-0.2.2 | lib/conoha/util.rb |
conoha-0.2.1 | lib/conoha/util.rb |
conoha-0.1.0 | lib/conoha/util.rb |
conoha-0.0.11 | lib/conoha/util.rb |