vertebrae 1.0.0 → 1.0.2

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: 62eabfcd0080454194f02c772758fcac1dee7998c264813b715f729c01f6deec
4
- data.tar.gz: 563e98c3ad61dc9040cc26134d795eb884d535197963d736f7a76e121f66d29f
3
+ metadata.gz: 6553709d307b6343edc5ba9f95d9746bc7011d2b766cfa71f004ac058aa31df3
4
+ data.tar.gz: c3e633375938b93ebe9ea4fd5471f132cefe424ddf8f414bf56b21d6be05d040
5
5
  SHA512:
6
- metadata.gz: 703b18a9b5ffa5b538a43ef6c68caa99d22c34411a75fca19bce78e020183811d3e9f4bb5b1708d365928f8b7fec8402325affea87491807b955ab5f38572355
7
- data.tar.gz: 59266d8c1051b15946274669008e702eafb08896a089a3f08eb6498d35b65d6a5ace24c3a72177d499a91a5fcac3be727b4a7a75d446020913537b2663eea7e4
6
+ metadata.gz: 875b777a7944ac034d03d1222d1adc32c611eff136772a6f22a1d4d60824ced6d57b93e7ab1dd2411cdf231bf1fcebbe2569aae8ea808f49c093c4058f0e0438
7
+ data.tar.gz: 98a03fd19a9a5407c40185c3216bda550d2fd118e67bbb9ee7f16c37080337db3d42a7b494ef18ef15ea1088ced62f01ad8f5c8998c0221318a146cf0d5a87e1
data/.gitignore ADDED
@@ -0,0 +1,26 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+ Gemfile.lock
15
+
16
+ # jeweler generated
17
+ pkg
18
+
19
+ # For MacOS:
20
+ #
21
+ .DS_Store
22
+ .idea
23
+
24
+ # For TextMate
25
+ *.tmproj
26
+ tmtags
@@ -3,8 +3,8 @@
3
3
  require 'faraday'
4
4
  require 'faraday/multipart'
5
5
  require 'faraday/mashify'
6
- require 'response/raise_error'
7
- require 'authorization'
6
+ require 'vertebrae/response/raise_error'
7
+ require 'vertebrae/authorization'
8
8
 
9
9
  module Vertebrae
10
10
  class Connection
@@ -13,6 +13,7 @@ module Vertebrae
13
13
 
14
14
  attr_reader :options
15
15
  attr_accessor :configuration
16
+ attr_accessor :faraday_connection
16
17
 
17
18
  ALLOWED_OPTIONS = [
18
19
  :headers,
@@ -71,7 +72,7 @@ module Vertebrae
71
72
  # Returns a Faraday::Connection object
72
73
  #
73
74
  def connection
74
- Faraday.new(configuration.faraday_options.merge(:builder => stack))
75
+ self.faraday_connection ||= Faraday.new(configuration.faraday_options.merge(:builder => stack))
75
76
  end
76
77
  end
77
78
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vertebrae
4
+ VERSION = '1.0.2'
5
+ end
data/lib/vertebrae.rb CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  require 'active_support/all'
4
4
 
5
- require 'constants'
6
- require 'authorization'
7
- require 'configuration'
8
- require 'connection'
9
- require 'request'
10
- require 'response_error'
11
- require 'api'
12
- require 'base'
13
- require 'model'
14
- require 'version'
5
+ require 'vertebrae/constants'
6
+ require 'vertebrae/authorization'
7
+ require 'vertebrae/configuration'
8
+ require 'vertebrae/connection'
9
+ require 'vertebrae/request'
10
+ require 'vertebrae/response_error'
11
+ require 'vertebrae/api'
12
+ require 'vertebrae/base'
13
+ require 'vertebrae/model'
14
+ require 'vertebrae/version'
15
15
 
16
16
  require 'railties' if defined? Rails
17
17
 
data/vertebrae.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'version'
5
+ require 'vertebrae/version'
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "vertebrae".freeze
@@ -18,40 +18,13 @@ Gem::Specification.new do |s|
18
18
  "LICENSE.txt",
19
19
  "README.md"
20
20
  ]
