spackle-ruby 0.0.19.beta → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cba8dd3558c9f2fd420c6012270d7a64b75a47abbeb7e78def87a708a7da9f8e
4
- data.tar.gz: f0e6d00f8074fd77d142a27c041dbda74423b75146d66ed2037e90a2dc9f8461
3
+ metadata.gz: 5e308f6efcd3b1382dbe36a32a0de17b053b02caab96e82922fefed84ae02252
4
+ data.tar.gz: 2ac13819cd9ec91fa3fc92f3dc2025851e179c9b39895040ac75b17de9bc01c1
5
5
  SHA512:
6
- metadata.gz: 63867ff2ce77badd85923ab5b1cc73445b13e4bd7805256fc6ca4304ae824f725cfcbae90c8cdcc07e25a5a00a552899c0f07291e65d6dbc2f9051a4c8f5ecb3
7
- data.tar.gz: 934bb37bc4be6ac675663a499ecb2885d68c7f59ea536c83f538f71625d4ee0894b1f2e3366f319307479f050a6f721323d731327087620a6684c8ec7ebbe992
6
+ metadata.gz: 533f9b6ece5e3cf29a1da44bd95d8bc8241b6bb517e149b3413f9e4e0c9e0e33a998d148720c4ef6b968310e41601d40c608a3d062a25961841981e794bccb54
7
+ data.tar.gz: 1feaa3357a5bfb08e11813743ba864ca0084ad24d7c57ead7034e51d86bcc09208d5cd2e72c3229be5a4a15d3a94a5835b560ec4eb22dbfbca08413a7d00b637
data/README.md CHANGED
@@ -25,7 +25,7 @@ gem 'spackle-ruby'
25
25
  ```
26
26
 
27
27
  ### Configure your environment
28
- In order to use Spackle, you need to configure your API key on the `Spackle` module. You can find your API key in Spackle app [settings page](https://dashboard.stripe.com/settings/apps/so.spackle.stripe).
28
+ In order to use Spackle, you need to configure your secret key on the `Spackle` module. You can find your secret key in Spackle app [settings page](https://dashboard.stripe.com/settings/apps/so.spackle.stripe).
29
29
 
30
30
  ```ruby
31
31
  require 'spackle'
@@ -33,14 +33,6 @@ require 'spackle'
33
33
  Spackle.api_key = "<api key>"
34
34
  ```
35
35
 
36
- ### Bootstrap the client (optional)
37
-
38
- The Spackle client requires a single initialization step that includes a network request. To front load this process, you can call the `bootstrap` method in your codebase.
39
-
40
- ```ruby
41
- Spackle.bootstrap()
42
- ```
43
-
44
36
  ## Usage
45
37
 
46
38
  ### Pricing tables
@@ -59,6 +51,8 @@ pricing_table = Spackle::PricingTable.retrieve("abcde123")
59
51
  intervals: string[]
60
52
  products: {
61
53
  id: string
54
+ name: string
55
+ description: string
62
56
  features: {
63
57
  id: string
64
58
  name: string
@@ -67,13 +61,14 @@ pricing_table = Spackle::PricingTable.retrieve("abcde123")
67
61
  value_flag: boolean
68
62
  value_limit: number | null
69
63
  }[]
70
- name: string
71
64
  prices: {
72
65
  month?: {
66
+ id: string
73
67
  unit_amount: number
74
68
  currency: string
75
69
  }
76
70
  year?: {
71
+ id: string
77
72
  unit_amount: number
78
73
  currency: string
79
74
  }
@@ -168,7 +163,7 @@ Then configure the file store in your application:
168
163
  Spackle.store = Spackle::FileStore.new('/app/spackle.json')
169
164
  ```
170
165
 
171
- ## Usage in test environments
166
+ #### Usage in test environments
172
167
 
173
168
  In production, Spackle requires a valid Stripe customer. However, that is not ideal in testing or some development environments. As an alternative, you can use an in-memory store to test your application with seed data.
174
169
 
@@ -4,13 +4,11 @@ module Spackle
4
4
  class SpackleConfiguration
5
5
  attr_accessor :api_key
6
6
  attr_accessor :api_base
7
- attr_accessor :edge_base
8
7
  attr_reader :logger
9
8
  attr_reader :version
10
9
 
11
10
  def initialize
12
11
  @api_base = 'https://api.spackle.so/v1'
13
- @edge_base = 'https://us-west-2.edge.spackle.so'
14
12
  @log_level = Logger::WARN
15
13
  @logger = Logger.new(STDOUT, level: @log_level)
16
14
  @version = 1
@@ -28,7 +26,7 @@ module Spackle
28
26
 
29
27
  def store()
30
28
  if @store == nil
31
- @store = EdgeStore.new
29
+ @store = ApiStore.new
32
30
  end
33
31
  @store
34
32
  end
