Class: Pipekit::Request

Inherits:
Object
  • Object
show all
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

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 = "", 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



59
60
61
62
# File 'lib/pipekit/request.rb', line 59

def get(id = "", query = {})
  uri = uri(id)
  _get(uri, query, get_request(uri, query))
end

#post(data) ⇒ Object



68
69
70
# File 'lib/pipekit/request.rb', line 68

def post(data)
  response_from self.class.post(uri, options(body: data))
end

#put(id, data) ⇒ Object



64
65
66
# File 'lib/pipekit/request.rb', line 64

def put(id, data)
  response_from self.class.put(uri(id), options(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.

This also uses the “request_all_pages” config option when set to do multiple requests, getting around Pipedrive’s pagination



37
38
39
40
41
42
43
44
45
46
# File 'lib/pipekit/request.rb', line 37

def search_by_field(field:, value:)
  query = {field_type: "#{resource}Field",
           field_key: Config.field_id(resource, field),
           return_item_ids: true,
           term: Config.field_value_id(resource, field, value),
           exact_match: 1
  }

  get_request("/searchResults/field", query).response(resource)
end