21
- s.files = [
22
- ".document",
23
- ".github/workflows/ci.yml",
24
- ".rspec",
25
- ".rubocop.yml",
26
- ".ruby-gemset",
27
- ".ruby-version",
28
- "Gemfile",
29
- "LICENSE.txt",
30
- "README.md",
31
- "Rakefile",
32
- "VERSION",
33
- "lib/api.rb",
34
- "lib/authorization.rb",
35
- "lib/base.rb",
36
- "lib/configuration.rb",
37
- "lib/connection.rb",
38
- "lib/constants.rb",
39
- "lib/core_ext/array.rb",
40
- "lib/model.rb",
41
- "lib/railties.rb",
42
- "lib/request.rb",
43
- "lib/response/raise_error.rb",
44
- "lib/response_error.rb",
45
- "lib/vertebrae.rb",
46
- "spec/api_spec.rb",
47
- "spec/configuration_spec.rb",
48
- "spec/dummy/client.rb",
49
- "spec/dummy/dummy.rb",
50
- "spec/logger_spec.rb",
51
- "spec/request_spec.rb",
52
- "spec/spec_helper.rb",
53
- "vertebrae.gemspec"
54
- ]
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+
55
28
  s.homepage = "http://github.com/controlshift/vertebrae".freeze
56
29
  s.licenses = ["MIT".freeze]
57
30
  s.summary = "API Client Infrastructure".freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vertebrae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Woodhull
@@ -161,6 +161,7 @@ extra_rdoc_files:
161
161
  files:
162
162
  - ".document"
163
163
  - ".github/workflows/ci.yml"
164
+ - ".gitignore"
164
165
  - ".rspec"
165
166
  - ".rubocop.yml"
166
167
  - ".ruby-gemset"
@@ -170,26 +171,20 @@ files:
170
171
  - README.md
171
172
  - Rakefile
172
173
  - VERSION
173
- - lib/api.rb
174
- - lib/authorization.rb
175
- - lib/base.rb
176
- - lib/configuration.rb
177
- - lib/connection.rb
178
- - lib/constants.rb
179
174
  - lib/core_ext/array.rb
180
- - lib/model.rb
181
- - lib/railties.rb
182
- - lib/request.rb
183
- - lib/response/raise_error.rb
184
- - lib/response_error.rb
185
175
  - lib/vertebrae.rb
186
- - spec/api_spec.rb
187
- - spec/configuration_spec.rb
188
- - spec/dummy/client.rb
189
- - spec/dummy/dummy.rb
190
- - spec/logger_spec.rb
191
- - spec/request_spec.rb
192
- - spec/spec_helper.rb
176
+ - lib/vertebrae/api.rb
177
+ - lib/vertebrae/authorization.rb
178
+ - lib/vertebrae/base.rb
179
+ - lib/vertebrae/configuration.rb
180
+ - lib/vertebrae/connection.rb
181
+ - lib/vertebrae/constants.rb
182
+ - lib/vertebrae/model.rb
183
+ - lib/vertebrae/railties.rb
184
+ - lib/vertebrae/request.rb
185
+ - lib/vertebrae/response/raise_error.rb
186
+ - lib/vertebrae/response_error.rb
187
+ - lib/vertebrae/version.rb
193
188
  - vertebrae.gemspec
194
189
  homepage: http://github.com/controlshift/vertebrae
195
190
  licenses:
@@ -210,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
205
  - !ruby/object:Gem::Version
211
206
  version: '0'
212
207
  requirements: []
213
- rubygems_version: 3.4.1
208
+ rubygems_version: 3.4.10
214
209
  signing_key:
215
210
  specification_version: 4
