Module: Pipekit::Repository
- Included in:
- Activity, Deal, FieldRepository, Note, Organization, Person, User
- 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
#method_missing(method_name, *args) ⇒ Object (private)
76 77 78 79 80 81 |
# File 'lib/pipekit/repository.rb', line 76 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
#all(query = {}) ⇒ Object
8 9 10 |
# File 'lib/pipekit/repository.rb', line 8 def all(query = {}) request.get("", query) end |
#create(fields) ⇒ Object
Public: Create a record on Pipedrive.
fields - fields for the record.
Examples
create({name: "John Doe", deal_id: 123})
Returns nothing.
55 56 57 |
# File 'lib/pipekit/repository.rb', line 55 def create(fields) request.post(fields) end |
#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 44 |
# File 'lib/pipekit/repository.rb', line 41 def find_by() warn "Using `Repository#find_by` with an email may return inexact matches" if email_key?() where(, true).first end |
#initialize(request = nil) ⇒ Object
4 5 6 |
# File 'lib/pipekit/repository.rb', line 4 def initialize(request = nil) @request = request || Request.new(resource) end |
#update(id, fields) ⇒ Object
Public: Updates a record on Pipedrive.
fields - fields for the record.
Examples
update(123, {name: "Jane Doe"})
Returns nothing.
68 69 70 |
# File 'lib/pipekit/repository.rb', line 68 def update(id, fields) request.put(id, fields) end |
#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_#{.keys.first}", .values.first) rescue ResourceNotFoundError => error raise error if raise_error [] end |