Class: Rents::Connection
- Inherits:
-
Object
- Object
- Rents::Connection
- Defined in:
- lib/rents/connection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#auth ⇒ Object
Attrs.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#end_point ⇒ Object
Returns the value of attribute end_point.
-
#end_point_versioned ⇒ Object
Returns the value of attribute end_point_versioned.
-
#path ⇒ Object
Returns the value of attribute path.
-
#request_params ⇒ Object
Returns the value of attribute request_params.
Instance Method Summary collapse
- #get_json_request ⇒ Object
-
#get_request ⇒ Object
HTTP REQUESTs METHODs ============== GET.
-
#initialize(params = {}) ⇒ Connection
constructor
Constructor.
- #post_json_request ⇒ Object
-
#post_request ⇒ Object
POST.
-
#url_requested ⇒ Object
Full URL for the last request.
Constructor Details
#initialize(params = {}) ⇒ Connection
Constructor
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rents/connection.rb', line 13 def initialize(params = {}) # Static part self.request_params = {transaction:params} setup_attrs(params) setup_config #TODO self.domain = 'localhost:7000' #'rents.pagerenter.com.br' self.domain = 'apprents.herokuapp.com' self.api_version = 'v1' self.end_point = "http://#{self.domain}/api" self.end_point_versioned = "http://#{self.domain}/api/#{self.api_version}" # Dynamic env setup_default_app unless params[:test_env].nil? end |
Instance Attribute Details
#api_version ⇒ Object
Returns the value of attribute api_version.
8 9 10 |
# File 'lib/rents/connection.rb', line 8 def api_version @api_version end |
#auth ⇒ Object
Attrs
4 5 6 |
# File 'lib/rents/connection.rb', line 4 def auth @auth end |
#domain ⇒ Object
Returns the value of attribute domain.
6 7 8 |
# File 'lib/rents/connection.rb', line 6 def domain @domain end |
#end_point ⇒ Object
Returns the value of attribute end_point.
7 8 9 |
# File 'lib/rents/connection.rb', line 7 def end_point @end_point end |
#end_point_versioned ⇒ Object
Returns the value of attribute end_point_versioned.
10 11 12 |
# File 'lib/rents/connection.rb', line 10 def end_point_versioned @end_point_versioned end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/rents/connection.rb', line 5 def path @path end |
#request_params ⇒ Object
Returns the value of attribute request_params.
9 10 11 |
# File 'lib/rents/connection.rb', line 9 def request_params @request_params end |
Instance Method Details
#get_json_request ⇒ Object
39 40 41 |
# File 'lib/rents/connection.rb', line 39 def get_json_request return JSON.parse(RestClient.get(self.url_requested)).it_keys_to_sym end |
#get_request ⇒ Object
HTTP REQUESTs METHODs ==============
GET
35 36 37 |
# File 'lib/rents/connection.rb', line 35 def get_request RestClient.get self.url_requested end |
#post_json_request ⇒ Object
48 49 50 |
# File 'lib/rents/connection.rb', line 48 def post_json_request return JSON.parse(RestClient.post(self.url_requested, self.request_params)).it_keys_to_sym end |
#post_request ⇒ Object
POST
44 45 46 |
# File 'lib/rents/connection.rb', line 44 def post_request RestClient.post self.url_requested, self.request_params end |
#url_requested ⇒ Object
Full URL for the last request
29 30 31 |
# File 'lib/rents/connection.rb', line 29 def url_requested "#{self.end_point}/#{self.api_version}/#{self.path}" end |