Module: URI

Defined in:
lib/overwrite.rb

Class Method Summary collapse

Class Method Details

.accessible?(uri) ⇒ Boolean

Returns checks if resource exists by making a HEAD-request

Returns:

  • (Boolean)

    checks if resource exists by making a HEAD-request


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/overwrite.rb', line 100

def self.accessible?(uri)
  parsed_uri = URI.parse(uri + (OpenTox::RestClientWrapper.subjectid ? "?subjectid=#{CGI.escape OpenTox::RestClientWrapper.subjectid}" : ""))
  http_code = URI.task?(uri) ? 600 : 400
  http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
  unless (URI.ssl? uri) == true
    http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
    request = Net::HTTP::Head.new(parsed_uri.request_uri)
    http.request(request).code.to_i < http_code
  else
    http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    request = Net::HTTP::Head.new(parsed_uri.request_uri)
    http.request(request).code.to_i < http_code
  end
rescue
  false
end

.compound?(uri) ⇒ Boolean

Returns:

  • (Boolean)

79
80
81
# File 'lib/overwrite.rb', line 79

def self.compound? uri
  uri =~ /compound/ and URI.valid? uri
end

.dataset?(uri) ⇒ Boolean

Returns:

  • (Boolean)

87
88
89
# File 'lib/overwrite.rb', line 87

def self.dataset? uri
  uri =~ /dataset/ and URI.accessible? uri
end

.model?(uri) ⇒ Boolean

Returns:

  • (Boolean)

91
92
93
# File 'lib/overwrite.rb', line 91

def self.model? uri
  uri =~ /model/ and URI.accessible? uri
end

.ssl?(uri) ⇒ Boolean

Returns:

  • (Boolean)

95
96
97
# File 'lib/overwrite.rb', line 95

def self.ssl? uri
  URI.parse(uri).instance_of? URI::HTTPS
end

.task?(uri) ⇒ Boolean

Returns:

  • (Boolean)

83
84
85
# File 'lib/overwrite.rb', line 83

def self.task? uri
  uri =~ /task/ and URI.valid? uri
end

.valid?(uri) ⇒ Boolean

Returns:

  • (Boolean)

119
120
121
122
123
124
# File 'lib/overwrite.rb', line 119

def self.valid? uri
  u = URI.parse(uri)
  u.scheme!=nil and u.host!=nil
rescue URI::InvalidURIError
  false
end