taylorbrooks / closeio

A Ruby wrapper for the Close.io API
http://developer.close.com
MIT License
45 stars 57 forks source link

list_opportunities endpoint adds query param to filter queries #31

Closed ayb closed 7 years ago

ayb commented 7 years ago

The "list opportunities" endpoint does not follow the Close.io API guidelines.

Specifically: it assumes that all filters are used as queries (via the "query") parameter. As a result it is prepending query to the URL for filters and yielding incorrect output/results.

ref:

def list_opportunities(options={})
  get(opportunity_path, query: options)
end

For example, when I try the following in console:

close = Closeio::Client.new(API_KEY)
close.list_opportunities(date_created__gte: '2016-08-01T00:54:51.337000+00:00')

I see the gem queries the following URL: https://app.close.io/api/v1/opportunity/?query%5Bdate_created__gte%5D=2016-08-01T00%3A54%3A51.337000%2B00%3A00

Per the API docs: https://developer.close.io/#opportunities

i.e.

GET /opportunity/{?lead_id, user_id, status_id, status_label, status_type, date_created__{lt|gt|lte|gte}, date_updated__{lt|gt|lte|gte}, date_won__{lt|gt|lte|gte}, value_period, query, _order_by, _group_by, _fields,lead_query}

The correct URL for filtering opportunities based on this parameter should be: https://app.close.io/api/v1/opportunity/?date_created__gte=2016-08-01T00:54:51.337000+00:00

taylorbrooks commented 7 years ago

Fixed in 2.6.2