Class: Broadway::Uri

Inherits:
Object
  • Object
show all
Defined in:
lib/broadway/resources/uri.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, query = {}) ⇒ Uri

Returns a new instance of Uri.



3
4
5
6
7
8
9
10
11
# File 'lib/broadway/resources/uri.rb', line 3

def initialize(url, query = {})
  unless query.blank?
    url << "?" unless url =~ /\?/
    url << query.map do |k, v|
      url << "#{k}=#{v}"
    end.join("&")
  end
  @uri = URI.parse(url)
end

Instance Method Details

#hostObject



25
26
27
# File 'lib/broadway/resources/uri.rb', line 25

def host
  uri.host
end

#http?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/broadway/resources/uri.rb', line 29

def http?
  scheme == "http"
end

#https?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/broadway/resources/uri.rb', line 33

def https?
  scheme == "https"
end

#pathObject



21
22
23
# File 'lib/broadway/resources/uri.rb', line 21

def path
  uri.path
end

#queryObject



41
42
43
# File 'lib/broadway/resources/uri.rb', line 41

def query
  uri.query
end

#query_hashObject



45
46
47
# File 'lib/broadway/resources/uri.rb', line 45

def query_hash
  @query_hash ||= Broadway::Utils.parse_query(query)
end

#schemeObject



37
38
39
# File 'lib/broadway/resources/uri.rb', line 37

def scheme
  uri.scheme
end

#to_sObject



17
18
19
# File 'lib/broadway/resources/uri.rb', line 17

def to_s
  url
end

#urlObject



13
14
15
# File 'lib/broadway/resources/uri.rb', line 13

def url
  @uri.to_s
end