Class: Pipekit::Request
- Inherits:
-
Object
- Object
- Pipekit::Request
- Includes:
- HTTParty
- Defined in:
- lib/pipekit/request.rb
Constant Summary collapse
- PIPEDRIVE_URL =
"https://api.pipedrive.com/v1"- DEFAULT_PAGINATION_LIMIT =
500
Instance Method Summary collapse
-
#get(id = nil, query = {}) ⇒ Object
Public: Pipedrive GET API call - does a GET request to the Pipedrive API based on the resource passed in the initialiser.
-
#initialize(resource) ⇒ Request
constructor
A new instance of Request.
- #post(data) ⇒ Object
- #put(id, data) ⇒ Object
-
#search_by_field(field:, value:) ⇒ Object
Public: Pipedrive /searchField API call.
Constructor Details
#initialize(resource) ⇒ Request
Returns a new instance of Request.
13 14 15 16 |
# File 'lib/pipekit/request.rb', line 13 def initialize(resource) @resource = resource self.class.debug_output $stdout if Config.fetch("debug_requests") end |
Instance Method Details
#get(id = nil, query = {}) ⇒ Object
Public: Pipedrive GET API call - does a GET request to the Pipedrive API based on the resource passed in the initialiser
id - If the resource being searched for has an id query - An optional query string start - The offset with which to start the query
As long as “request_all_pages” is not set to false in the config this will recursively call #get until all the pages of the request have been fetched from pipedrive Pipedrive until everything available has been received
55 56 57 |
# File 'lib/pipekit/request.rb', line 55 def get(id = nil, query = {}) _get(id, query, get_request(id, query)) end |
#post(data) ⇒ Object
63 64 65 |
# File 'lib/pipekit/request.rb', line 63 def post(data) response_from self.class.post(uri, (body: data)) end |
#put(id, data) ⇒ Object
59 60 61 |
# File 'lib/pipekit/request.rb', line 59 def put(id, data) response_from self.class.put(uri(id), (body: data)) end |
#search_by_field(field:, value:) ⇒ Object
Public: Pipedrive /searchField API call.
type - Type of the field:
:person - person fields
:deal - deal fields
field - The name of the field.
If it's the custom field the id of the field should be stored in `config/pipedrive.yml`.
value - The value of the field.
Examples
search_by_field(field: :cohort, value: 119)
search_by_field(field: :github_username, value: "octocat")
Returns an array of Response objects or throws a ResourceNotFoundError if it couldn’t find anything.
34 35 36 37 38 39 40 41 42 |
# File 'lib/pipekit/request.rb', line 34 def search_by_field(field:, value:) query = {field_type: "#{resource}Field", field_key: Config.field_id(resource, field), return_item_ids: true, term: value } response_from self.class.get("/searchResults/field", (query: query)) end |