Class: RestApiClient::RestModel
- Inherits:
-
Object
- Object
- RestApiClient::RestModel
- Defined in:
- lib/rest/api/client.rb
Constant Summary collapse
- PATH =
''- SERVICE_KEY =
''
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
- .count(params = {}) ⇒ Object
- .find(id) ⇒ Object
- .get(id) ⇒ Object
- .get_model_name ⇒ Object
- .list(params = {}) ⇒ Object
-
.path ⇒ Object
default path to class methods.
- .perform_get(path, args = {}, headers = {}) ⇒ Object
-
.service_key ⇒ Object
default service_key to class methods.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #delete ⇒ Object
- #get_model_name ⇒ Object
-
#path ⇒ Object
default path to instance methods.
- #perform_delete(path, args = {}, headers = {}) ⇒ Object
- #perform_get(path, args = {}, headers = {}) ⇒ Object
- #perform_post(path, args = {}, headers = {}) ⇒ Object
- #perform_put(path, args = {}, headers = {}) ⇒ Object
- #save! ⇒ Object
-
#service_key ⇒ Object
default service_key to instance methods.
- #update! ⇒ Object
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
19 20 21 |
# File 'lib/rest/api/client.rb', line 19 def errors @errors end |
Class Method Details
.count(params = {}) ⇒ Object
29 30 31 |
# File 'lib/rest/api/client.rb', line 29 def self.count(params = {}) perform_get "#{path}/count", {:params => params} end |
.find(id) ⇒ Object
33 34 35 |
# File 'lib/rest/api/client.rb', line 33 def self.find(id) perform_get "#{path}/#{id}", {:type => self} end |
.get(id) ⇒ Object
37 38 39 |
# File 'lib/rest/api/client.rb', line 37 def self.get(id) self.find id end |
.get_model_name ⇒ Object
91 92 93 |
# File 'lib/rest/api/client.rb', line 91 def self.get_model_name self.name.split('::').last.downcase end |
.list(params = {}) ⇒ Object
25 26 27 |
# File 'lib/rest/api/client.rb', line 25 def self.list(params = {}) perform_get path, {:type => self, :params => params} end |
.path ⇒ Object
default path to class methods
111 112 113 |
# File 'lib/rest/api/client.rb', line 111 def self.path PATH end |
.perform_get(path, args = {}, headers = {}) ⇒ Object
83 84 85 |
# File 'lib/rest/api/client.rb', line 83 def self.perform_get(path, args = {}, headers = {}) RequestsHandler.perform_get(service_key, path, args, headers) end |
.service_key ⇒ Object
default service_key to class methods
101 102 103 |
# File 'lib/rest/api/client.rb', line 101 def self.service_key SERVICE_KEY end |
Instance Method Details
#==(other) ⇒ Object
115 116 117 |
# File 'lib/rest/api/client.rb', line 115 def ==(other) id == other.id end |
#delete ⇒ Object
52 53 54 |
# File 'lib/rest/api/client.rb', line 52 def delete perform_delete "#{path}/#{id}" end |
#get_model_name ⇒ Object
87 88 89 |
# File 'lib/rest/api/client.rb', line 87 def get_model_name self.class.name.split('::').last.downcase end |
#path ⇒ Object
default path to instance methods
106 107 108 |
# File 'lib/rest/api/client.rb', line 106 def path PATH end |
#perform_delete(path, args = {}, headers = {}) ⇒ Object
79 80 81 |
# File 'lib/rest/api/client.rb', line 79 def perform_delete(path, args = {}, headers = {}) RequestsHandler.perform_delete(service_key, path, args, headers) end |
#perform_get(path, args = {}, headers = {}) ⇒ Object
67 68 69 |
# File 'lib/rest/api/client.rb', line 67 def perform_get(path, args = {}, headers = {}) RequestsHandler.perform_get(service_key, path, args, headers) end |
#perform_post(path, args = {}, headers = {}) ⇒ Object
71 72 73 |
# File 'lib/rest/api/client.rb', line 71 def perform_post(path, args = {}, headers = {}) RequestsHandler.perform_post(service_key, path, args, headers) end |
#perform_put(path, args = {}, headers = {}) ⇒ Object
75 76 77 |
# File 'lib/rest/api/client.rb', line 75 def perform_put(path, args = {}, headers = {}) RequestsHandler.perform_put(service_key, path, args, headers) end |
#save! ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rest/api/client.rb', line 41 def save! begin klazz = self.class response = perform_post path, {:type => klazz, :params => {get_model_name => self.attributes}} self.attributes = response && response.is_a?(klazz) ? response.attributes : {} rescue RestApiClient::ModelErrorsException => e @errors = e.errors return false end end |
#service_key ⇒ Object
default service_key to instance methods
96 97 98 |
# File 'lib/rest/api/client.rb', line 96 def service_key SERVICE_KEY end |
#update! ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rest/api/client.rb', line 56 def update! begin klazz = self.class response = perform_put "#{path}/#{id}", {:type => klazz, :params => {get_model_name => self.attributes}} self.attributes = response && response.is_a?(klazz) ? response.attributes : {} rescue RestApiClient::ModelErrorsException => e @errors = e.errors return false end end |