coinbase_commerce_client 0.3.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c4adff7d11dee8fb401c917dcccc4a1d571af2a26f833b9931ee3f13315199e
4
- data.tar.gz: 4b46f2cd7f8050a20b6e5763396b6e058fe387fb18e81797509472adcd749f64
3
+ metadata.gz: 1dffeec59ae055d348576c580c7d368d08f1e6cfa83eff0df98654bedc37f10c
4
+ data.tar.gz: b259d64a1f5acecbf1c1ba596d9dc81851a5f7ad95518e2978dccc372afe31fa
5
5
  SHA512:
6
- metadata.gz: 14cc887e20de18fe1b667d29eaa2c014f539e656535243dc9910696403b1ab029eae4d8199b572469368302317c1517a9b9931cd3825bf635f3e7dd1aebcec5a
7
- data.tar.gz: 6c9c4806f579bc6fc638bc45513d3d2bae10ca03474317cc3d21cc61f45b95edd2b9e1a592e9594617c33a93d779f4203d504558e56af4045130e579287e8716
6
+ metadata.gz: 36af3d120360de81dfbb33d60cbdfcce9dd06710e40e7d797d9ef04e85e1693757ae10e73a8bb768131b10e620aad992a87242eff16c73e1978fcb992680e86d
7
+ data.tar.gz: 45fe372fb55aa69c0041bca0072745558ca2f9807a0e51b3b13764834d9b14f8df5605ef1a531ca561ae2ef698d3b83b5e82838e999311600b80ef194a09dd2d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coinbase_commerce_client (0.2.0)
4
+ coinbase_commerce_client (0.4.2)
5
5
  faraday (~> 2.6)
6
6
  multipart-post (~> 2.0)
7
7
 
