Class: SimpleRequest
- Inherits:
-
Object
- Object
- SimpleRequest
- Defined in:
- lib/SimpleRequest.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #clear_params ⇒ Object
- #get(format = "normal") ⇒ Object
-
#initialize ⇒ SimpleRequest
constructor
A new instance of SimpleRequest.
- #post(format = "normal") ⇒ Object
Constructor Details
#initialize ⇒ SimpleRequest
Returns a new instance of SimpleRequest.
6 7 8 |
# File 'lib/SimpleRequest.rb', line 6 def initialize @params={} end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/SimpleRequest.rb', line 4 def params @params end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/SimpleRequest.rb', line 4 def url @url end |
Instance Method Details
#clear_params ⇒ Object
33 34 35 |
# File 'lib/SimpleRequest.rb', line 33 def clear_params @params={} end |
#get(format = "normal") ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/SimpleRequest.rb', line 23 def get(format="normal") url=URI(@url) res=Net::HTTP.get(url) if format=="normal" return res elsif format=="json" return JSON.parse(res) end end |
#post(format = "normal") ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/SimpleRequest.rb', line 10 def post(format="normal") url=URI(@url) res="" http=Net::HTTP if format=="normal" res=http.post_form(url,@params) elsif format=="json" json_data=JSON.generate(@params) res=http.post_form(url,'json'=>json_data) end res.body end |