Class: Clearsale::OrderResponse
- Inherits:
-
Object
- Object
- Clearsale::OrderResponse
- Defined in:
- lib/clearsale/order_response.rb
Constant Summary collapse
- STATUS_MAP =
{ "APA" => :approved, "PAV" => :approval_pending, "APQ" => :approved_by_survey, "RPQ" => :rejected_by_survey, "RPP" => :rejected_by_policy, "RPA" => :rejected }
Instance Attribute Summary collapse
-
#order_id ⇒ Object
readonly
Returns the value of attribute order_id.
-
#quiz_url ⇒ Object
readonly
Returns the value of attribute quiz_url.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
Class Method Summary collapse
Instance Method Summary collapse
- #approved? ⇒ Boolean
-
#initialize(hash) ⇒ OrderResponse
constructor
A new instance of OrderResponse.
- #pending? ⇒ Boolean
- #rejected? ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ OrderResponse
Returns a new instance of OrderResponse.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/clearsale/order_response.rb', line 22 def initialize(hash) response = hash.fetch(:orders, {}).fetch(:order, {}) if response.blank? if hash && hash[:status_code] == "05" @status = :order_already_exists else @status = :inexistent_order end else @order_id = response[:id].gsub(/[a-zA-Z]*/, '').to_i @score = response[:score].to_f @quiz_url = response[:quiz_url] @status = STATUS_MAP[response[:status]] end end |
Instance Attribute Details
#order_id ⇒ Object (readonly)
Returns the value of attribute order_id.
12 13 14 |
# File 'lib/clearsale/order_response.rb', line 12 def order_id @order_id end |
#quiz_url ⇒ Object (readonly)
Returns the value of attribute quiz_url.
12 13 14 |
# File 'lib/clearsale/order_response.rb', line 12 def quiz_url @quiz_url end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
12 13 14 |
# File 'lib/clearsale/order_response.rb', line 12 def score @score end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/clearsale/order_response.rb', line 12 def status @status end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
12 13 14 |
# File 'lib/clearsale/order_response.rb', line 12 def transaction_id @transaction_id end |
Class Method Details
.build_from_send_order(package) ⇒ Object
14 15 16 |
# File 'lib/clearsale/order_response.rb', line 14 def self.build_from_send_order(package) new(package.fetch(:package_status, {})) end |
.build_from_update(package) ⇒ Object
18 19 20 |
# File 'lib/clearsale/order_response.rb', line 18 def self.build_from_update(package) new(package.fetch(:clear_sale, {})) end |
Instance Method Details
#approved? ⇒ Boolean
38 39 40 |
# File 'lib/clearsale/order_response.rb', line 38 def approved? @status == :approved || @status == :approved_by_survey end |
#pending? ⇒ Boolean
46 47 48 |
# File 'lib/clearsale/order_response.rb', line 46 def pending? @status == :approval_pending end |
#rejected? ⇒ Boolean
42 43 44 |
# File 'lib/clearsale/order_response.rb', line 42 def rejected? @status == :rejected_by_survey || @status == :rejected_by_policy || @status == :rejected end |