data/README.md CHANGED
@@ -1,32 +1,34 @@
1
- [![Coverage](badge.svg)](https://github.com/viniciusborgeis/coinbase_commerce_client)
2
- <p>
3
- <img width="100%" src="https://raw.githubusercontent.com/viniciusborgeis/coinbase_commerce_client/main/assets/banner.png" alt="Solid Vite Templates">
1
+ <h1 align="center">
2
+ <br>
3
+ <img width="100%" src="https://raw.githubusercontent.com/viniciusborgeis/coinbase_commerce_client/main/assets/banner.png" alt="Coinbase Commerce Client">
4
+ <br>
5
+ Coinbase Commerce Client
6
+ <br>
7
+ </h1>
8
+
9
+ <h4 align="center">A client to handle cryptocurrency payments using <a href="https://commerce.coinbase.com/" target="_blank">Coinbase Commerce</a> platform</h4>
10
+
11
+ <p align="center">
12
+ <img src="https://badge.fury.io/rb/coinbase_commerce_client.svg" alt="Coverage">
13
+ <img src="https://raw.githubusercontent.com/viniciusborgeis/coinbase_commerce_client/main/badge.svg" alt="Coverage">
14
+ <img src="https://img.shields.io/gem/dt/coinbase_commerce_client.svg?type=total" alt="Total Downloads">
4
15
  </p>
5
16
 
6
- # Coinbase Commerce Client
7
- > <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>
8
-
9
- Coinbase Commerce Client Ruby Gem
10
-
11
- # Table of contents
12
-
13
- <!--ts-->
14
- * [Ruby Versions](#ruby-version)
15
- * [Third Party Libraries and Dependencies](#third-party-libraries-and-dependencies)
16
- * [Documentation](#documentation)
17
- * [Installation](#installation)
18
- * [Usage](#usage)
19
- * [Checkouts](#checkouts)
20
- * [Charges](#charges)
21
- * [Events](#events)
22
- * [Validating webhook signatures](#validating-webhook-signatures)
23
- * [Testing and Contributing](#testing-and-contributing)
24
- <!--te-->
17
+ <p align="center">
18
+ <a href="#ruby-version">Ruby Versions</a>
19
+ <a href="#dependencies">Dependencies</a> •
20
+ <a href="#documentation">Docs</a>
21
+ <a href="#installation">Installation</a> •
22
+ <a href="#usage">Usage</a>
23
+ <a href="#validating-webhook-signatures">Validating Webhook</a> •
24
+ <a href="#testing-and-contributing">Contributing</a>
25
+ </p>
26
+ <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>
25
27
 
26
28
  ## Ruby Version
27
- Ruby [2.3 -> 3.1.2] are supported and tested.
29
+ Ruby [2.3 -> 3.2.2] are supported and tested.
28
30
 
29
- ## Third Party Libraries and Dependencies
31
+ ## Dependencies
30
32
 
31
33
  The following libraries will be installed when you install the client library:
32
34
  * [faraday](https://github.com/lostisland/faraday)
@@ -38,6 +40,19 @@ For more details visit [Coinbase API docs](https://commerce.coinbase.com/docs/ap
38
40
  To start using library, you'll need to [create a Coinbase Commmerce account](https://commerce.coinbase.com/signup).
39
41
  Once you've created your Coinbase Commerce account, create an ``API_KEY`` in Settings.
40
42
 
43
+ ### On Ruby on Rails
44
+ 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:
45
+
46
+ ```ruby
47
+ CoinbaseCommerceClient.configure do |config|
48
+ config.api_key = ENV['COINBASE_API_KEY']
49
+ # or
50
+ config.api_key = Rails.application.credentials.coinbase[:coinbase_api_key]
51
+ end
52
+ ```
53
+
54
+ ### Pure ruby example
55
+
41
56
  Next create a ``Client`` object for interacting with the API:
42
57
  ```ruby
43
58
  require 'coinbase_commerce_client'
@@ -48,21 +63,32 @@ client = CoinbaseCommerceClient::Client.new(api_key: API_KEY)
48
63
  ``Client`` contains links to every Ruby Class representations of the API resources
49
64
  ``Checkout, Charge, Invoices, Event``
50
65
 
51
- You can call ``list, auto_paging, create, retrieve, modify`` methods from API resource classes
66
+ You can call ``list, auto_paging, create, resolve, cancel, retrieve, modify`` methods from API resource classes
52
67
 
53
68
  ```ruby
54
- client.charge.create
55
- client.checkout.auto_paging
56
- client.event.list
57
- client.charge.retrieve
58
- client.checkout.modify
59
- ```
60
- as well as ``save, delete, refresh`` methods from API resource class instances.
61
- ```ruby
69
+ #charges
70
+ client.charge.list
71
+ client.charge.auto_paging
72
+ client.charge.create <payload>
73
+ charge = client.charge.retrieve <id>
74
+ charge.resolve
75
+ charge.cancel
76
+
77
+ #checkout
78
+ client.checkout.list
79
+ client.checkout.auto_paging
80
+ client.checkout.create <payload>
62
81
  checkout = client.checkout.retrieve <id>
63
82
  checkout.refresh
64
83
  checkout.save
84
+ checkout.modify <payload>
65
85
  checkout.delete
86
+
87
+ #events
88
+ client.event.list
89
+ client.event.auto_paging
90
+ event = client.event.retrieve <id>
91
+
66
92
  ```
67
93
 
68
94
  Each API method returns an ``APIObject`` representing the JSON response from the API, all of the models support hash and JSON representation.\
@@ -105,17 +131,25 @@ gem install coinbase_commerce_client
105
131
  ```
106
132
 
107
133
  ## Usage
134
+ * [Checkouts](#checkouts)
135
+ * [Charges](#charges)
136
+ * [Events](#events)
137
+
138
+
108
139
  ```ruby
109
140
  require 'coinbase_commerce_client'
110
141
  client = CoinbaseCommerceClient::Client.new(api_key: 'your_api_key')
111
142
  ```
112
- ## Checkouts
143
+
144
+ ### Checkouts
113
145
  [Checkouts API docs](https://commerce.coinbase.com/docs/api/#checkouts)
114
- ### Retrieve
146
+
147
+ #### Retrieve
115
148
  ```ruby
116
149
  checkout = client.checkout.retrieve <checkout_id>
117
150
  ```
118
- ### Create
151
+
152
+ #### Create
119
153
  ```ruby
120
154
  checkout_info = {
121
155
  "name": "The Sovereign Individual",
@@ -139,7 +173,7 @@ checkout = client.checkout.create(:name=>'The Sovereign Individual',
139
173
  :requested_info=>["name", "email"])
140
174
  ```
141
175
 
142
- ### Update
176
+ #### Update
143
177
  ```ruby
144
178
  checkout = client.checkout.retrieve <checkout_id>
145
179
  checkout.name = 'new name'
@@ -151,28 +185,32 @@ client.checkout.modify(<checkout_id>, "local_price": {
151
185
  })
152
186
  ```
153
187
 
154
- ### Delete
188
+ #### Delete
155
189
  ```ruby
156
190
  checkout.delete
157
191
  ```
158
- ### List
192
+
193
+ #### List
159
194
  ```ruby
160
195
  checkouts = client.checkout.list
161
196
  ```
162
- ### Paging list iterations
197
+
198
+ #### Paging list iterations
163
199
  ```ruby
164
200
  client.checkout.auto_paging do |ch|
165
201
  puts ch.id
166
202
  end
167
203
  ```
168
204
 
169
- ## Charges
170
- [Charges API docs](https://commerce.coinbase.com/docs/api/#charges)
171
- ### Retrieve
205
+ ### Charges
206
+ [Charges API docs](https://docs.cloud.coinbase.com/commerce/reference/getcharges)
207
+
208
+ #### Retrieve
172
209
  ```ruby
173
210
  charge = client.charge.retrieve <charge_id>
174
211
  ```
175
- ### Create
212
+
213
+ #### Create
176
214
  ```ruby
177
215
  charge_info = {
178
216
  "name": "The Sovereign Individual",
@@ -194,42 +232,45 @@ charge = client.charge.create(:name=>'The Sovereign Individual',
194
232
  "currency": "USD"
195
233
  })
196
234
  ```
197
- ### List
235
+
236
+ #### List
198
237
  ```ruby
199
238
  charges_list = client.charge.list
200
239
  ```
201
- ### Cancel
240
+
241
+ #### Paging list iterations
202
242
  ```ruby
203
- charge = client.charge.retrieve <charge_id>
204
-
205
- charge.cancel
243
+ client.charge.auto_paging do |charge|
244
+ puts charge.id
245
+ end
206
246
  ```
207
247
 
208
- ### Resolve
248
+ #### Resolve
209
249
  ```ruby
210
250
  charge = client.charge.retrieve <charge_id>
211
-
212
251
  charge.resolve
213
252
  ```
214
253
 
215
- ### Paging list iterations
254
+ #### Cancel
216
255
  ```ruby
217
- client.charge.auto_paging do |charge|
218
- puts charge.id
219
- end
256
+ charge = client.charge.retrieve <charge_id>
257
+ charge.cancel
220
258
  ```
221
259
 
222
260
  ## Events
223
- [Events API Docs](https://commerce.coinbase.com/docs/api/#events)
224
- ### Retrieve
261
+ [Events API Docs](https://docs.cloud.coinbase.com/commerce/reference/getevents)
262
+
263
+ #### Retrieve
225
264
  ```ruby
226
265
  event = client.event.retrieve <event_id>
227
266
  ```
228
- ### List
267
+
268
+ #### List
229
269
  ```ruby
230
270
  events = client.event.list
231
271
  ```
232
- ### Paging list iterations
272
+
273
+ #### Paging list iterations
233
274
  ```ruby
234
275
  client.event.auto_paging do |event|
235
276
  puts event.id
@@ -252,7 +293,7 @@ post '/webhooks' do
252
293
  # event handle
253
294
  puts "Received event id=#{event.id}, type=#{event.type}"
254
295
  status 200
255
- # errors handle
296
+ # errors handle
256
297
  rescue JSON::ParserError => e
257
298
  puts "json parse error"
258
299
  status 400
data/badge.svg CHANGED
@@ -1 +1 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="114" height="20" role="img" aria-label="coverage: 89.44%"><title>coverage: 89.44%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="114" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="53" height="20" fill="#97ca00"/><rect width="114" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text><text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text><text aria-hidden="true" x="865" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">89.44%</text><text x="865" y="140" transform="scale(.1)" fill="#fff" textLength="430">89.44%</text></g></svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="114" height="20" role="img" aria-label="coverage: 89.66%"><title>coverage: 89.66%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="114" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="61" height="20" fill="#555"/><rect x="61" width="53" height="20" fill="#97ca00"/><rect width="114" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text><text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text><text aria-hidden="true" x="865" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">89.66%</text><text x="865" y="140" transform="scale(.1)" fill="#fff" textLength="430">89.66%</text></g></svg>
@@ -2,10 +2,28 @@ module CoinbaseCommerceClient
2
2
  BASE_API_URL = 'https://api.commerce.coinbase.com/'.freeze
3
3
  API_VERSION = '2018-03-22'.freeze
4
4
 
5
+ class Configuration
6
+ attr_accessor :api_key
7
+
8
+ def initialize
9
+ @api_key = nil
10
+ end
11
+ end
12
+
13
+ @configuration = Configuration.new
14
+
15
+ def self.configure
16
+ yield(@configuration)
17
+ end
18
+
19
+ def self.config
20
+ @configuration
21
+ end
22
+
5
23
  class Client
6
24
  def initialize(options = {})
7
25
  check_api_key!(options[:api_key])
8
- @api_key = options[:api_key]
26
+ @api_key = options[:api_key] || CoinbaseCommerceClient.config.api_key
9
27
  @api_uri = URI.parse(options[:api_url] || BASE_API_URL)
10
28
  @api_ver = options[:api_ver] || API_VERSION
11
29
 
@@ -46,7 +64,7 @@ module CoinbaseCommerceClient
46
64
  end
47
65
 
48
66
  def check_api_key!(api_key)
49
- raise AuthenticationError, 'No API key provided' unless api_key
67
+ raise CoinbaseCommerceClient::Errors::AuthenticationError, 'No API key provided' unless (api_key || CoinbaseCommerceClient.config.api_key)
50
68
  end
51
69
 
52
70
  def request(method, path, params = {})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CoinbaseCommerceClient
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coinbase_commerce_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinicius Borges
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-17 00:00:00.000000000 Z
11
+ date: 2024-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -123,14 +123,14 @@ files:
123
123
  - lib/coinbase_commerce_client/version.rb
124
124
  - lib/coinbase_commerce_client/webhooks.rb
125
125
  - sig/coinbase_commerce_client.rbs
126
- homepage: https://github.com/viniciusborgeis/coinbase_commerce_client
126
+ homepage: https://github.com/BiteCraft/coinbase_commerce_client
127
127
  licenses:
128
128
  - MIT
129
129
  metadata:
130
- homepage_uri: https://github.com/viniciusborgeis/coinbase_commerce_client
131
- source_code_uri: https://github.com/viniciusborgeis/coinbase_commerce_client
132
- changelog_uri: https://github.com/viniciusborgeis/coinbase_commerce_client
133
- post_install_message:
130
+ homepage_uri: https://github.com/BiteCraft/coinbase_commerce_client
131
+ source_code_uri: https://github.com/BiteCraft/coinbase_commerce_client
132
+ changelog_uri: https://github.com/BiteCraft/coinbase_commerce_client
133
+ post_install_message:
134
134
  rdoc_options: []
135
135
  require_paths:
136
136
  - lib
@@ -145,8 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.3.7
149
- signing_key:
148
+ rubygems_version: 3.2.3
149
+ signing_key:
150
150
  specification_version: 4
151
151
  summary: Coinbase Commerce integration client for crypto payments
152
152
  test_files: []