Class: PortfolioManager::REST::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/portfolio_manager/rest/request.rb

Overview

Manage HTTP requests

Constant Summary collapse

BASE_URL =
'https://portfoliomanager.energystar.gov'
LIVE_PATH =
'/ws'
TEST_PATH =
'/wstest'
CONTENT_TYPE =
'application/xml'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, request_method, path, options) ⇒ Request

Returns a new instance of Request.

Parameters:

  • client (PortfolioManager::Client)
  • request_method (Symbol, String)
  • path (String)
  • options (Hash)

    used for creating query params and headers


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/portfolio_manager/rest/request.rb', line 25

def initialize(client, request_method, path, options)
  @client = client
  @path = api_environment + path
  @options = options
  @request_method = request_method
  @conn = Faraday.new(url: BASE_URL) do |conn|
    conn.request :authorization, :basic, client.username, client.password
    conn.request :xml
  end
  @parser = Nori.new
  setup_client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.


17
18
19
# File 'lib/portfolio_manager/rest/request.rb', line 17

def client
  @client
end

#optionsObject

Returns the value of attribute options.


18
19
20
# File 'lib/portfolio_manager/rest/request.rb', line 18

def options
  @options
end

#parserObject (readonly)

Returns the value of attribute parser.


17
18
19
# File 'lib/portfolio_manager/rest/request.rb', line 17

def parser
  @parser
end

#pathObject (readonly)

Returns the value of attribute path.


17
18
19
# File 'lib/portfolio_manager/rest/request.rb', line 17

def path
  @path
end

#request_methodObject (readonly)

Returns the value of attribute request_method.


17
18
19
# File 'lib/portfolio_manager/rest/request.rb', line 17

def request_method
  @request_method
end

Instance Method Details

#performHash

Returns:

  • (Hash)

40
41
42
# File 'lib/portfolio_manager/rest/request.rb', line 40

def perform
  parser.parse(response_body)
end