Class: CarvoyantAPI::Base
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- CarvoyantAPI::Base
- Defined in:
- lib/carvoyant_api/resources/base.rb
Class Method Summary collapse
- .activate_session(token) ⇒ Object
- .collection_path(prefix_options = {}, query_options = nil) ⇒ Object
- .element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
- .headers ⇒ Object
Instance Method Summary collapse
Class Method Details
.activate_session(token) ⇒ Object
28 29 30 |
# File 'lib/carvoyant_api/resources/base.rb', line 28 def activate_session(token) headers.merge!({ 'Authorization' => "Bearer #{token}" }) end |
.collection_path(prefix_options = {}, query_options = nil) ⇒ Object
13 14 15 16 |
# File 'lib/carvoyant_api/resources/base.rb', line 13 def collection_path( = {}, = nil) , = () if .nil? "#{prefix()}#{element_name}/#{query_string()}" end |
.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object
7 8 9 10 11 |
# File 'lib/carvoyant_api/resources/base.rb', line 7 def element_path(id, = {}, = nil) () , = () if .nil? "#{prefix()}#{element_name}/#{URI.parser.escape id.to_s}#{query_string()}" end |
.headers ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/carvoyant_api/resources/base.rb', line 18 def headers if defined?(@headers) @headers elsif superclass != Object && superclass.headers superclass.headers else @headers ||= {} end end |
Instance Method Details
#errors ⇒ Object
49 50 51 |
# File 'lib/carvoyant_api/resources/base.rb', line 49 def errors @errors ||= Errors.new(self) end |
#save ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/carvoyant_api/resources/base.rb', line 41 def save super rescue ActiveResource::ServerError, ActiveResource::ResourceInvalid => error @remote_errors = error load_remote_errors(@remote_errors, true) false end |
#update ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/carvoyant_api/resources/base.rb', line 33 def update run_callbacks :update do connection.post(element_path(), encode, self.class.headers).tap do |response| load_attributes_from_response(response) end end end |