Module: RailsConnector::Migrations::MigrationDsl

Defined in:
lib/rails_connector/migrations/migration_dsl.rb

Instance Method Summary collapse

Instance Method Details

#create_obj(attributes = {}) ⇒ Object

Creates a CMS object.

Examples:

Create “/test” Object


create_obj(_path: '/test', _obj_class: 'Test')

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes and their values of the new CMS object.

Returns:

  • nothing



87
88
89
90
91
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 87

def create_obj(attributes = {})
  endpoint = "workspaces/#{Workspace.current.id}/objs"

  CmsRestApi.post(endpoint, obj: attributes)
end

#create_obj_class(attributes = {}) ⇒ Object

Creates a CMS object class.

Examples:

Create “Test” Object Class


create_obj_class(name: 'Test', type: 'publication')

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes and their values of the new CMS object class.

Returns:

  • nothing



104
105
106
107
108
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 104

def create_obj_class(attributes = {})
  endpoint = "workspaces/#{Workspace.current.id}/obj_classes"

  CmsRestApi.post(endpoint, obj_class: attributes)
end

#delete_obj(id) ⇒ Object

Deletes a CMS object with the given id.

Examples:

Deletes “a1b2c3” Object


delete_obj('a1b2c3')

Parameters:

  • id (String)

    The ID of the CMS object.

Returns:

  • nothing



120
121
122
123
124
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 120

def delete_obj(id)
  endpoint = "workspaces/#{Workspace.current.id}/objs/#{id}"

  CmsRestApi.delete(endpoint)
end

#get_obj(id) ⇒ Hash

Fetches all object attributes and their values.

Examples:

Get all attributes for the obj with id “abc123”


get_obj('abc123')

Parameters:

  • id (String)

    The ID of the CMS object.

Returns:

  • (Hash)

    a hash with attributes and their values.



136
137
138
139
140
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 136

def get_obj(id)
  endpoint = "workspaces/#{Workspace.current.id}/objs/#{id}"

  CmsRestApi.get(endpoint)
end

#get_obj_class(id) ⇒ Hash

Fetches all object class attributes and their values.

Examples:

Get all attributes for the object class “Test”


get_obj_class('Test')

Parameters:

  • id (String)

    The ID of the object class.

Returns:

  • (Hash)

    a hash with attributes and their values.



152
153
154
155
156
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 152

def get_obj_class(id)
  endpoint = "workspaces/#{Workspace.current.id}/obj_classes/#{id}"

  CmsRestApi.get(endpoint)
end

#update_obj(id, attributes = {}) ⇒ Object

Updates a CMS object.

Examples:

Update the title of the “a1b2c3” Object


update_attribute('a1b2c3', title: 'Test Title')

Parameters:

  • id (String)

    The ID of the CMS object.

  • attributes (Hash) (defaults to: {})

    The updated attributes and their values.

Returns:

  • nothing



169
170
171
172
173
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 169

def update_obj(id, attributes = {})
  endpoint = "workspaces/#{Workspace.current.id}/objs/#{id}"

  CmsRestApi.put(endpoint, obj: attributes)
end

#update_obj_class(id, attributes = {}) ⇒ Object

Updates a CMS object class.

Examples:

Update the title of the “Test” Object Class


update_obj_class('Test', title: 'Test Title')

Parameters:

  • id (String)

    The ID of the CMS object class.

  • attributes (Hash) (defaults to: {})

    The updated attributes and their values.

Returns:

  • nothing



186
187
188
189
190
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 186

def update_obj_class(id, attributes = {})
  endpoint = "workspaces/#{Workspace.current.id}/obj_classes/#{id}"

  CmsRestApi.put(endpoint, obj_class: attributes)
end

#upload_file(file) ⇒ Object

Uploads a file to the content store.

Examples:

Upload “image.png” and store it in an “Image” CMS object.


filename = 'image.png'
file = File.new(filename)
blob = upload_file(file)
create_obj(_path: "/resources/images/#{filename}", _obj_class: 'Image', blob: blob)

Parameters:

  • file (IO)

    The file IO object that gets uploaded.

Returns:

  • The blob of the uploaded file that can be stored on a CMS object.



205
206
207
208
209
210
211
212
213
214
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 205

def upload_file(file)
  upload_permission = RailsConnector::CmsRestApi.get('blobs/upload_permission')

  fields = upload_permission['fields'].map { |name, value| [name, value] }
  fields << [:file, file]

  RestClient.post(upload_permission['url'], fields)

  upload_permission['blob']
end