Skip to content

Commit

Permalink
[redirects] fetch_uri is a private method
Browse files Browse the repository at this point in the history
  • Loading branch information
portertech committed Dec 25, 2012
1 parent 3639d65 commit d8ad3f1
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/carrot-top.rb
Expand Up @@ -19,6 +19,22 @@ def initialize(options={})
@rabbitmq_api = "#{protocol}://#{credentials}@#{location}/api"
end

def query_api(options={})
raise ArgumentError, "You must supply an API path" if options[:path].nil?
fetch_uri(@rabbitmq_api + options[:path])
end

def method_missing(method, *args, &block)
response = self.query_api(:path => "/#{method}")
begin
JSON.parse(response.body)
rescue JSON::ParserError
Hash.new
end
end

private

def fetch_uri(uri, limit=5)
raise ArgumentError, "HTTP redirect too deep" if limit == 0
url = URI.parse(uri)
Expand All @@ -44,17 +60,4 @@ def fetch_uri(uri, limit=5)
end
end

def query_api(options={})
raise ArgumentError, "You must supply an API path" if options[:path].nil?
fetch_uri(@rabbitmq_api + options[:path])
end

def method_missing(method, *args, &block)
response = self.query_api(:path => "/#{method}")
begin
JSON.parse(response.body)
rescue JSON::ParserError
Hash.new
end
end
end

0 comments on commit d8ad3f1

Please sign in to comment.