Class: ThePlatform::Data

Inherits:
Object
  • Object
show all
Extended by:
Configuration
Includes:
HTTParty
Defined in:
lib/theplatform/data.rb

Overview

Class to RESTfully interface with thePlatform’s API

ThePlatform::Data#

Instance Attribute Summary

Attributes included from Configuration

#_duration, #_idleTimeout, #form, #password, #schema, #token, #username

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configuration

configure, parameters, parameters?

Constructor Details

#initialize(params = {}) ⇒ Data

Returns a new instance of Data.



10
11
12
13
# File 'lib/theplatform/data.rb', line 10

def initialize(params={})
  @endpoint = params[:endpoint]
  @objects  = params[:objects]
end

Class Method Details

.keysObject

Set the different available params to configure



23
24
25
# File 'lib/theplatform/data.rb', line 23

def self.keys
  @keys ||= [:schema, :form, :token]
end

.servicesObject

List the available services to build objects with



16
17
18
19
20
# File 'lib/theplatform/data.rb', line 16

def self.services
  service = []
  ThePlatform.const_get(:SERVICE).keys.each { |k| service << k }
  service
end

Instance Method Details

#delete(object, id = [], options = {}) ⇒ Object

DELETE objects

To DELETE Objects, pass the Object type and comma separated IDs, or specify ‘none’ for ID if DELETE’ing via query.

Needed parameters: schema, form, token, and account

ThePlatform::Data.mds.delete('Media','27550715', schema:'1.4.0',form:'cjson',
  token:'Nez8Y9ScVDxPxLDmUsg_ESCDYJCJwPBk',account:'Ruby Test Account')


90
91
92
93
94
95
# File 'lib/theplatform/data.rb', line 90

def delete(object,id=[],options={})
  set_uri
  set_header options
  set_id = "/#{id}" unless id =~ /none/i
  self.class.delete("/#{object}#{set_id}", query: extras.merge(options))
end

#get(object, id = [], options = {}) ⇒ Object

GET call for data Object.

This is built by passing the Object, the comma delimited IDs, and the RESTful parameters. To return all the Objects, pass ‘all’ for the id param.

Needed paramters are: schema, form, and token

ThePlatform::Data.mds.get('Category','1278889',schema:'1.4.0',form:'json',token:'12uZynnc2zHvVNDokvgG0mmK33yOOd',account:'my_account')

or

ThePlatform::Data.mds.get('Category','all',schema:'1.4.0',form:'json',token:'12uZynnc2zHvVNDokvgG0mmK33yOOd',account:'my_account')


44
45
46
47
48
49
# File 'lib/theplatform/data.rb', line 44

def get(object, id=[],options={})
  set_uri
  set_header options
  set_id = "/#{id}" unless id =~ /all/i
  self.class.get("/#{object}#{set_id}", query: extras.merge(options))
end

#notify(options = {}) ⇒ Object

NOTIFY endpoint

This moves to the /notify endpoint of the data service

Needed parameters: token

ThePlatform::Data.mds.notify(token:'G1yP1Zsp7nEHW2fug6glIQCjfjIIIl', size:'10', since:'289334341')


104
105
106
107
108
# File 'lib/theplatform/data.rb', line 104

def notify(options={})
  set_header options
  self.class.base_uri @endpoint
  self.class.get("/notify", query: extras.merge(options))
end

#post(object, body, options = {}) ⇒ Object

POST to create new Objects.

Posts are created by passing the Object type, and a String object of the POST body.

Needed parameters are: schema, form, token, and account.

the_body = '{'title':'Using the RUBYds',"ownerId":"http://access.auth.theplatform.com/data/Account/2011111628"}'
ThePlatform::Data.mds.put('Media', the_body,
  schema:'1.4.0',form:'cjson',token:'Nez8Y9ScVDxPxLDmUsg_ESCDYJCJwPBk',account:'Ruby Test Account')


60
61
62
63
64
# File 'lib/theplatform/data.rb', line 60

def post(object, body, options={})
  set_uri
  set_header options
  self.class.post("/#{object}", query: extras.merge(options), body: body)
end

#put(object, body, options = {}) ⇒ Object

PUT to edit Objects.

Put needs the Object type and String body.

Needed parameters: schema, form, token, and account.

the_body = '{"id":""http://data.media.theplatform.com/media/data/Media/27444715"","title":"test"}'
ThePlatform::Data.mds.put('Media', the_body,
  schema:'1.4.0',form:'cjson',token:'Nez8Y9ScVDxPxLDmUsg_ESCDYJCJwPBk',account:'Ruby Test Account')


75
76
77
78
79
# File 'lib/theplatform/data.rb', line 75

def put(object, body, options={})
  set_uri
  set_header options
  self.class.put("/#{object}", query: extras.merge(options), body: body)
end