sowderca / connectwise-ruby-sdk

A gem to provide a ruby client to Connectwise's REST API
10 stars 17 forks source link

Add a configuration value for API version #4

Open jaredmoody opened 5 years ago

jaredmoody commented 5 years ago

According to the documentation, the way to specify the specific API version you want is with an accept header like: "application/vnd.connectwise.com+json; version=3.0.0"

Currently I'm doing this to set it:

ConnectWise::ApiClient.default.default_headers['Accept'] = "application/vnd.connectwise.com+json; version=3.0.0"

but it would be nice if I could just pass the version in the configuration block like so:

ConnectWise.configure do |config|
  config.api_version = '3.0.0'
end

What do you think about adding that? I'd be happy to submit a PR if you like the idea.

jaredmoody commented 5 years ago

I tagged the wrong issue in my commit - this is still unresolved, can you re-open? However, perhaps a different approach to the issue would be better here:

Since the fields that are passed to the CW API are all explicitly defined, you really can't use this library with new API versions like 3.0.1 - at least you can't pass any of the new fields defined.

Instead of allowing configuration of the API version, since this library is tied to 3.0.0 (unless a major update is made), perhaps should be added "application/vnd.connectwise.com+json; version=3.0.0" as the default Accepts header for all requests.

sowderca commented 5 years ago

@jaredmoody I've thought some more about this and I think that your idea of defaulting the Accepts header to mirror the version of the API that the models were generated from is the best solution. According to the documentation the API will attempt to convert the endpoint to the new mode which should help with usability. I also noticed that they have moved where the OpenAPI specification files were stored which was causing the gem's models to be a bit outdated. I'll push an update here in a minute using the new specs.