Module: Pipekit::Repository
- Included in:
- Deal, Note, Person, PersonField
- Defined in:
- lib/pipekit/repository.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ 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 = Pipekit::Request.new) ⇒ Object
-
#update(id, fields) ⇒ Object
Public: Updates a record on Pipedrive.
-
#where(options) ⇒ 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)
81 82 83 84 85 86 |
# File 'lib/pipekit/repository.rb', line 81 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 |
Class Method Details
.included(base) ⇒ Object
69 70 71 |
# File 'lib/pipekit/repository.rb', line 69 def self.included(base) base.send :extend, ClassMethods end |
Instance Method Details
#all ⇒ Object
9 10 11 |
# File 'lib/pipekit/repository.rb', line 9 def all request.get("/#{uri}") 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.
52 53 54 |
# File 'lib/pipekit/repository.rb', line 52 def create(fields) request.post("/#{uri}", 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.
39 40 41 |
# File 'lib/pipekit/repository.rb', line 39 def find_by() where().first end |
#initialize(request = Pipekit::Request.new) ⇒ Object
5 6 7 |
# File 'lib/pipekit/repository.rb', line 5 def initialize(request = Pipekit::Request.new) @request = request end |
#update(id, fields) ⇒ Object
Public: Updates a record on Pipedrive.
fields - fields for the record.
Examples
update(123, {name: "Jane Doe"})
Returns nothing.
65 66 67 |
# File 'lib/pipekit/repository.rb', line 65 def update(id, fields) request.put("/#{uri}/#{id}", fields) end |
#where(options) ⇒ 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.
24 25 26 |
# File 'lib/pipekit/repository.rb', line 24 def where() send("get_by_#{.keys.first}", .values.first) end |