Module: Wunderlist::Helper
- Defined in:
- lib/wunderlist/helper.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #model_name ⇒ Object
- #path ⇒ Object
- #plural_model_name ⇒ Object
- #resource_path ⇒ Object
- #save ⇒ Object
- #to_hash ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
18 19 20 |
# File 'lib/wunderlist/helper.rb', line 18 def create self.api.request :post, path, self.to_hash end |
#destroy ⇒ Object
31 32 33 34 35 36 |
# File 'lib/wunderlist/helper.rb', line 31 def destroy self.api.request :delete, resource_path, {:revision => self.revision} self.id = nil self end |
#model_name ⇒ Object
46 47 48 49 50 51 |
# File 'lib/wunderlist/helper.rb', line 46 def model_name self.class.to_s.gsub('Wunderlist::',''). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z])([A-Z])/, '\1_\2'). downcase end |
#path ⇒ Object
42 43 44 |
# File 'lib/wunderlist/helper.rb', line 42 def path "api/v1/#{plural_model_name}" end |
#plural_model_name ⇒ Object
53 54 55 |
# File 'lib/wunderlist/helper.rb', line 53 def plural_model_name "#{model_name}s" end |
#resource_path ⇒ Object
38 39 40 |
# File 'lib/wunderlist/helper.rb', line 38 def resource_path "api/v1/#{plural_model_name}/#{self.id}" end |
#save ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/wunderlist/helper.rb', line 22 def save if self.id.nil? res = self.create else res = self.update end set_attrs(res) end |
#to_hash ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/wunderlist/helper.rb', line 4 def to_hash i_vs = self.instance_variables i_vs.delete_if {|i_v| i_v.to_s == '@api'} hash = {} i_vs.each {|var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) } hash end |
#update ⇒ Object
14 15 16 |
# File 'lib/wunderlist/helper.rb', line 14 def update self.api.request :put, resource_path, self.to_hash end |