Class: PartyResource::Request
- Inherits:
-
Object
- Object
- PartyResource::Request
- Defined in:
- lib/party_resource/request.rb
Instance Attribute Summary collapse
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #data ⇒ Object
- #http_data(options = {}) ⇒ Object
-
#initialize(verb, path, context, args, params) ⇒ Request
constructor
A new instance of Request.
- #params_key ⇒ Object
- #path ⇒ Object
- #path_params ⇒ Object
Constructor Details
#initialize(verb, path, context, args, params) ⇒ Request
Returns a new instance of Request.
4 5 6 7 8 9 10 |
# File 'lib/party_resource/request.rb', line 4 def initialize(verb, path, context, args, params) @verb = verb @path = path @args = args @context = context @params = params || {} end |
Instance Attribute Details
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
3 4 5 |
# File 'lib/party_resource/request.rb', line 3 def verb @verb end |
Instance Method Details
#data ⇒ Object
19 20 21 |
# File 'lib/party_resource/request.rb', line 19 def data @params.merge(@args).reject{|name,value| path_params.include?(name)} end |
#http_data(options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/party_resource/request.rb', line 23 def http_data(={}) = .merge(self.params_key => self.data) unless self.data.empty? end |
#params_key ⇒ Object
28 29 30 |
# File 'lib/party_resource/request.rb', line 28 def params_key verb == :get ? :query : :body end |
#path ⇒ Object
12 13 14 15 16 17 |
# File 'lib/party_resource/request.rb', line 12 def path args = @context.parameter_values(path_params - @args.keys).merge(@args) URI.encode(path_params.inject(@path) do |path, param| path.gsub(":#{param}", args[param].to_s) end) end |
#path_params ⇒ Object
32 33 34 |
# File 'lib/party_resource/request.rb', line 32 def path_params @path.scan(/:([\w]+)/).flatten.map{|p| p.to_sym} end |