Class: Vocalware::Request
- Inherits:
-
Object
- Object
- Vocalware::Request
- 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
-
#initialize(attrs) ⇒ Request
constructor
A new instance of Request.
-
#to_url ⇒ String
Build a query as a URL with GET parameters.
Constructor Details
#initialize(attrs) ⇒ Request
Returns a new instance of Request.
9 10 11 12 |
# File 'lib/vocalware/request.rb', line 9 def initialize(attrs) @attrs = attrs validate! end |
Instance Method Details
#to_url ⇒ String
Build a query as a URL with GET parameters.
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 |