Class: ShippingEasy::Http::Request
- Inherits:
-
Object
- Object
- ShippingEasy::Http::Request
- Defined in:
- lib/shipping_easy/http/request.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#params ⇒ Object
Returns the value of attribute params.
-
#relative_path ⇒ Object
Returns the value of attribute relative_path.
Class Method Summary collapse
Instance Method Summary collapse
- #adapter ⇒ Object
- #api_key ⇒ Object
- #api_secret ⇒ Object
- #base_url ⇒ Object
- #connect! ⇒ Object
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
- #sign_request! ⇒ Object
- #signature ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 10 |
# File 'lib/shipping_easy/http/request.rb', line 5 def initialize( = {}) @http_method = .fetch(:http_method, :get) @params = .fetch(:params, {}) @body = [:payload] && [:payload].to_json @relative_path = .delete(:relative_path) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/shipping_easy/http/request.rb', line 3 def body @body end |
#http_method ⇒ Object
Returns the value of attribute http_method.
3 4 5 |
# File 'lib/shipping_easy/http/request.rb', line 3 def http_method @http_method end |
#params ⇒ Object
Returns the value of attribute params.
3 4 5 |
# File 'lib/shipping_easy/http/request.rb', line 3 def params @params end |
#relative_path ⇒ Object
Returns the value of attribute relative_path.
3 4 5 |
# File 'lib/shipping_easy/http/request.rb', line 3 def relative_path @relative_path end |
Class Method Details
.connect!(options = {}) ⇒ Object
12 13 14 |
# File 'lib/shipping_easy/http/request.rb', line 12 def self.connect!( = {}) new().connect! end |
Instance Method Details
#adapter ⇒ Object
35 36 37 |
# File 'lib/shipping_easy/http/request.rb', line 35 def adapter ShippingEasy.configuration.http_adapter.new(self) end |
#api_key ⇒ Object
43 44 45 |
# File 'lib/shipping_easy/http/request.rb', line 43 def api_key ShippingEasy.api_key end |
#api_secret ⇒ Object
39 40 41 |
# File 'lib/shipping_easy/http/request.rb', line 39 def api_secret ShippingEasy.api_secret end |
#base_url ⇒ Object
47 48 49 |
# File 'lib/shipping_easy/http/request.rb', line 47 def base_url ShippingEasy.base_url end |
#connect! ⇒ Object
16 17 18 19 |
# File 'lib/shipping_easy/http/request.rb', line 16 def connect! sign_request! adapter.connect! end |
#sign_request! ⇒ Object
21 22 23 24 25 |
# File 'lib/shipping_easy/http/request.rb', line 21 def sign_request! params[:api_key] = api_key params[:api_timestamp] = Time.now.to_i params[:api_signature] = signature.to_s end |
#signature ⇒ Object
31 32 33 |
# File 'lib/shipping_easy/http/request.rb', line 31 def signature ShippingEasy::Signature.new(api_secret: api_secret, method: http_method, path: uri, params: params, body: body) end |
#uri ⇒ Object
27 28 29 |
# File 'lib/shipping_easy/http/request.rb', line 27 def uri "/api#{relative_path}" end |