Class: USPS::Request::Base

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.apiObject (readonly)

Returns the value of attribute api.



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

def api
  @api
end

.responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

.secureObject (readonly) Also known as: secure?

Returns the value of attribute secure.



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

def secure
  @secure
end

.tagObject (readonly)

Returns the value of attribute tag.



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

def tag
  @tag
end

Class Method Details

.config(options = {}) ⇒ Object

Config given

api: The USPS API name as given in the request URL
tag: The root tag used for the request
secure: Whether or not the request is against the secure server
response: The USPS::Response class used to handle responses


13
14
15
16
17
18
# File 'lib/usps/request/base.rb', line 13

def config(options = {})
  @api = options[:api].to_s
  @tag = options[:tag].to_s
  @secure = !!options[:secure]
  @response = options[:response]
end

Instance Method Details

#apiObject



29
30
31
# File 'lib/usps/request/base.rb', line 29

def api
  self.class.api
end

#build(&block) ⇒ Object



37
38
39
40
# File 'lib/usps/request/base.rb', line 37

def build(&block)
  builder = Builder::XmlMarkup.new(:indent => 0)
  builder.tag!(self.class.tag, :USERID => USPS.config.username, &block)
end

#response_for(xml) ⇒ Object



33
34
35
# File 'lib/usps/request/base.rb', line 33

def response_for(xml)
  self.class.response.parse(xml)
end

#secure?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/usps/request/base.rb', line 25

def secure?
  !!self.class.secure?
end

#send!Object



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

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