Class: DopisOnlineClient::Request
- Inherits:
-
Object
- Object
- DopisOnlineClient::Request
- Includes:
- HTTMultiParty
- Defined in:
- lib/dopis_online_client/request.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#payment_type ⇒ Object
readonly
Returns the value of attribute payment_type.
-
#pdf_file ⇒ Object
readonly
Returns the value of attribute pdf_file.
-
#postage_type ⇒ Object
readonly
Returns the value of attribute postage_type.
-
#response_format ⇒ Object
readonly
Returns the value of attribute response_format.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #deliver ⇒ Object
-
#initialize(params) ⇒ Request
constructor
A new instance of Request.
- #parse_response(body) ⇒ Object
Constructor Details
#initialize(params) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 15 |
# File 'lib/dopis_online_client/request.rb', line 8 def initialize(params) @color = params[:color] || 0 # cernobile @postage_type = params[:postage_type] || 66 # obycejne @payment_type = params[:payment_type] || 0 # fakturou @format = params[:format] || :xml @pdf_file_path = params[:pdf_file_path] self.class.base_uri DopisOnlineClient.base_uri end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
6 7 8 |
# File 'lib/dopis_online_client/request.rb', line 6 def color @color end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
6 7 8 |
# File 'lib/dopis_online_client/request.rb', line 6 def password @password end |
#payment_type ⇒ Object (readonly)
Returns the value of attribute payment_type.
6 7 8 |
# File 'lib/dopis_online_client/request.rb', line 6 def payment_type @payment_type end |
#pdf_file ⇒ Object (readonly)
Returns the value of attribute pdf_file.
6 7 8 |
# File 'lib/dopis_online_client/request.rb', line 6 def pdf_file @pdf_file end |
#postage_type ⇒ Object (readonly)
Returns the value of attribute postage_type.
6 7 8 |
# File 'lib/dopis_online_client/request.rb', line 6 def postage_type @postage_type end |
#response_format ⇒ Object (readonly)
Returns the value of attribute response_format.
6 7 8 |
# File 'lib/dopis_online_client/request.rb', line 6 def response_format @response_format end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
6 7 8 |
# File 'lib/dopis_online_client/request.rb', line 6 def username @username end |
Class Method Details
.send(params) ⇒ Object
41 42 43 |
# File 'lib/dopis_online_client/request.rb', line 41 def self.send(params) @request = new(params).deliver end |
Instance Method Details
#deliver ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dopis_online_client/request.rb', line 17 def deliver response = self.class.post '/dopisonline.php', :body => { :user => DopisOnlineClient.username, :passwd => DopisOnlineClient.password, :barvatisku => @color, :typvyplatneho => @postage_type, :typuhrady => @payment_type, :typvystupu => @format.to_s, :soubor => File.new(@pdf_file_path) } parsed_response = parse_response(response.body) DopisOnlineClient::Response.new(parsed_response, response.body, response.code) end |
#parse_response(body) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/dopis_online_client/request.rb', line 31 def parse_response(body) return nil if body.nil? or body.empty? case @format when :xml Crack::XML.parse(body) else body end end |