Class: StackMob::DataStore

Inherits:
Object
  • Object
show all
Defined in:
lib/stackmob/data_store.rb

Constant Summary collapse

API_SVC =
:api

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cl) ⇒ DataStore

Returns a new instance of DataStore.



22
23
24
# File 'lib/stackmob/data_store.rb', line 22

def initialize(cl)
  self.client = cl
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



18
19
20
# File 'lib/stackmob/data_store.rb', line 18

def client
  @client
end

Instance Method Details

#api_schemaObject



26
27
28
# File 'lib/stackmob/data_store.rb', line 26

def api_schema
  self.client.request(:get, API_SVC, "/listapi")
end

#create(obj_name, params) ⇒ Object



30
31
32
33
34
# File 'lib/stackmob/data_store.rb', line 30

def create(obj_name, params)
  create!(obj_name, params)
rescue Client::RequestError
  false
end

#create!(obj_name, params) ⇒ Object



36
37
38
# File 'lib/stackmob/data_store.rb', line 36

def create!(obj_name, params)
  self.client.request(:post, API_SVC, obj_name_to_path(obj_name), params)
end

#delete(obj_name, params) ⇒ Object



40
41
42
43
44
# File 'lib/stackmob/data_store.rb', line 40

def delete(obj_name, params)
  delete!(obj_name, params); true
rescue Client::RequestError
  false
end

#delete!(obj_name, params) ⇒ Object



46
47
48
# File 'lib/stackmob/data_store.rb', line 46

def delete!(obj_name, params)
  self.client.request(:delete, API_SVC, obj_name_to_path(obj_name), params)
end

#get(obj_name, params = {}) ⇒ Object



50
51
52
# File 'lib/stackmob/data_store.rb', line 50

def get(obj_name, params = {})
  self.client.request(:get, API_SVC, obj_name_to_path(obj_name), params)
end

#get_one(obj_name, params) ⇒ Object



54
55
56
# File 'lib/stackmob/data_store.rb', line 54

def get_one(obj_name, params)
  get(obj_name, params).first
end

#update(obj_name, obj_id, params) ⇒ Object



58
59
60
61
62
# File 'lib/stackmob/data_store.rb', line 58

def update(obj_name, obj_id, params)
  update!(obj_name, obj_id, params); true
rescue Client::RequestError
  false
end

#update!(obj_name, obj_id, params) ⇒ Object



64
65
66
# File 'lib/stackmob/data_store.rb', line 64

def update!(obj_name, obj_id, params)
  self.client.request(:put, API_SVC, obj_name_to_path(obj_name) + "/#{obj_id}", params)
end