Class: ShippingScale::Request

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



16
17
18
19
# File 'lib/shipping_scale/request.rb', line 16

def initialize(options={})
  @response = options[:response]
  @packages = options[:packages]
end

Class Attribute Details

.apiObject (readonly)

Returns the value of attribute api.



4
5
6
# File 'lib/shipping_scale/request.rb', line 4

def api
  @api
end

.secureObject (readonly)

Returns the value of attribute secure.



4
5
6
# File 'lib/shipping_scale/request.rb', line 4

def secure
  @secure
end

.tagObject (readonly)

Returns the value of attribute tag.



4
5
6
# File 'lib/shipping_scale/request.rb', line 4

def tag
  @tag
end

Instance Attribute Details

#packagesObject (readonly)

Returns the value of attribute packages.



22
23
24
# File 'lib/shipping_scale/request.rb', line 22

def packages
  @packages
end

#responseObject

Returns the value of attribute response.



21
22
23
# File 'lib/shipping_scale/request.rb', line 21

def response
  @response
end

Class Method Details

.config(options = {}) ⇒ Object



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

def config(options = {})
  defaults = {api: "RateV4", tag: "RateV4Request"}
  options = defaults.merge(options)

  @api = options[:api]
  @tag = options[:tag]
  @secure = !!options[:secure]
end

Instance Method Details

#apiObject



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

def api
  self.class.api
end

#buildObject



32
33
34
35
36
37
38
# File 'lib/shipping_scale/request.rb', line 32

def build
  xml.tag!(self.class.tag, USERID: ShippingScale.config.user_id) do |req|
    req.tag!("Revision", "2")
    packages_to_xml(req)
  end
  xml
end

#secure?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/shipping_scale/request.rb', line 24

def secure?
  !!self.class.secure
end

#send!Object



40
41
42
# File 'lib/shipping_scale/request.rb', line 40

def send!
  ShippingScale.client.request(self)
end