Class: Rents::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/rents/connection.rb

Direct Known Subclasses

Status, Transaction

Instance Attribute Summary collapse

Instance Method Summary collapse

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_versionObject

Returns the value of attribute api_version.



8
9
10
# File 'lib/rents/connection.rb', line 8

def api_version
  @api_version
end

#authObject

Attrs



4
5
6
# File 'lib/rents/connection.rb', line 4

def auth
  @auth
end

#domainObject

Returns the value of attribute domain.



6
7
8
# File 'lib/rents/connection.rb', line 6

def domain
  @domain
end

#end_pointObject

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_versionedObject

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

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/rents/connection.rb', line 5

def path
  @path
end

#request_paramsObject

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_requestObject



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_requestObject

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_requestObject



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_requestObject

POST



44
45
46
# File 'lib/rents/connection.rb', line 44

def post_request
  RestClient.post self.url_requested, self.request_params
end

#url_requestedObject

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