Sha256: f1a5bbe6787c2e46c80c4f05b74df68ec985a14521c20a3b81f91b72d8ce4567

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

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(self.instance_attributes)) do |req|
              req.headers['Content-Type'] = 'application/json'
              req.body = JSON.dump(self.serialize_for_write)
            end
          end
          json = ChartMogul::Utils::JSONParser.parse(resp.body)

          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)

            new_from_json(json)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
chartmogul-ruby-1.1.3 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.1.1 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.1.0 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.0.2 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.0.1 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.0.0 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-0.1.4 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-0.1.3 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-0.1.2 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-0.1.1 lib/chartmogul/api/actions/create.rb