Class: PostcodeAnywhere::Request
- Inherits:
-
Object
- Object
- PostcodeAnywhere::Request
- Defined in:
- lib/postcode_anywhere/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#client ⇒ Object
Returns the value of attribute client.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#request_method ⇒ Object
(also: #verb)
Returns the value of attribute request_method.
Instance Method Summary collapse
-
#initialize(client, request_method, path, body_hash = {}, options = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
- #perform_with_object(klass) ⇒ Object
- #perform_with_objects(klass) ⇒ Object
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 = {}, = {}) @client = client @request_method = request_method.to_sym @path = path @body_hash = body_hash @options = end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/postcode_anywhere/request.rb', line 3 def body @body end |
#client ⇒ Object
Returns the value of attribute client.
3 4 5 |
# File 'lib/postcode_anywhere/request.rb', line 3 def client @client end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/postcode_anywhere/request.rb', line 3 def @options end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/postcode_anywhere/request.rb', line 3 def path @path end |
#request_method ⇒ Object 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
#perform ⇒ Object
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 |