Sha256: 9e2a78d83f1e2fbbbceb3df45652f3effb00c101d91a8caf7802023b0f88751c

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module ChartMogul
  module API
    module Actions
      module Update
        def self.included(base)
          base.extend ClassMethods
        end

        def update!
          resp = handling_errors do
            connection.patch("#{resource_path.apply(instance_attributes)}/#{uuid}") do |req|
              req.headers['Content-Type'] = 'application/json'
              req.body = JSON.dump(serialize_for_write)
            end
          end
          json = ChartMogul::Utils::JSONParser.parse(resp.body)

          assign_all_attributes(json)
        end

        module ClassMethods
          def update!(uuid, attributes = {})
            resource = new(attributes)

            resp = handling_errors do
              connection.patch("#{resource_path.apply(attributes)}/#{uuid}") do |req|
                req.headers['Content-Type'] = 'application/json'
                req.body = JSON.dump(resource.serialize_for_write)
              end
            end
            json = ChartMogul::Utils::JSONParser.parse(resp.body)

            new_from_json(json)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chartmogul-ruby-1.6.6 lib/chartmogul/api/actions/update.rb
chartmogul-ruby-1.6.4 lib/chartmogul/api/actions/update.rb
chartmogul-ruby-1.6.3 lib/chartmogul/api/actions/update.rb
chartmogul-ruby-1.6.2 lib/chartmogul/api/actions/update.rb