0.0
No commit activity in last 3 years
No release in over 3 years
Gem for working with the ChartMogul API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0

Runtime

~> 0.9
 Project Readme

ChartMogul

This gem is designed to streamline interaction with the ChartMogul API. The initial focus has been on support for the Import API.

Installation

Add this line to your application's Gemfile:

gem 'chart_mogul'

And then execute:

$ bundle

Or install it yourself as:

$ gem install chart_mogul

Usage

Credentials are provided in the Account / API area of the ChartMogul application and comprise an account_token and secret_key.

This can be passed in when insantiating a ChartMogul::Client instance, eg:

client = ChartMogul::Client.new(account_token: 'token value', secret_key: 'secret value')

If not passed to the constructor the values returned by the CHART_MOGUL_ACCOUNT_TOKEN and CHART_MOGUL_SECRET_KEY environment variables are used.

Methods for access the API are exposed on the client.

Reading data

Reading methods, list_ prefix, are either presented as simple methods that page through all responses from the API and present a fully populated Array of typed objects.

client.list_customers  # => [ Import::Customer, Import::Customer ]

and as an iterative version, with an _each suffix, that expects a block. Useful for those situations where you're dealing with a lot of records and don't want them necessarily all in memory. This again handles the paging transparently.

The block is yielded to with a typed object.

client.list_customers_each do |customer|
  # do something with the Import::Customer here
end

Importing data

Data records are imported by passing a Hash of attributes to a create_ prefixed method.

client.create_plan({
  data_source_uuid: "ds_2323232",
  name: "Top Plan",
  interval_count: 1,
  interval_unit: :month
})

Dates and times are expected as Time objects. The gem handles the formatting required by the ChartMogul API.

Where possible pre request validation is also handled by the gem. ArgumentErrors with a description of the variable are raised in the event that pre submit validation fails.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/adambird/chart_mogul. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.