Class: Commentatr::Request
- Inherits:
-
Object
- Object
- Commentatr::Request
- Defined in:
- lib/commentatr/request.rb
Constant Summary collapse
- HOST =
"api.commentatr.net"
- PORT =
80
Instance Attribute Summary collapse
-
#get_params ⇒ Object
Returns the value of attribute get_params.
-
#method ⇒ Object
Returns the value of attribute method.
-
#post_params ⇒ Object
Returns the value of attribute post_params.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(method, uri, get_params = {}, post_params = {}) ⇒ Request
constructor
A new instance of Request.
- #make ⇒ Object
Constructor Details
#initialize(method, uri, get_params = {}, post_params = {}) ⇒ Request
Returns a new instance of Request.
9 10 11 12 |
# File 'lib/commentatr/request.rb', line 9 def initialize(method, uri, get_params = {}, post_params = {}) @method, @uri, @get_params, @post_params = method, uri, get_params, post_params @response = nil end |
Instance Attribute Details
#get_params ⇒ Object
Returns the value of attribute get_params.
6 7 8 |
# File 'lib/commentatr/request.rb', line 6 def get_params @get_params end |
#method ⇒ Object
Returns the value of attribute method.
6 7 8 |
# File 'lib/commentatr/request.rb', line 6 def method @method end |
#post_params ⇒ Object
Returns the value of attribute post_params.
6 7 8 |
# File 'lib/commentatr/request.rb', line 6 def post_params @post_params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/commentatr/request.rb', line 7 def response @response end |
#uri ⇒ Object
Returns the value of attribute uri.
6 7 8 |
# File 'lib/commentatr/request.rb', line 6 def uri @uri end |
Instance Method Details
#make ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/commentatr/request.rb', line 14 def make uri = @uri + ("?" + uri_params(@get_params) unless @get_params.empty?).to_s http = ::Net::HTTP.start(HOST, PORT) response = http.send_request(@method.to_s.upcase, uri, uri_params(@post_params)) begin body = JSON.parse(response.body) rescue body = nil end @response = Commentatr::Response.new(response.code.to_i, body) end |