216
211
  summary: API Client Infrastructure
data/spec/api_spec.rb DELETED
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Vertebrae::API do
6
- subject { described_class.new(options) }
7
-
8
- it { expect(described_class.included_modules).to include Vertebrae::Request }
9
-
10
- describe 'initialize' do
11
- before(:each) do
12
- allow_any_instance_of(Vertebrae::API).to receive(:default_options).and_return({content_type: 'foo'})
13
- end
14
-
15
- context 'with an empty hash' do
16
- let(:options) { {} }
17
- specify { expect(subject.connection.options).to eq({content_type: 'foo'}) }
18
- end
19
-
20
- context 'with a default content-type' do
21
- let(:options) { {content_type: 'text/csv'} }
22
- specify { expect(subject.connection.options).to eq({content_type: 'text/csv'}) }
23
- end
24
- end
25
-
26
- describe 'dummy' do
27
- describe 'should delegate to the client class' do
28
- specify { expect(Dummy.new).to respond_to(:api) }
29
- specify { expect(Dummy).to respond_to(:api) }
30
- end
31
- end
32
- end
@@ -1,128 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Vertebrae::Configuration do
6
-
7
- subject { Vertebrae::Configuration.new({}) }
8
-
9
- {:scheme => described_class::DEFAULT_SCHEME,
10
- :ssl => described_class::DEFAULT_SSL,
11
- :user_agent => described_class::DEFAULT_USER_AGENT,
12
- :username => described_class::DEFAULT_USERNAME,
13
- :password => described_class::DEFAULT_PASSWORD }.each do | key, value |
14
- its(key) { should == value }
15
- its("default_#{key}") { should == value }
16
- end
17
-
18
- its(:connection_options) { should be_a Hash }
19
- its(:connection_options) { should be_empty }
20
-
21
- describe "override" do
22
- subject{ Vertebrae::Configuration.new({username: 'foo', password: 'bar', scheme: 'http'}) }
23
-
24
- its(:default_scheme) { should == described_class::DEFAULT_SCHEME }
25
- its(:default_username) { should == described_class::DEFAULT_USERNAME }
26
- its(:default_password) { should == described_class::DEFAULT_PASSWORD }
27
-
28
- its(:scheme) { should == 'http'}
29
- its(:username) { should == 'foo'}
30
- its(:password) { should == 'bar'}
31
- end
32
-
33
- describe "setter" do
34
- before(:each) do
35
- subject.username = 'foo'
36
- end
37
- its(:username) { should == 'foo'}
38
- its(:default_username) { should == described_class::DEFAULT_USERNAME }
39
- end
40
-
41
- describe 'endpoint' do
42
- context 'with no port specification' do
43
- subject { Vertebrae::Configuration.new({host: 'test.com', prefix: ''}) }
44
-
45
- specify { expect(subject.host).to eq('test.com') }
46
- specify { expect(subject.endpoint).to eq('https://test.com')}
47
- end
48
-
49
- context 'with port specification' do
50
- subject { Vertebrae::Configuration.new({host: 'test.com', prefix: '', port: 8080}) }
51
-
52
- specify { expect(subject.port).to eq(8080) }
53
- specify { expect(subject.endpoint).to eq('https://test.com:8080')}
54
-
55
- context 'with prefix' do
56
- subject { Vertebrae::Configuration.new({host: 'test.com', prefix: '/api/v1', port: 8080}) }
57
-
58
- specify { expect(subject.prefix).to eq('/api/v1') }
59
- specify { expect(subject.endpoint).to eq('https://test.com:8080/api/v1')}
60
- end
61
- end
62
- end
63
-
64
- describe 'adapter' do
65
- it 'should default to :net_http' do
66
- expect(subject.adapter).to eq(:net_http)
67
- end
68
- end
69
-
70
- describe 'adapter=' do
71
- it 'should allow setting and retrieval' do
72
- subject.adapter = :foo
73
- expect(subject.adapter).to eq(:foo)
74
- end
75
- end
76
-
77
- describe '#faraday_options' do
78
- subject { Vertebrae::Configuration.new(host: 'example.com') }
79
-
80
- it 'should include headers, ssl, and url settings by default' do
81
- opts = subject.faraday_options
82
- expect(opts.keys).to contain_exactly(:headers, :ssl, :url)
83
- expect(opts[:headers]).to eq({'Accept' => 'application/json;q=0.1',
84
- 'Accept-Charset' => 'utf-8',
85
- 'User-Agent' => 'Vertebrae REST Gem',
86
- 'Content-Type' => 'application/json'})
87
- expect(opts[:ssl]).to eq({})
88
- expect(opts[:url]).to eq 'https://example.com/'
89
- end
90
-
91
- context 'with connection_options' do
92
- let(:connection_options) { {ssl: {verify: false},
93
- timeout: 5} }
94
-
95
- subject { Vertebrae::Configuration.new(host: 'example.com', connection_options: connection_options) }
96
-
97
- it 'should override and extend the default options' do
98
- opts = subject.faraday_options
99
- expect(opts.keys).to contain_exactly(:headers, :ssl, :timeout, :url)
100
- expect(opts[:headers]).to eq({'Accept' => 'application/json;q=0.1',
101
- 'Accept-Charset' => 'utf-8',
102
- 'User-Agent' => 'Vertebrae REST Gem',
103
- 'Content-Type' => 'application/json'})
104
- expect(opts[:ssl]).to eq({verify: false})
105
- expect(opts[:url]).to eq 'https://example.com/'
106
- expect(opts[:timeout]).to eq 5
107
- end
108
- end
109
-
110
- context 'with additional_headers' do
111
- let(:additional_headers) { {'special-auth-token' => 'abcde12345'} }
112
-
113
- subject { Vertebrae::Configuration.new(host: 'example.com', additional_headers: additional_headers) }
114
-
115
- it 'should add the additional headers to the other headers' do
116
- opts = subject.faraday_options
117
- expect(opts.keys).to contain_exactly(:headers, :ssl, :url)
118
- expect(opts[:headers]).to eq({'Accept' => 'application/json;q=0.1',
119
- 'Accept-Charset' => 'utf-8',
120
- 'User-Agent' => 'Vertebrae REST Gem',
121
- 'Content-Type' => 'application/json',
122
- 'special-auth-token' => 'abcde12345'})
123
- expect(opts[:ssl]).to eq({})
124
- expect(opts[:url]).to eq 'https://example.com/'
125
- end
126
- end
127
- end
128
- end
data/spec/dummy/client.rb DELETED
@@ -1,7 +0,0 @@
1
- module Dummy
2
- class Client < Vertebrae::API
3
- def api(options={}, &block)
4
- @api ||= Vertebrae::API.new(current_options.merge(options), &block)
5
- end
6
- end
7
- end
data/spec/dummy/dummy.rb DELETED
@@ -1,8 +0,0 @@
1
- module Dummy
2
- extend Vertebrae::Base
3
- class << self
4
- def new(options = {}, &block)
5
- Dummy::Client.new(options, &block)
6
- end
7
- end
8
- end
data/spec/logger_spec.rb DELETED
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'logging' do
6
- it "should have a logger" do
7
- expect(Dummy).to respond_to(:logger)
8
- end
9
-
10
- it "should be able to log debug methods" do
11
- expect(Dummy.logger).to respond_to(:debug)
12
- end
13
-
14
- it "should be settable" do
15
- expect(Dummy).to respond_to(:logger=)
16
- log = double
17
- Dummy.logger = log
18
- expect(Dummy.logger).to eq(log)
19
- end
20
- end
data/spec/request_spec.rb DELETED
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Vertebrae::Request do
6
- let(:vb) { Vertebrae::API.new }
7
- let(:path) { 'actionkit.api/rest/v1/action' }
8
- let(:params) { {} }
9
- let(:options) { {} }
10
-
11
- it "knows how to make get request" do
12
- expect(vb).to receive(:request).with(:get, path, params, options)
13
- vb.get_request path, params, options
14
- end
15
-
16
- it "knows how to make patch request" do
17
- expect(vb).to receive(:request).with(:patch, path, params, options)
18
- vb.patch_request path, params, options
19
- end
20
-
21
- it "knows how to make post request" do
22
- expect(vb).to receive(:request).with(:post, path, params, options)
23
- vb.post_request path, params, options
24
- end
25
-
26
- it "knows how to make put request" do
27
- expect(vb).to receive(:request).with(:put, path, params, options)
28
- vb.put_request path, params, options
29
- end
30
-
31
- it "knows how to make delete request" do
32
- vb.should_receive(:request).with(:delete, path, params, options)
33
- vb.delete_request path, params, options
34
- end
35
-
36
- describe 'it should result in an appropriately configured connection object when it comes time to run transactions' do
37
- before(:each) do
38
- logger = double
39
- logger.stub(:debug).and_return(true)
40
- allow(Vertebrae::Base).to receive(:logger).and_return(logger)
41
- allow_any_instance_of(Vertebrae::API).to receive(:default_options).and_return({host: 'test.com'})
42
- end
43
-
44
- context 'with an empty hash' do
45
- let(:options) { {} }
46
- it 'should make the request to the default host' do
47
- stub_request(:get, 'https://test.com/path')
48
- vb.request(:get, '/path', {}, options)
49
- end
50
- end
51
-
52
- context 'with a different host' do
53
- let(:options) { {host: 'test2.com'} }
54
- it 'should make the request to the default host' do
55
- stub_request(:get, 'https://test2.com/path')
56
- vb.request(:get, '/path', {}, options)
57
- end
58
- end
59
-
60
- context 'with host specified at client initiation time' do
61
- let(:options) { {} }
62
-
63
- let(:vb) { Vertebrae::API.new host: 'test3.com' }
64
-
65
- it 'should make the request to the default host' do
66
- stub_request(:get, 'https://test3.com/path')
67
- vb.request(:get, '/path', {}, options)
68
- end
69
-
70
- context 'with a different host' do
71
- let(:options) { {host: 'test2.com'} }
72
- it 'should make the request to the default host' do
73
- stub_request(:get, 'https://test2.com/path')
74
- vb.request(:get, '/path', {}, options)
75
- end
76
- end
77
- end
78
-
79
- context 'with basic auth' do
80
- let(:options) { {} }
81
- let(:vb) { Vertebrae::API.new username: 'user', password: 'pass' }
82
-
83
- it 'should make requests with basic auth' do
84
- stub_request(:get, 'https://test3.com/path').with(basic_auth: %w[user pass])
85
- vb.request(:get, '/path', {}, {host: 'test3.com'})
86
- end
87
- end
88
- end
89
- end
data/spec/spec_helper.rb DELETED
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- require 'rspec'
6
- require 'vertebrae'
7
- require 'dummy/dummy'
8
- require 'dummy/client'
9
- require 'webmock/rspec'
10
-
11
- require 'rspec/its'
12
-
13
- # Requires supporting files with custom matchers and macros, etc,
14
- # in ./support/ and its subdirectories.
15
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
16
-
17
- RSpec.configure do |config|
18
- config.mock_with :rspec do |mocks|
19
- mocks.syntax = [:should, :expect]
20
- end
21
-
22
- config.expect_with :rspec do |c|
23
- c.syntax = [:should, :expect]
24
- end
25
- end
26
-
27
-
28
- def reset_authentication_for(object)
29
- %w[username password].each do |item|
30
- Vertebrae::Base.send("#{item}=", nil)
31
- object.send("#{item}=", nil)
32
- end
33
- end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes