Class: Lettr::Base
- Inherits:
-
Object
- Object
- Lettr::Base
- Defined in:
- lib/lettr/base.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{ :accept => :json }
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
- #[](path) ⇒ Object
- #destroy(object) ⇒ Object
- #find(path) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #save(object) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/lettr/base.rb', line 7 def initialize @client = RestClient::Resource.new self.class.site_url, self.class.user, self.class.pass end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/lettr/base.rb', line 5 def client @client end |
Class Method Details
Instance Method Details
#[](path) ⇒ Object
30 31 32 |
# File 'lib/lettr/base.rb', line 30 def [] path client[path] end |
#destroy(object) ⇒ Object
22 23 24 |
# File 'lib/lettr/base.rb', line 22 def destroy object client[object.path].delete DEFAULT_HEADERS end |
#find(path) ⇒ Object
26 27 28 |
# File 'lib/lettr/base.rb', line 26 def find path ActiveSupport::JSON.decode(client[path].get DEFAULT_HEADERS) end |
#save(object) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/lettr/base.rb', line 15 def save object path = object.collection_path payload = object.to_payload payload.merge! :files => object.files if object.respond_to?(:files) && object.files client[path].post(payload, DEFAULT_HEADERS) end |