@@ -0,0 +1,30 @@
1
+ require 'faraday'
2
+ require "faraday/net_http_persistent"
3
+ require 'json'
4
+ require 'logger'
5
+
6
+ module Spackle
7
+ class ApiStore < BaseStore
8
+ def initialize()
9
+ @api = Faraday.new(
10
+ url: Spackle.api_base,
11
+ headers: {
12
+ 'Authorization' => "Bearer #{Spackle.api_key}",
13
+ 'X-Spackle-Schema-Version' => Spackle.version.to_s,
14
+ }
15
+ ) do |faraday|
16
+ faraday.adapter :net_http_persistent
17
+ end
18
+ end
19
+
20
+ def get_customer_data(id)
21
+ response = @api.get("/customers/#{id}/state")
22
+
23
+ if response.status != 200
24
+ raise SpackleError.new "Customer #{id} not found"
25
+ end
26
+
27
+ return JSON.parse(response.body)
28
+ end
29
+ end
30
+ end
data/lib/spackle.rb CHANGED
@@ -8,7 +8,7 @@ require 'spackle/util'
8
8
  require 'spackle/waiters'
9
9
 
10
10
  require 'spackle/stores/base'
11
- require 'spackle/stores/edge'
11
+ require 'spackle/stores/api'
12
12
  require 'spackle/stores/file'
13
13
  require 'spackle/stores/memory'
14
14
 
@@ -28,7 +28,6 @@ module Spackle
28
28
 
29
29
  def_delegators :@config, :api_key, :api_key=
30
30
  def_delegators :@config, :api_base, :api_base=
31
- def_delegators :@config, :edge_base, :edge_base=
32
31
  def_delegators :@config, :log_level, :log_level=
33
32
  def_delegators :@config, :store, :store=
34
33
  def_delegators :@config, :logger, :logger=
data/spackle.gemspec CHANGED
@@ -2,7 +2,7 @@ $LOAD_PATH.unshift(::File.join(::File.dirname(__FILE__), "lib"))
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "spackle-ruby"
5
- s.version = "0.0.19.beta"
5
+ s.version = "0.0.20"
6
6
  s.summary = "Spackle Ruby gem"
7
7
  s.description = "Spackle is the easiest way to integrate your Ruby app with Stripe Billing. " \
8
8
  "See https://www.spackle.so for details."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spackle-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19.beta
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spackle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-08 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -125,8 +125,8 @@ files:
125
125
  - lib/spackle/customer.rb
126
126
  - lib/spackle/pricing_table.rb
127
127
  - lib/spackle/spackle_configuration.rb
128
+ - lib/spackle/stores/api.rb
128
129
  - lib/spackle/stores/base.rb
129
- - lib/spackle/stores/edge.rb
130
130
  - lib/spackle/stores/file.rb
131
131
  - lib/spackle/stores/memory.rb
132
132
  - lib/spackle/util.rb
@@ -152,9 +152,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - ">"
155
+ - - ">="
156
156
  - !ruby/object:Gem::Version
157
- version: 1.3.1
157
+ version: '0'
158
158
  requirements: []
159
159
  rubygems_version: 3.4.10
160
160
  signing_key:
@@ -1,51 +0,0 @@
1
- require 'faraday'
2
- require "faraday/net_http_persistent"
3
- require 'json'
4
- require 'logger'
5
-
6
- module Spackle
7
- class EdgeStore < BaseStore
8
- def initialize()
9
- @edge = Faraday.new(
10
- url: Spackle.edge_base,
11
- headers: {
12
- 'Authorization' => "Bearer #{Spackle.api_key}",
13
- 'X-Spackle-Schema-Version' => Spackle.version.to_s,
14
- }
15
- ) do |faraday|
16
- faraday.adapter :net_http_persistent
17
- end
18
-
19
- @api = Faraday.new(
20
- url: Spackle.api_base,
21
- headers: {
22
- 'Authorization' => "Bearer #{Spackle.api_key}",
23
- 'X-Spackle-Schema-Version' => Spackle.version.to_s,
24
- }
25
- ) do |faraday|
26
- faraday.adapter :net_http_persistent
27
- end
28
- end
29
-
30
- def get_customer_data(id)
31
- response = @edge.get("/customers/#{id}/state")
32
-
33
- if response.status != 200
34
- return fetch_state_from_api(id)
35
- end
36
-
37
- return JSON.parse(response.body)
38
- end
39
-
40
- def fetch_state_from_api(id)
41
- Util.log_warn("Customer #{id} not found. Fetching from API...")
42
- response = @api.get(Spackle.api_base + "/customers/#{id}/state")
43
-
44
- if response.status != 200
45
- raise SpackleError.new "Customer #{id} not found"
46
- end
47
-
48
- return JSON.parse(response.body)
49
- end
50
- end
51
- end