Class: RubyRedtail::Query
- Inherits:
-
Object
- Object
- RubyRedtail::Query
- Defined in:
- lib/ruby-redtail/query.rb
Class Method Summary collapse
-
.run(uri, auth_hash, method, request_body = nil) ⇒ Object
TODO: Refactor (Lots of repetition).
Class Method Details
.run(uri, auth_hash, method, request_body = nil) ⇒ Object
TODO: Refactor (Lots of repetition)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby-redtail/query.rb', line 4 def self.run (uri, auth_hash, method, request_body = nil) base_uri = RubyRedtail.config.api_uri if method == "GET" @response = HTTParty.get(base_uri + uri, :headers => {"Authorization" => auth_hash, 'Content-Type' => 'text/json'}).parsed_response elsif method == "POST" @response = HTTParty.post(base_uri + uri, :headers => {"Authorization" => auth_hash, 'Content-Type' => 'text/json'}, :body => request_body.to_json).parsed_response elsif method == "PUT" @response = HTTParty.put(base_uri + uri, :headers => {"Authorization" => auth_hash, 'Content-Type' => 'text/json'}, :body => request_body.to_json).parsed_response elsif method == "DELETE" @response = HTTParty.post(base_uri + uri, :headers => {"Authorization" => auth_hash, 'Content-Type' => 'text/json'}, :body => "").parsed_response end return @response end |