Class: PostcodeAnywhere::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, request_method, path, body_hash = {}, options = {}) ⇒ Request

Returns a new instance of Request.



6
7
8
9
10
11
12
# File 'lib/postcode_anywhere/request.rb', line 6

def initialize(client, request_method, path, body_hash = {}, options = {})
  @client = client
  @request_method = request_method.to_sym
  @path = path
  @body_hash = body_hash
  @options = options
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



3
4
5
# File 'lib/postcode_anywhere/request.rb', line 3

def body
  @body
end

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/postcode_anywhere/request.rb', line 3

def client
  @client
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/postcode_anywhere/request.rb', line 3

def options
  @options
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/postcode_anywhere/request.rb', line 3

def path
  @path
end

#request_methodObject Also known as: verb

Returns the value of attribute request_method.



3
4
5
# File 'lib/postcode_anywhere/request.rb', line 3

def request_method
  @request_method
end

Instance Method Details

#performObject



14
15
16
# File 'lib/postcode_anywhere/request.rb', line 14

def perform
  @client.send(@request_method, @path, @body_hash, @options).body
end

#perform_with_object(klass) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/postcode_anywhere/request.rb', line 18

def perform_with_object(klass)
  result = perform
  if result.class == Array
    klass.new(result.first)
  else
    klass.new(result)
  end
end

#perform_with_objects(klass) ⇒ Object



27
28
29
30
31
# File 'lib/postcode_anywhere/request.rb', line 27

def perform_with_objects(klass)
  perform.map do |element|
    klass.new(element)
  end
end