Class: PipeDrive::Base
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- PipeDrive::Base
- Defined in:
- lib/pipe_drive/base.rb
Direct Known Subclasses
Class Method Summary collapse
- .create(opts) ⇒ Object
- .delete(id) ⇒ Object
- .find_by_id(id) ⇒ Object
- .parameterize(target_string, separator) ⇒ Object
- .requester ⇒ Object
- .search_and_setup_by(type, opts, strict = false) ⇒ Object
- .update(id, opts) ⇒ Object
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(attrs) ⇒ Base
constructor
A new instance of Base.
- #parameterize(target_string, separator) ⇒ Object
- #requester ⇒ Object
- #update(opts) ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Base
Returns a new instance of Base.
4 5 6 7 8 9 |
# File 'lib/pipe_drive/base.rb', line 4 def initialize(attrs) struct_attrs = attrs[:data] || PipeDrive.hash_except(attrs, [:additional_data]) struct_attrs.merge!(attrs[:additional_data]) unless attrs[:additional_data].nil? super(struct_attrs) end |
Class Method Details
.create(opts) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/pipe_drive/base.rb', line 44 def create(opts) opts.transform_keys!{|key| field_keys[key] || key} requester.http_post("/#{resource_name}s", opts) do |result| new(result) end end |
.delete(id) ⇒ Object
59 60 61 62 |
# File 'lib/pipe_drive/base.rb', line 59 def delete(id) path = "/#{resource_name}s/#{id}" requester.http_del(path){|result| puts result} end |
.find_by_id(id) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/pipe_drive/base.rb', line 37 def find_by_id(id) path = "/#{resource_name}s/#{id}" requester.http_get(path) do |result| result[:data].nil? ? nil : new(result) end end |
.parameterize(target_string, separator) ⇒ Object
73 74 75 76 |
# File 'lib/pipe_drive/base.rb', line 73 def parameterize(target_string, separator) target_string.gsub!(/[\-_\ ]+/, separator) target_string.downcase end |
.requester ⇒ Object
33 34 35 |
# File 'lib/pipe_drive/base.rb', line 33 def requester PipeDrive.requester end |
.search_and_setup_by(type, opts, strict = false) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/pipe_drive/base.rb', line 64 def search_and_setup_by(type, opts, strict=false) target = find_by(type, opts, strict) if target.nil? create(opts) else target.update(opts) end end |
.update(id, opts) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/pipe_drive/base.rb', line 51 def update(id, opts) path = "/#{resource_name}s/#{id}" opts.transform_keys!{|key| field_keys[key] || key} requester.http_put(path, opts) do |result| new(result) end end |
Instance Method Details
#delete ⇒ Object
23 24 25 26 |
# File 'lib/pipe_drive/base.rb', line 23 def delete path = "/#{self.class.resource_name}s/#{id}" requester.http_del(path) end |
#parameterize(target_string, separator) ⇒ Object
28 29 30 |
# File 'lib/pipe_drive/base.rb', line 28 def parameterize(target_string, separator) self.class.parameterize(target_string, separator) end |
#requester ⇒ Object
11 12 13 |
# File 'lib/pipe_drive/base.rb', line 11 def requester PipeDrive.requester end |
#update(opts) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/pipe_drive/base.rb', line 15 def update(opts) path = "/#{self.class.resource_name}s/#{id}" opts.transform_keys!{|key| field_keys[key] || key} requester.http_put(path, opts) do |result| new(result) end end |