class PortfolioManager::REST::Request
Manage HTTP requests
Constants
- BASE_URL
- CONTENT_TYPE
- LIVE_PATH
- TEST_PATH
Attributes
client[R]
options[RW]
parser[R]
path[R]
request_method[R]
Public Class Methods
new(client, request_method, path, options)
click to toggle source
@param [PortfolioManager::Client] client @param [Symbol, String] request_method
@param [String] path @param [Hash] options used for creating query params and headers
# File lib/portfolio_manager/rest/request.rb, line 21 def initialize(client, request_method, path, options) @client = client @path = api_environment + path @options = options @request_method = request_method @conn = Hurley::Client.new(BASE_URL) @parser = Nori.new setup_client end
Public Instance Methods
perform()
click to toggle source
@return [Hash]
# File lib/portfolio_manager/rest/request.rb, line 33 def perform parser.parse(response_body) end
Private Instance Methods
api_environment()
click to toggle source
# File lib/portfolio_manager/rest/request.rb, line 76 def api_environment if client.live LIVE_PATH else TEST_PATH end end
response_body()
click to toggle source
@return [String]
# File lib/portfolio_manager/rest/request.rb, line 41 def response_body case request_method when :get @conn.get(path).body when :post @conn.post(path, options[:body], CONTENT_TYPE).body else raise ArgumentError, '#{request_method} is not yet implemented' end end
set_basic_authentication()
click to toggle source
# File lib/portfolio_manager/rest/request.rb, line 71 def set_basic_authentication @conn.url.user = client.username @conn.url.password = client.password end
set_header()
click to toggle source
# File lib/portfolio_manager/rest/request.rb, line 58 def set_header @conn.header[:user_agent] = 'Ruby PortfolioManager API Client' options[:header].each do |key, value| @conn.header[key] = value end unless options[:header].nil? end
set_query()
click to toggle source
# File lib/portfolio_manager/rest/request.rb, line 65 def set_query options[:query].each do |key, value| @conn.query[key] = value end unless options[:query].nil? end
setup_client()
click to toggle source
# File lib/portfolio_manager/rest/request.rb, line 52 def setup_client set_header set_query set_basic_authentication end