fastly 2.2.0 → 2.3.0

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
- SHA1:
3
- metadata.gz: 1b2d0dd8d907e2b7f4c37cddcf867c85720a3e5e
4
- data.tar.gz: 5fe96ced94e86970b9d46462e628078f151eaab9
2
+ SHA256:
3
+ metadata.gz: 77c4d6df5e0621d48acdbecb30dd4245dbcacc9225ca5485a3da71871108a006
4
+ data.tar.gz: 232962c9bb9513d029cb23ae84e066a64b1238d5fe03c3ef0612d9bf946ade1c
5
5
  SHA512:
6
- metadata.gz: 59afefcb6fc28167b3c23e6f94dd8bf854ba37550a210d6120ff69e74007ab19c5e1a77ebf5f58f6fed0b2269ffcb31958a8769ab4a7302db37f4823944ce382
7
- data.tar.gz: 616e90bf3b77370a0c7f5f8679c17e89b37ef782ee9e1ea5039a98a436123261d85b76415be68de987ef4aa3e0b3fbb4001948873e42c2cb1adbe51c5db109d1
6
+ metadata.gz: aa2ad393f31e11794e9e8bc900583793ef301c84bceb07d7eaa68440f4ebf880de0d748290e2bfc09a113e007294f0fbb44f164895f40e1ab7c0c43450da33a1
7
+ data.tar.gz: 82ba77b6314b2ffdebbfde260a121664a4b2687e9ad2e2f7950fd267278f3037dc33a6358e5d5d8a6b0998d4f8a6e3ea59a12b8b1e91d23dd186be66a56df8be
@@ -3,11 +3,11 @@ script: 'bundle exec rake test:unit'
3
3
  sudo: false
4
4
  matrix:
5
5
  include:
6
- - rvm: 2.1.10
6
+ - rvm: 2.3.8
7
7
  gemfile: gemfiles/HEAD.gemfile
8
- - rvm: 2.2.7
8
+ - rvm: 2.4.5
9
9
  gemfile: gemfiles/HEAD.gemfile
10
- - rvm: 2.3.4
10
+ - rvm: 2.5.3
11
11
  gemfile: gemfiles/HEAD.gemfile
12
- - rvm: 2.4.1
12
+ - rvm: 2.6.0
13
13
  gemfile: gemfiles/HEAD.gemfile
@@ -80,9 +80,7 @@ class Fastly
80
80
  end
81
81
 
82
82
  # Return a User object representing the current logged in user.
83
- # NOTE: requires you to be fully authed - will not work with only an API key
84
83
  def current_user
85
- fail FullAuthRequired unless fully_authed?
86
84
  @current_user ||= get(User)
87
85
  end
88
86
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'cgi'
3
5
  require 'net/http' # also requires uri
@@ -9,28 +11,19 @@ class Fastly
9
11
 
10
12
  DEFAULT_URL = 'https://api.fastly.com'.freeze
11
13
 
12
- attr_accessor :http, :api_key, :user, :password, :cookie, :customer
14
+ attr_accessor :api_key, :base_url, :debug, :user, :password, :cookie, :customer
13
15
 
14
16
  def initialize(opts)
15
- @api_key = opts.fetch(:api_key, nil)
16
- @user = opts.fetch(:user, nil)
17
- @password = opts.fetch(:password, nil)
18
- @customer = opts.fetch(:customer, nil)
19
- @oldpurge = opts.fetch(:use_old_purge_method, false)
20
-
21
- base = opts.fetch(:base_url, DEFAULT_URL)
22
- uri = URI.parse(base)
23
-
24
- @http = Net::HTTP.new(uri.host, uri.port, :ENV, nil, nil, nil)
25
-
26
- # handle TLS connections outside of development
27
- @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
28
- @http.use_ssl = uri.scheme.downcase == 'https'
29
-
30
- # debug http interactions if specified
31
- @http.set_debug_output(opts[:debug]) if opts[:debug]
32
-
33
- @http.start
17
+ @api_key = opts.fetch(:api_key, nil)
18
+ @base_url = opts.fetch(:base_url, DEFAULT_URL)
19
+ @customer = opts.fetch(:customer, nil)
20
+ @oldpurge = opts.fetch(:use_old_purge_method, false)
21
+ @password = opts.fetch(:password, nil)
22
+ @user = opts.fetch(:user, nil)
23
+ @debug = opts.fetch(:debug, nil)
24
+ @thread_http_client = if defined?(Concurrent::ThreadLocalVar)
25
+ Concurrent::ThreadLocalVar.new { build_http_client }
26
+ end
34
27
 
35
28
  return self unless fully_authed?
36
29
 
@@ -114,8 +107,29 @@ class Fastly
114
107
  JSON.parse(resp.body)
115
108
  end
116
109
 
110
+ def http
111
+ return @thread_http_client.value if @thread_http_client
112
+ return Thread.current[:fastly_net_http] if Thread.current[:fastly_net_http]
113
+
114
+ Thread.current[:fastly_net_http] = build_http_client
115
+ end
116
+
117
117
  private
118
118
 
119
+ def build_http_client
120
+ uri = URI.parse(base_url)
121
+ net_http = Net::HTTP.new(uri.host, uri.port, :ENV, nil, nil, nil)
122
+
123
+ # handle TLS connections outside of development
124
+ net_http.verify_mode = OpenSSL::SSL::VERIFY_PEER
125
+ net_http.use_ssl = uri.scheme.downcase == 'https'
126
+
127
+ # debug http interactions if specified
128
+ net_http.set_debug_output(debug) if debug
129
+
130
+ net_http
131
+ end
132
+
119
133
  def post_and_put(method, path, params = {})
120
134
  extras = params.delete(:headers) || {}
121
135
  query = make_params(params)
@@ -1,4 +1,4 @@
1
1
  # The current version of the library
2
2
  class Fastly
3
- VERSION = "2.2.0"
3
+ VERSION = "2.3.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastly
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fastly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-11 00:00:00.000000000 Z
11
+ date: 2019-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Client library for the Fastly acceleration system
14
14
  email:
@@ -106,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.5.2.3
109
+ rubygems_version: 3.0.1
111
110
  signing_key:
112
111
  specification_version: 4
113
112
  summary: Client library for the Fastly acceleration system