Module: AdaptivePayments::JsonModel::Writing
- Included in:
- AdaptivePayments::JsonModel
- Defined in:
- lib/pp-adaptive/support/json_model.rb
Overview
Methods for converting a JsonModel into a JSON string for transport to the API
Instance Method Summary collapse
-
#to_hash ⇒ Hash
Recursively read all attributes in a ruby Hash, mapping attribute names to JSON parameters, according to the :param option.
-
#to_json ⇒ String
Convert this JsonModel into a JSON string for transport to the PayPal API.
Instance Method Details
#to_hash ⇒ Hash
Recursively read all attributes in a ruby Hash, mapping attribute names to JSON parameters, according to the :param option
100 101 102 103 104 |
# File 'lib/pp-adaptive/support/json_model.rb', line 100 def to_hash Hash[attribute_set.map{ |a| [a.name, self[a.name]] }]. inject({}) { |hash, (key, value)| value.nil? ? hash : hash.merge(json_key(key) => json_value(value)) }. reject { |key, value| value.kind_of?(Enumerable) && value.none? } end |
#to_json ⇒ String
Convert this JsonModel into a JSON string for transport to the PayPal API
110 111 112 |
# File 'lib/pp-adaptive/support/json_model.rb', line 110 def to_json(*) to_hash.to_json end |