Sha256: b14faf5ca9f45433c84f09fe8c458165a3d33c5b3731f8d7d7892b41d332a881

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

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

        def create!
          resp = handling_errors do
            connection.post(resource_path.apply(instance_attributes)) do |req|
              req.headers['Content-Type'] = 'application/json'
              req.body = JSON.dump(serialize_for_write)
            end
          end
          json = ChartMogul::Utils::JSONParser.parse(resp.body, skip_case_conversion: self.class.skip_case_conversion)

          assign_all_attributes(json)
        end

        module ClassMethods
          def create!(attributes = {})
            resource = new(attributes)

            resp = handling_errors do
              connection.post(resource_path.apply(attributes)) 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, skip_case_conversion: skip_case_conversion)

            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.7.1 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.6.9 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.6.8 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.6.7 lib/chartmogul/api/actions/create.rb