Class: Grendel::Client
- Inherits:
-
Object
- Object
- Grendel::Client
- Defined in:
- lib/grendel/client.rb
Defined Under Namespace
Classes: HTTPException
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#debug_output ⇒ Object
Returns the value of attribute debug_output.
Instance Method Summary collapse
- #delete(uri, options = {}) ⇒ Object
- #get(uri, options = {}) ⇒ Object
-
#initialize(base_uri, options = {}) ⇒ Client
constructor
Create a new Grendel client instance.
- #post(uri, data = {}, options = {}) ⇒ Object
- #put(uri, data = {}, options = {}) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(base_uri, options = {}) ⇒ Client
Create a new Grendel client instance
8 9 10 11 12 |
# File 'lib/grendel/client.rb', line 8 def initialize(base_uri, = {}) @base_uri = base_uri @debug = [:debug] @debug_output = [:debug_output] || $stderr end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
5 6 7 |
# File 'lib/grendel/client.rb', line 5 def base_uri @base_uri end |
#debug ⇒ Object
Returns the value of attribute debug.
4 5 6 |
# File 'lib/grendel/client.rb', line 4 def debug @debug end |
#debug_output ⇒ Object
Returns the value of attribute debug_output.
4 5 6 |
# File 'lib/grendel/client.rb', line 4 def debug_output @debug_output end |
Instance Method Details
#delete(uri, options = {}) ⇒ Object
45 46 47 48 49 |
# File 'lib/grendel/client.rb', line 45 def delete(uri, = {}) .merge!(:debug_output => @debug_output) if @debug response = HTTParty.delete(@base_uri + uri, ) raise HTTPException.new(response) if response.code >= 400 end |
#get(uri, options = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/grendel/client.rb', line 14 def get(uri, = {}) .merge!(:debug_output => @debug_output) if @debug response = HTTParty.get(@base_uri + uri, ) raise HTTPException.new(response) if response.code >= 400 return response end |
#post(uri, data = {}, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/grendel/client.rb', line 21 def post(uri, data = {}, = {}) data = data.to_json unless .delete(:raw_data) .merge!( :body => data, :headers => {'Content-Type' => 'application/json'} ) .merge!(:debug_output => @debug_output) if @debug response = HTTParty.post(@base_uri + uri, ) raise HTTPException.new(response) if response.code >= 400 return response end |
#put(uri, data = {}, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/grendel/client.rb', line 33 def put(uri, data = {}, = {}) data = data.to_json unless .delete(:raw_data) = { :body => data, :headers => {'Content-Type' => 'application/json'} }.update() .merge!(:debug_output => @debug_output) if @debug response = HTTParty.put(@base_uri + uri, ) raise HTTPException.new(response) if response.code >= 400 return response end |
#users ⇒ Object
51 52 53 |
# File 'lib/grendel/client.rb', line 51 def users UserManager.new(self) end |