Class: PartyResource::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#verbObject (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

#dataObject



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(options={})
  options = options.merge(self.params_key => self.data) unless self.data.empty?
  options
end

#params_keyObject



28
29
30
# File 'lib/party_resource/request.rb', line 28

def params_key
  verb == :get ? :query : :body
end

#pathObject



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_paramsObject



32
33
34
# File 'lib/party_resource/request.rb', line 32

def path_params
  @path.scan(/:([\w]+)/).flatten.map{|p| p.to_sym}
end