Class: GnipApi::Request
- Inherits:
-
Object
- Object
- GnipApi::Request
- Defined in:
- lib/gnip_api/request.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
- .new_delete(uri, payload, headers = nil) ⇒ Object
- .new_get(uri, headers = nil) ⇒ Object
- .new_post(uri, payload, headers = nil) ⇒ Object
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(params = {}) ⇒ Request
constructor
A new instance of Request.
- #log! ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Request
19 20 21 22 23 24 25 |
# File 'lib/gnip_api/request.rb', line 19 def initialize params={} @uri = params[:uri] @payload = params[:payload] @headers = params[:headers] @request_method = params[:request_method] @adapter = GnipApi::Adapter.new end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/gnip_api/request.rb', line 3 def headers @headers end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
3 4 5 |
# File 'lib/gnip_api/request.rb', line 3 def payload @payload end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
3 4 5 |
# File 'lib/gnip_api/request.rb', line 3 def request_method @request_method end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
3 4 5 |
# File 'lib/gnip_api/request.rb', line 3 def uri @uri end |
Class Method Details
.new_delete(uri, payload, headers = nil) ⇒ Object
14 15 16 |
# File 'lib/gnip_api/request.rb', line 14 def new_delete uri, payload, headers=nil new(:uri => uri, :headers => headers, :payload => payload, :request_method => GnipApi::Adapter::POST) end |
.new_get(uri, headers = nil) ⇒ Object
6 7 8 |
# File 'lib/gnip_api/request.rb', line 6 def new_get uri, headers=nil new(:uri => uri, :headers => headers, :request_method => GnipApi::Adapter::GET) end |
.new_post(uri, payload, headers = nil) ⇒ Object
10 11 12 |
# File 'lib/gnip_api/request.rb', line 10 def new_post uri, payload, headers=nil new(:uri => uri, :headers => headers, :payload => payload, :request_method => GnipApi::Adapter::POST) end |
Instance Method Details
#execute! ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gnip_api/request.rb', line 27 def execute! log! case request_method when GnipApi::Adapter::GET response = @adapter.get(self) when GnipApi::Adapter::POST response = @adapter.post(self) when GnipApi::Adapter::DELETE response = @adapter.delete(self) else raise 'RequestNotAllowed' end response.check_for_errors! return response.body unless response.body.empty? return true end |
#log! ⇒ Object
44 45 46 47 48 |
# File 'lib/gnip_api/request.rb', line 44 def log! GnipApi.logger.info "Starting #{request_method} request to #{uri}" GnipApi.logger.debug "Headers -> #{headers.inspect}" GnipApi.logger.debug "Payload -> #{payload.inspect}" end |