Sha256: 5f7369feac37c9b8f59fbc6c3e4e3ce5b14057c82142de2d8044457c5f44442a

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 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(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)

          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

14 entries across 14 versions & 1 rubygems

Version Path
chartmogul-ruby-1.5.1 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.5.0 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.4.1 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.4.0 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.3.3 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.3.2 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.3.1 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.3.0 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.2.2 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.2.1 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.2.0 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.1.9 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.1.8 lib/chartmogul/api/actions/create.rb
chartmogul-ruby-1.1.7 lib/chartmogul/api/actions/create.rb