Class: Vocalware::Request

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

Overview

Request to send to Vocalware’s remote service. Builds a URL with all necessary parameters according to the API.

Constant Summary collapse

REQUIRED_PARAMETERS =

Required parameters according to the Vocalware API reference.

['EID', 'LID', 'VID', 'TXT', 'ACC', 'API', 'CS']

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Request

Returns a new instance of Request.

Parameters:

  • attrs (Hash<Symbol, Object>)


9
10
11
12
# File 'lib/vocalware/request.rb', line 9

def initialize(attrs)
  @attrs = attrs
  validate!
end

Instance Method Details

#to_urlString

Build a query as a URL with GET parameters.

Returns:

  • (String)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vocalware/request.rb', line 17

def to_url
  port = @attrs[:port]
  url  = "#{@attrs[:protocol]}://#{@attrs[:host]}"
  url << ":#{port}" if port
  url << "#{@attrs[:path]}?"

  params_str = params.map {|name, value|
                            "#{CGI.escape(name)}=#{CGI.escape(value)}"
                          }.join('&')
  url << params_str
end