blinkbid / chargify_wrapper

Wrapper for Chargify API
0 stars 0 forks source link

feat(json): replace XML with JSON as API comunication format #11

Closed rscardinho closed 1 month ago

rscardinho commented 1 month ago

N/A

Feature

This gem was initially made using XML as data format to comunicate with Chargify API because there was a problem on casting date fields in the response json. Since we are planning to add more endpoints that do not exist in XML format, it was required to setup the json data format in order to keep the same structure on all endpoints.

This was done by setting UTC as the default timezone (chargify provides the dates with timezone included) and activating both JSON parse_json_times and ActiveSupport's use_standard_json_time_format. Those three settings enables the dates coming from Chargify API to be parsed properly as an DateTime ruby object.

Beyond that, the setup for VCR got improved by creating a new cassette for each spec and hiding sensitive information from the cassettes.

Setup

Q & A

Run an irb on your console

irb

Paste the following script, replacing needed data

require 'chargify_wrapper'

ChargifyWrapper.configure do |config|
  config.subdomain = 'your-subdomain' # like blinkbid-local
  config.api_key = 'your-api-key' # same as set on blinkbid-app. you can get from rails credentials:show -e local
end

subscription = ChargifyWrapper::Subscription.find(SUBSCRIPTION_ID) # an existing chargify subscription id
subscription.delayed_cancel(reason: 'test', code: 'test')

Both rerquests should work as expected, finding the subscription and setting it to be cancelled