Module: Pipekit::Repository
- Included in:
- Deal, FieldRepository, Note, Organization, Person
- Defined in:
- lib/pipekit/repository.rb
Instance Method Summary collapse
- #all(query = {}) ⇒ Object
-
#create(fields) ⇒ Object
Public: Create a record on Pipedrive.
-
#find_by(options) ⇒ Object
Public: Get the first record by one field from Pipedrive.
- #initialize(request = nil) ⇒ Object
-
#update(id, fields) ⇒ Object
Public: Updates a record on Pipedrive.
-
#where(options, raise_error = false) ⇒ Object
Public: Get all records from Pipedrive by one of the record’s fields.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
permalink #method_missing(method_name, *args) ⇒ Object (private)
[View source]
75 76 77 78 79 80 |
# File 'lib/pipekit/repository.rb', line 75 def method_missing(method_name, *args) super unless method_name =~ /^get_by/ field = method_name.to_s.gsub("get_by_", "") get_by_field(field: field, value: args[0]) end |
Instance Method Details
permalink #all(query = {}) ⇒ Object
[View source]
8 9 10 |
# File 'lib/pipekit/repository.rb', line 8 def all(query = {}) request.get("", query) end |
permalink #create(fields) ⇒ Object
Public: Create a record on Pipedrive.
fields - fields for the record.
Examples
create({name: "John Doe", deal_id: 123})
Returns nothing.
54 55 56 |
# File 'lib/pipekit/repository.rb', line 54 def create(fields) request.post(fields) end |
permalink #find_by(options) ⇒ Object
Public: Get the first record by one field from Pipedrive.
options - A Hash with one key-value pair. Key is a field name and values is a field value.
Examples
find_by(name: "John Doe")
find_by(github_username: "pipedriver")
find_by(id: 123)
Returns a Hash or nil if none found.
41 42 43 |
# File 'lib/pipekit/repository.rb', line 41 def find_by() where(, true).first end |
permalink #initialize(request = nil) ⇒ Object
[View source]
4 5 6 |
# File 'lib/pipekit/repository.rb', line 4 def initialize(request = nil) @request = request || Request.new(resource) end |
permalink #update(id, fields) ⇒ Object
Public: Updates a record on Pipedrive.
fields - fields for the record.
Examples
update(123, {name: "Jane Doe"})
Returns nothing.
67 68 69 |
# File 'lib/pipekit/repository.rb', line 67 def update(id, fields) request.put(id, fields) end |
permalink #where(options, raise_error = false) ⇒ Object
Public: Get all records from Pipedrive by one of the record’s fields.
options - A Hash with one key-value pair. Key is a field name and values is a field value.
Examples
where(name: "John Doe")
where(github_username: "pipedriver")
where(id: 123)
Returns array of Hashes.
23 24 25 26 27 28 |
# File 'lib/pipekit/repository.rb', line 23 def where(, raise_error = false) send("get_by_#{options.keys.first}", .values.first) rescue ResourceNotFoundError => error raise error if raise_error [] end |