Skip to content

Commit

Permalink
parse
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-plivo committed May 30, 2024
1 parent 1b95c0a commit 3ee132e
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/plivo/base/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,26 @@ def parse_and_set_response(resource_json)

valid_param?(:resource_json, resource_json, Hash, true)

parsed_response = {}

resource_json.each do |k, v|
if v.is_a?(Hash)
nested_object_name = k
instance_variable_set("@#{nested_object_name}", {})
v.each do |nested_k, nested_v|
instance_variable_set("@#{nested_object_name}_#{nested_k}", nested_v)
self.class.send(:attr_reader, "#{nested_object_name}_#{nested_k}")
parsed_response["#{k}_#{nested_k}".to_sym] = nested_v
end
else
instance_variable_set("@#{k}", v)
self.class.send(:attr_reader, k)
parsed_response[k.to_sym] = v
end
end

if @_identifier_string && resource_json.key?(@_identifier_string)
@id = resource_json[@_identifier_string]
end
parsed_response
end






def perform_update(params, use_multipart_conn = false)
unless @id
raise_invalid_request("Cannot update a #{@_name} resource "\
Expand Down

0 comments on commit 3ee132e

Please sign in to comment.