README.md in coinbase_commerce_client-0.3.0 vs README.md in coinbase_commerce_client-0.4.2
- old
+ new
@@ -1,34 +1,36 @@
-[](https://github.com/viniciusborgeis/coinbase_commerce_client)
-<p>
- <img width="100%" src="https://raw.githubusercontent.com/viniciusborgeis/coinbase_commerce_client/main/assets/banner.png" alt="Solid Vite Templates">
-</p>
+<h1 align="center">
+ <br>
+ <img width="100%" src="https://raw.githubusercontent.com/viniciusborgeis/coinbase_commerce_client/main/assets/banner.png" alt="Coinbase Commerce Client">
+ <br>
+ Coinbase Commerce Client
+ <br>
+</h1>
-# Coinbase Commerce Client
-> <sub>This gem is completely inspired by official Coinbase gem [coinbase-commerce-ruby](https://github.com/coinbase/coinbase-commerce-ruby), unfortunately the oficial gem actually is deprecated, and my motivation is to continue support for this gem</sub>
+<h4 align="center">A client to handle cryptocurrency payments using <a href="https://commerce.coinbase.com/" target="_blank">Coinbase Commerce</a> platform</h4>
-Coinbase Commerce Client Ruby Gem
+<p align="center">
+ <img src="https://badge.fury.io/rb/coinbase_commerce_client.svg" alt="Coverage">
+ <img src="https://raw.githubusercontent.com/viniciusborgeis/coinbase_commerce_client/main/badge.svg" alt="Coverage">
+ <img src="https://img.shields.io/gem/dt/coinbase_commerce_client.svg?type=total" alt="Total Downloads">
+</p>
-# Table of contents
+<p align="center">
+ <a href="#ruby-version">Ruby Versions</a> •
+ <a href="#dependencies">Dependencies</a> •
+ <a href="#documentation">Docs</a> •
+ <a href="#installation">Installation</a> •
+ <a href="#usage">Usage</a> •
+ <a href="#validating-webhook-signatures">Validating Webhook</a> •
+ <a href="#testing-and-contributing">Contributing</a>
+</p>
+<sub>This gem is completely inspired by official Coinbase gem <a href="https://github.com/coinbase/coinbase-commerce-ruby">coinbase-commerce-ruby</a>, unfortunately the oficial gem actually is deprecated, and my motivation is to continue support for this gem</sub>
-<!--ts-->
-* [Ruby Versions](#ruby-version)
-* [Third Party Libraries and Dependencies](#third-party-libraries-and-dependencies)
-* [Documentation](#documentation)
-* [Installation](#installation)
-* [Usage](#usage)
- * [Checkouts](#checkouts)
- * [Charges](#charges)
- * [Events](#events)
-* [Validating webhook signatures](#validating-webhook-signatures)
-* [Testing and Contributing](#testing-and-contributing)
-<!--te-->
-
## Ruby Version
-Ruby [2.3 -> 3.1.2] are supported and tested.
+Ruby [2.3 -> 3.2.2] are supported and tested.
-## Third Party Libraries and Dependencies
+## Dependencies
The following libraries will be installed when you install the client library:
* [faraday](https://github.com/lostisland/faraday)
## Documentation
@@ -36,35 +38,59 @@
For more details visit [Coinbase API docs](https://commerce.coinbase.com/docs/api/).
To start using library, you'll need to [create a Coinbase Commmerce account](https://commerce.coinbase.com/signup).
Once you've created your Coinbase Commerce account, create an ``API_KEY`` in Settings.
+### On Ruby on Rails
+To use this gem in Ruby on Rails, first pass your Coinbase API_KEY to an environment variable or credentials. After doing this, create a new initializer called `coinbase_commerce_client.rb` and insert the following code:
+
+```ruby
+CoinbaseCommerceClient.configure do |config|
+ config.api_key = ENV['COINBASE_API_KEY']
+ # or
+ config.api_key = Rails.application.credentials.coinbase[:coinbase_api_key]
+end
+```
+
+### Pure ruby example
+
Next create a ``Client`` object for interacting with the API:
```ruby
require 'coinbase_commerce_client'
API_KEY = "API KEY"
client = CoinbaseCommerceClient::Client.new(api_key: API_KEY)
```
``Client`` contains links to every Ruby Class representations of the API resources
``Checkout, Charge, Invoices, Event``
-You can call ``list, auto_paging, create, retrieve, modify`` methods from API resource classes
+You can call ``list, auto_paging, create, resolve, cancel, retrieve, modify`` methods from API resource classes
```ruby
-client.charge.create
-client.checkout.auto_paging
-client.event.list
-client.charge.retrieve
-client.checkout.modify
-```
-as well as ``save, delete, refresh`` methods from API resource class instances.
-```ruby
+#charges
+client.charge.list
+client.charge.auto_paging
+client.charge.create <payload>
+charge = client.charge.retrieve <id>
+charge.resolve
+charge.cancel
+
+#checkout
+client.checkout.list
+client.checkout.auto_paging
+client.checkout.create <payload>
checkout = client.checkout.retrieve <id>
checkout.refresh
checkout.save
+checkout.modify <payload>
checkout.delete
+
+#events
+client.event.list
+client.event.auto_paging
+event = client.event.retrieve <id>
+
```
Each API method returns an ``APIObject`` representing the JSON response from the API, all of the models support hash and JSON representation.\
Also when the response data is parsed into Ruby objects, the appropriate ``APIObject`` subclasses will be used automatically.
All subclasses of ``APIResource`` class support ``refresh`` method. This will update their attributes and all nested data by making a fresh ``GET`` request to the relevant API endpoint.
@@ -103,21 +129,29 @@
```sh
gem install coinbase_commerce_client
```
## Usage
+* [Checkouts](#checkouts)
+* [Charges](#charges)
+* [Events](#events)
+
+
```ruby
require 'coinbase_commerce_client'
client = CoinbaseCommerceClient::Client.new(api_key: 'your_api_key')
```
-## Checkouts
+
+### Checkouts
[Checkouts API docs](https://commerce.coinbase.com/docs/api/#checkouts)
-### Retrieve
+
+#### Retrieve
```ruby
checkout = client.checkout.retrieve <checkout_id>
```
-### Create
+
+#### Create
```ruby
checkout_info = {
"name": "The Sovereign Individual",
"description": "Mastering the Transition to the Information Age",
"pricing_type": "fixed_price",
@@ -137,11 +171,11 @@
"currency": "USD"
},
:requested_info=>["name", "email"])
```
-### Update
+#### Update
```ruby
checkout = client.checkout.retrieve <checkout_id>
checkout.name = 'new name'
checkout.save
# or
@@ -149,32 +183,36 @@
"amount": "10000.00",
"currency": "USD"
})
```
-### Delete
+#### Delete
```ruby
checkout.delete
```
-### List
+
+#### List
```ruby
checkouts = client.checkout.list
```
-### Paging list iterations
+
+#### Paging list iterations
```ruby
client.checkout.auto_paging do |ch|
puts ch.id
end
```
-## Charges
-[Charges API docs](https://commerce.coinbase.com/docs/api/#charges)
-### Retrieve
+### Charges
+[Charges API docs](https://docs.cloud.coinbase.com/commerce/reference/getcharges)
+
+#### Retrieve
```ruby
charge = client.charge.retrieve <charge_id>
```
-### Create
+
+#### Create
```ruby
charge_info = {
"name": "The Sovereign Individual",
"description": "Mastering the Transition to the Information Age",
"pricing_type": "fixed_price",
@@ -192,46 +230,49 @@
:local_price=>{
"amount": "100.00",
"currency": "USD"
})
```
-### List
+
+#### List
```ruby
charges_list = client.charge.list
```
-### Cancel
+
+#### Paging list iterations
```ruby
-charge = client.charge.retrieve <charge_id>
-
-charge.cancel
+client.charge.auto_paging do |charge|
+ puts charge.id
+end
```
-### Resolve
+#### Resolve
```ruby
charge = client.charge.retrieve <charge_id>
-
charge.resolve
```
-### Paging list iterations
+#### Cancel
```ruby
-client.charge.auto_paging do |charge|
- puts charge.id
-end
+charge = client.charge.retrieve <charge_id>
+charge.cancel
```
## Events
-[Events API Docs](https://commerce.coinbase.com/docs/api/#events)
-### Retrieve
+[Events API Docs](https://docs.cloud.coinbase.com/commerce/reference/getevents)
+
+#### Retrieve
```ruby
event = client.event.retrieve <event_id>
```
-### List
+
+#### List
```ruby
events = client.event.list
```
-### Paging list iterations
+
+#### Paging list iterations
```ruby
client.event.auto_paging do |event|
puts event.id
end
```
@@ -250,10 +291,10 @@
begin
event = CoinbaseCommerceClient::Webhook.construct_event(request_payload, sig_header, WEBHOOK_SECRET)
# event handle
puts "Received event id=#{event.id}, type=#{event.type}"
status 200
- # errors handle
+ # errors handle
rescue JSON::ParserError => e
puts "json parse error"
status 400
return
rescue CoinbaseCommerceClient::Errors::SignatureVerificationError => e
\ No newline at end of file