|
| 1 | +Mango |
| 2 | +===== |
| 3 | + |
| 4 | +Ruby wrapper for Mango API |
| 5 | + |
| 6 | + |
| 7 | +## Description |
| 8 | + |
| 9 | +API to interact with Mango |
| 10 | +https://getmango.com/ |
| 11 | + |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +As usual, you can install it using rubygems. |
| 16 | + |
| 17 | +``` |
| 18 | +$ gem build mango-ruby.gemspec |
| 19 | +``` |
| 20 | + |
| 21 | +``` |
| 22 | +$ gem install ./mango-ruby-0.0.1.gem |
| 23 | +``` |
| 24 | + |
| 25 | +Note: We'll be uploading the gem to [RubyGems](https://rubygems.org) in the next couple of days. |
| 26 | + |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +``` |
| 31 | +require 'mango-ruby' |
| 32 | +
|
| 33 | +Mango.api_key = ENV['MANGO_SECRET_KEY'] |
| 34 | +
|
| 35 | +params = { |
| 36 | + |
| 37 | + name: "John Doe" |
| 38 | +} |
| 39 | +
|
| 40 | +begin |
| 41 | + customer = Mango::Customer.create params |
| 42 | +rescue Mango::Error => e |
| 43 | + e.each {|code, message| ... } |
| 44 | +end |
| 45 | +``` |
| 46 | + |
| 47 | +You can set a global API_KEY (`Mango.api_key`) or override it on each request |
| 48 | + |
| 49 | + |
| 50 | +## API |
| 51 | + |
| 52 | +All the requests go through: |
| 53 | +``` |
| 54 | +Mango.request(method, url, api_key=nil, params={}, headers={}) |
| 55 | +``` |
| 56 | + |
| 57 | +But you can use CRUD methods on `Mango::Card`, `Mango::Customer`... |
| 58 | +``` |
| 59 | +def create params={}, api_key=nil |
| 60 | +def list params={}, api_key=nil |
| 61 | +def retrieve uid, params={}, api_key=nil |
| 62 | +def delete uid, params={}, api_key=nil |
| 63 | +def update uid, params={}, api_key=nil |
| 64 | +``` |
| 65 | + |
| 66 | +So this two are equivalent: |
| 67 | +``` |
| 68 | +customer = Mango::Customer.create params |
| 69 | +customer = Mango.request :post, '/customers/', api_key, params |
| 70 | +``` |
| 71 | + |
| 72 | +This are the operations available for each resource: |
| 73 | + |
| 74 | +|Resource|list|create|retrieve|update|delete|delete_all| |
| 75 | +|-|:-:|:-:|:-:|:-:|:-:|:-:| |
| 76 | +|Card | x | x | x | x | x | | |
| 77 | +|Charge | x | x | x | | | | |
| 78 | +|Customer | x | x | x | x | x | | |
| 79 | +|Installment | | | x | | | | |
| 80 | +|Queue | x | x | x | | x | x | |
| 81 | +|Refund | x | x | x | | | | |
0 commit comments