spackle-ruby 0.0.13 → 0.0.15

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: a9db8095ffa764bd7168fd58dd693be699a3935bfec20f94b47083f48ac7c6c3
4
- data.tar.gz: f9c1ac487e16061759e4c617e49f7962567f32fd0559b5917b9de106c53af9fd
3
+ metadata.gz: 62488969b7e0cbd8420db57f77f1f75b7c7b0cd7e9ca246521bc01c3a91c94f0
4
+ data.tar.gz: ed07a041cf115c6120bdfc1940a11dc322908c95e3e10fb99842a74aa7dec32a
5
5
  SHA512:
6
- metadata.gz: c9551e7c797ad58938d4de81dc5aca6016cf344b72fdca62a2d24f90d7124ff5d02c5497ebdcd77fbd13a8ba6c9abbeff0edfe365ff7196b07541de8be2e6806
7
- data.tar.gz: 37408f32c5a15421157b4ab3987cf7b01eda0c341136e33772890476549a76df1694a157a5c71901b0ec23bf627ab7d86b644bf947f13dbfe21fe4e4197e706e
6
+ metadata.gz: c89eb3973dbdbd7b3b72d9c83cbbd62e0d7eb06c03c84f4bd3f19978e52d3f6881a62dd4367839ba48ce1133cce0dc611be07bd6c01a5339d67f292c02be6dba
7
+ data.tar.gz: f26e1cb1ea3c87a9baa86b3108801bb2fd4c4775c2e1850e29d3684dfcb23c1b25d2dcc80ef94a01936179096731c01cfdecec90b8a20dc72194dae969ee4e56
data/Gemfile CHANGED
@@ -7,4 +7,7 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
7
7
  gem "rake", "~> 13.0"
8
8
  gem "nokogiri", "~> 1.13"
9
9
  gem "minitest", "~> 5.18"
10
+ gem "webmock", "~> 3.18"
10
11
  gem "stripe", "~> 8.3"
12
+ gem "http", "~> 5.1"
13
+ gem "connection_pool", "~> 2.4"
@@ -1,46 +1,43 @@
1
- require 'net/http'
1
+ require 'connection_pool'
2
+ require 'http'
2
3
  require 'json'
3
4
  require 'logger'
4
5
 
5
6
  module Spackle
6
7
  class EdgeStore < BaseStore
7
8
  def initialize()
8
- edge_uri = URI(Spackle.edge_base)
9
- @edge_http = Net::HTTP.new(edge_uri.host, edge_uri.port)
10
- @edge_http.use_ssl = true
9
+ @edge = ConnectionPool.new(size: 10, timeout: 5) do
10
+ HTTP.persistent(Spackle.edge_base)
11
+ end
11
12
 
12
- api_uri = URI(Spackle.api_base)
13
- @api_http = Net::HTTP.new(api_uri.host, api_uri.port)
14
- @api_http.use_ssl = true
13
+ @api = ConnectionPool.new(size: 10, timeout: 5) do
14
+ HTTP.persistent(Spackle.api_base)
15
+ end
15
16
  end
16
17
 
17
18
  def get_customer_data(id)
18
- request = Net::HTTP::Get.new(Spackle.edge_base + '/customers/' + id + '/state')
19
- request['Authorization'] = 'Bearer ' + Spackle.api_key
20
- request['X-Spackle-Schema-Version'] = Spackle.version.to_s
19
+ @edge.with do |http|
20
+ response = http.auth("Bearer #{Spackle.api_key}").get(Spackle.edge_base + '/customers/' + id + '/state').flush
21
21
 
22
- response = @edge_http.request(request)
23
- if response.code != '200'
24
- return fetch_state_from_api(id)
25
- end
22
+ if response.code != 200
23
+ return fetch_state_from_api(id)
24
+ end
26
25
 
27
- JSON.parse(response.body)
26
+ return JSON.parse(response.body)
27
+ end
28
28
  end
29
29
 
30
30
  def fetch_state_from_api(id)
31
31
  Util.log_warn("Customer #{id} not found. Fetching from API...")
32
- request = Net::HTTP::Get.new(Spackle.api_base + '/customers/' + id + '/state')
33
- request['Authorization'] = 'Bearer ' + Spackle.api_key
34
- request['X-Spackle-Schema-Version'] = Spackle.version.to_s
35
-
36
- response = @api_http.request(request)
37
- if response.code != '200'
38
- puts response.code
39
- puts response.body
40
- raise SpackleError.new "Customer #{id} not found"
41
- end
32
+ @api.with do |http|
33
+ response = http.auth("Bearer #{Spackle.api_key}").get(Spackle.api_base + '/customers/' + id + '/state').flush
34
+
35
+ if response.code != 200
36
+ raise SpackleError.new "Customer #{id} not found"
37
+ end
42
38
 
43
- JSON.parse(response.body)
39
+ return JSON.parse(response.body)
40
+ end
44
41
  end
45
42
  end
46
43
  end
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.13"
5
+ s.version = "0.0.15"
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."
@@ -20,9 +20,12 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency "nokogiri", "~> 1.13"
22
22
  s.add_dependency "stripe", "~> 8.3"
23
+ s.add_dependency "http", "~> 5.1"
24
+ s.add_dependency "connection_pool", "~> 2.4"
23
25
 
24
26
  s.add_development_dependency "rake", "~> 13.0"
25
27
  s.add_development_dependency "minitest", "~> 5.18"
28
+ s.add_development_dependency "webmock", "~> 3.18"
26
29
 
27
30
  ignored = Regexp.union(
28
31
  /\A\.editorconfig/,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spackle-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spackle
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '8.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: http
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: connection_pool
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.4'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +94,20 @@ dependencies:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
96
  version: '5.18'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.18'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.18'
69
111
  description: Spackle is the easiest way to integrate your Ruby app with Stripe Billing.
70
112
  See https://www.spackle.so for details.
71
113
  email: support@spackle.so