unobtainium-faraday 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa9b05752123df74861b071237f39f990d867e1e
4
+ data.tar.gz: a10c676af0d8c4b83f7c44ba2b3a81ec4cf75c87
5
+ SHA512:
6
+ metadata.gz: d9b325d1a72f8455b9c28667b372f9077f045953a930e804663041b23c6a0d7ea94d11622c57dae46bf5fa4b6c707cf065332733c1bc48b8167a62cec542e051
7
+ data.tar.gz: 0643a2263e3eb391dfc68a81838cfae8f6e01ce34d885ebb7402241df37a82d220960071c8aaedaea40b3481cccf095e106db8a678bdfe2754ad28f601f9ed40
data/.codeclimate.yml ADDED
@@ -0,0 +1,28 @@
1
+ ---
2
+ engines:
3
+ bundler-audit:
4
+ enabled: true
5
+ duplication:
6
+ enabled: true
7
+ config:
8
+ languages:
9
+ - ruby
10
+ - javascript
11
+ - python
12
+ - php
13
+ fixme:
14
+ enabled: true
15
+ rubocop:
16
+ enabled: true
17
+ ratings:
18
+ paths:
19
+ - Gemfile.lock
20
+ - "**.inc"
21
+ - "**.js"
22
+ - "**.jsx"
23
+ - "**.module"
24
+ - "**.php"
25
+ - "**.py"
26
+ - "**.rb"
27
+ exclude_paths:
28
+ - spec/
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
38
+ # Editor files
39
+ .*.sw*
data/.rubocop.yml ADDED
@@ -0,0 +1,69 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.2
3
+
4
+ # Metrics
5
+
6
+ Metrics/LineLength:
7
+ Max: 83
8
+ Details: >-
9
+ Line length of 80 is ideal for readability and compatibility; we'll accept
10
+ an extra 3 for minor edge cases.
11
+
12
+ Metrics/MethodLength:
13
+ Max: 35
14
+
15
+ Metrics/BlockNesting:
16
+ Max: 5
17
+
18
+ Metrics/AbcSize:
19
+ Max: 50
20
+
21
+ Metrics/PerceivedComplexity:
22
+ Max: 15
23
+
24
+ Metrics/CyclomaticComplexity:
25
+ Max: 15
26
+
27
+ Metrics/ClassLength:
28
+ Max: 300
29
+
30
+ # Style
31
+
32
+ Style/StringLiterals:
33
+ Enabled: false
34
+
35
+ Style/ConditionalAssignment:
36
+ Enabled: false
37
+
38
+ Style/EmptyLinesAroundModuleBody:
39
+ Enabled: false
40
+
41
+ Style/AndOr:
42
+ Enabled: false
43
+
44
+ Style/Not:
45
+ Enabled: false
46
+
47
+ Style/NegatedIf:
48
+ Enabled: false
49
+
50
+ Style/RedundantReturn:
51
+ Enabled: false
52
+
53
+ Style/IfUnlessModifier:
54
+ Enabled: false
55
+
56
+ Style/TrailingCommaInLiteral:
57
+ Enabled: false
58
+
59
+ Style/FirstParameterIndentation:
60
+ Enabled: false
61
+
62
+ Style/TrailingUnderscoreVariable:
63
+ Enabled: false
64
+
65
+ Style/NumericLiterals:
66
+ Enabled: false
67
+
68
+ Style/FileName:
69
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ addons:
7
+ code_climate:
8
+ repo_token: 443b06454b58c9de3948457314b2ba3e6a0671ea565e115733caea9a7e89b0d3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in unobtainium.gemspec
4
+ gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ unobtainium-faraday (0.1.0)
5
+ unobtainium (~> 0.3, >= 0.3.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.2.0)
11
+ codeclimate-test-reporter (0.5.0)
12
+ simplecov (>= 0.7.1, < 1.0.0)
13
+ diff-lcs (1.2.5)
14
+ docile (1.1.5)
15
+ faraday (0.9.2)
16
+ multipart-post (>= 1.2, < 3)
17
+ faraday_json (0.1.2)
18
+ faraday (>= 0.7.4, < 0.10)
19
+ faraday_middleware (0.10.0)
20
+ faraday (>= 0.7.4, < 0.10)
21
+ json (1.8.3)
22
+ multi_xml (0.5.5)
23
+ multipart-post (2.0.0)
24
+ parser (2.3.1.0)
25
+ ast (~> 2.2)
26
+ powerpack (0.1.1)
27
+ rainbow (2.1.0)
28
+ rake (11.1.2)
29
+ rspec (3.4.0)
30
+ rspec-core (~> 3.4.0)
31
+ rspec-expectations (~> 3.4.0)
32
+ rspec-mocks (~> 3.4.0)
33
+ rspec-core (3.4.4)
34
+ rspec-support (~> 3.4.0)
35
+ rspec-expectations (3.4.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.4.0)
38
+ rspec-mocks (3.4.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.4.0)
41
+ rspec-support (3.4.1)
42
+ rubocop (0.39.0)
43
+ parser (>= 2.3.0.7, < 3.0)
44
+ powerpack (~> 0.1)
45
+ rainbow (>= 1.99.1, < 3.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (~> 1.0, >= 1.0.1)
48
+ ruby-progressbar (1.8.0)
49
+ simplecov (0.11.2)
50
+ docile (~> 1.1.0)
51
+ json (~> 1.8)
52
+ simplecov-html (~> 0.10.0)
53
+ simplecov-html (0.10.0)
54
+ sys-proctable (1.0.0)
55
+ unicode-display_width (1.0.3)
56
+ unobtainium (0.3.5)
57
+ sys-proctable (~> 1.0)
58
+ yard (0.8.7.6)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ bundler (~> 1.11)
65
+ codeclimate-test-reporter
66
+ faraday
67
+ faraday_json
68
+ faraday_middleware
69
+ multi_xml
70
+ rake (~> 11.1)
71
+ rspec (~> 3.4)
72
+ rubocop (~> 0.39)
73
+ simplecov (~> 0.11)
74
+ unobtainium-faraday!
75
+ yard (~> 0.8)
76
+
77
+ BUNDLED WITH
78
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ Copyright (c) Jens Finkhaeuser (http://finkhaeuser.de/) and other
2
+ unobtainium-faraday contributors. All rights not covered below are reserved.
3
+
4
+ The MIT +no-false-attribs License (MITNFA)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to
8
+ deal in the Software without restriction, including without limitation the
9
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ sell copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ Distributions of all or part of the Software intended to be used by the
17
+ recipients as they would use the unmodified Software, containing modifications
18
+ that substantially alter, remove, or disable functionality of the Software,
19
+ outside of the documented configuration mechanisms provided by the Software,
20
+ shall be modified such that the Original Author's bug reporting email addresses
21
+ and urls are either replaced with the contact information of the parties
22
+ responsible for the changes, or removed entirely.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30
+ IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # unobtainium-faraday
2
+
3
+ This gem provides a driver implementation for [unobtainium](https://github.com/jfinkhaeuser/unobtainium)
4
+ based on [faraday](https://github.com/lostisland/faraday).
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/unobtainium-faraday.svg)](https://badge.fury.io/rb/unobtainium-faraday)
7
+ [![Build status](https://travis-ci.org/jfinkhaeuser/unobtainium-faraday.svg?branch=master)](https://travis-ci.org/jfinkhaeuser/unobtainium-faraday)
8
+ [![Code Climate](https://codeclimate.com/github/jfinkhaeuser/unobtainium-faraday/badges/gpa.svg)](https://codeclimate.com/github/jfinkhaeuser/unobtainium-faraday)
9
+ [![Test Coverage](https://codeclimate.com/github/jfinkhaeuser/unobtainium-faraday/badges/coverage.svg)](https://codeclimate.com/github/jfinkhaeuser/unobtainium-faraday/coverage)
10
+
11
+ To use it, require it after requiring unobtainium, then create the appropriate driver:
12
+
13
+ ```ruby
14
+ require 'unobtainium'
15
+ require 'unobtainium-faraday'
16
+
17
+ include Unobtainium::World
18
+
19
+ drv = driver(:faraday)
20
+ ```
21
+
22
+ The main purpose of this gem is to make API testing a little easier. To that
23
+ end, the driver (which is a faraday connection object) is initialized with some
24
+ middleware, in particular [faraday_json](https://github.com/spriteCloud/faraday_json)
25
+ to fix some encoding issues in the default middleware.
26
+
27
+ If you're coming from faraday, initializing the driver/connection is going to
28
+ feel a little different. Instead of the block-initialization favoured by faraday,
29
+ you pass an options hash:
30
+
31
+ ```ruby
32
+ drv = driver(:faraday,
33
+ uri: 'http://finkhaeuser.de',
34
+ connection: {
35
+ request: :json,
36
+ response: [:logger, [:json, content_type: /\bjson$/ ]]
37
+ })
38
+ ```
39
+
40
+ Afterwards, using the driver is identical to faraday usage:
41
+
42
+ ```ruby
43
+ res = drv.get '/'
44
+ puts res.body
45
+ ```
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # Rubocop
2
+ require 'rubocop/rake_task'
3
+ RuboCop::RakeTask.new(:rubocop)
4
+
5
+ # Rspec
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:rspec)
8
+
9
+ # Documentation
10
+ require 'yard'
11
+ YARD::Rake::YardocTask.new do |t|
12
+ t.files = ['lib/**/*.rb']
13
+ t.options = ['-m', 'markdown']
14
+ t.stats_options = ['--list-undoc']
15
+ end
16
+
17
+ # Combined test task
18
+ desc "Test all the things!"
19
+ task :test do
20
+ Rake::Task[:rubocop].invoke
21
+ Rake::Task[:rspec].invoke
22
+ end
23
+
24
+ # Default is the test task
25
+ task default: :test
@@ -0,0 +1,10 @@
1
+ # coding: utf-8
2
+ #
3
+ # unobtainium-faraday
4
+ # https://github.com/jfinkhaeuser/unobtainium-faraday
5
+ #
6
+ # Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-faraday contributors.
7
+ # All rights reserved.
8
+ #
9
+
10
+ require 'unobtainium-faraday/driver'
@@ -0,0 +1,204 @@
1
+ # coding: utf-8
2
+ #
3
+ # unobtainium-faraday
4
+ # https://github.com/jfinkhaeuser/unobtainium-faraday
5
+ #
6
+ # Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-faraday contributors.
7
+ # All rights reserved.
8
+ #
9
+
10
+ require 'unobtainium'
11
+ require 'unobtainium/support/util'
12
+ require 'unobtainium/pathed_hash'
13
+
14
+ module Unobtainium
15
+ ##
16
+ # Faraday namespace
17
+ module Faraday
18
+
19
+ ##
20
+ # Driver implementation using faraday (and open-uri).
21
+ class Driver
22
+ # Recognized labels for matching the driver
23
+ LABELS = {
24
+ faraday: [:api,],
25
+ }.freeze
26
+
27
+ # @private
28
+ # Default options to pass to Faraday
29
+ DEFAULT_OPTIONS = PathedHash.new(
30
+ connection: {
31
+ request: [:multipart, :json],
32
+ response: [
33
+ [:xml, content_type: /\bxml$/],
34
+ [:json, content_type: /\bjson$/],
35
+ ],
36
+ }
37
+ ).freeze
38
+
39
+ class << self
40
+ include ::Unobtainium::Support::Utility
41
+
42
+ ##
43
+ # Return true if the given label matches this driver implementation,
44
+ # false otherwise.
45
+ def matches?(label)
46
+ return nil != normalize_label(label)
47
+ end
48
+
49
+ ##
50
+ # Ensure that the driver's preconditions are fulfilled.
51
+ def ensure_preconditions(_, _)
52
+ require 'faraday'
53
+ require 'faraday_middleware'
54
+ require 'faraday_json'
55
+ rescue LoadError => err
56
+ raise LoadError, "#{err.message}: you need to add "\
57
+ "'faraday', 'faraday_middleware' and 'faraday_json' to your "\
58
+ "Gemfile to use this driver!",
59
+ err.backtrace
60
+ end
61
+
62
+ ##
63
+ # Mostly serves to populate options with default options.
64
+ def resolve_options(label, options)
65
+ # Start with sensible defaults
66
+ opts = {}
67
+ if not options.nil?
68
+ opts = options.dup
69
+ end
70
+ opts = DEFAULT_OPTIONS.recursive_merge(opts)
71
+
72
+ # For SSL options, if 'client_key' and 'client_cert' are
73
+ # 1) Strings that name files, then the file contents are substituted, and
74
+ # 2) Strings that are certificates/private keys, then they are parsed
75
+ resolve_ssl_option(opts, 'ssl.client_cert',
76
+ /BEGIN CERTIFICATE/,
77
+ ::OpenSSL::X509::Certificate)
78
+ resolve_ssl_option(opts, 'ssl.client_key',
79
+ /BEGIN (EC|DSA|RSA| *) ?PRIVATE KEY/,
80
+ ::OpenSSL::PKey, 1)
81
+
82
+ return normalize_label(label), opts
83
+ end
84
+
85
+ ##
86
+ # Create and return a driver instance
87
+ def create(_, options)
88
+ driver = ::Unobtainium::Faraday::Driver.new(options)
89
+ return driver
90
+ end
91
+
92
+ ##
93
+ # Helper function for resolve_options for resolving SSL options
94
+ def resolve_ssl_option(opts, path, pattern, klass, match_index = 0)
95
+ # Ignore if the path doesn't exist
96
+ if opts.nil? or opts[path].nil?
97
+ return
98
+ end
99
+
100
+ # Skip if the path isn't a String. We assume it's already been
101
+ # processed. Either way, faraday can take care of it.
102
+ val = opts[path]
103
+ if not val.is_a? String
104
+ return
105
+ end
106
+
107
+ # If the string represents a file name, read the file! Any errors with
108
+ # that should go through to the caller.
109
+ if File.file?(val)
110
+ val = File.read(val)
111
+ end
112
+
113
+ # If the value doesn't match the given pattern, that seems like an
114
+ # error.
115
+ match = val.match(pattern)
116
+ if not match
117
+ raise ArgumentError, "Option '#{path}' does not appear to be valid, "\
118
+ "as it does not match #{pattern}."
119
+ end
120
+
121
+ # Finally, we can pass the value on to OpenSSL/the klass. Make that
122
+ # dependent on what class klass actually is.
123
+ case klass
124
+ when Class
125
+ val = klass.new(val)
126
+ when Module
127
+ name = match[match_index]
128
+ if name.nil? or name.empty?
129
+ name = 'RSA'
130
+ end
131
+ name = '::' + klass.name + '::' + name
132
+ val = Object.const_get(name).new(val)
133
+ end
134
+
135
+ # Overwrite the options!
136
+ opts[path] = val
137
+ end
138
+ end # class << self
139
+
140
+ ##
141
+ # Map any missing method to nokogiri
142
+ def respond_to?(meth)
143
+ if not @conn.nil? and @conn.respond_to?(meth)
144
+ return true
145
+ end
146
+ return super
147
+ end
148
+
149
+ ##
150
+ # Map any missing method to nokogiri
151
+ def method_missing(meth, *args, &block)
152
+ if not @conn.nil? and @conn.respond_to?(meth)
153
+ return @conn.send(meth.to_s, *args, &block)
154
+ end
155
+ return super
156
+ end
157
+
158
+ attr_accessor :conn
159
+
160
+ private
161
+
162
+ ##
163
+ # Private initialize to force use of Driver#create.
164
+ def initialize(opts)
165
+ @options = opts.dup
166
+
167
+ # Extract URI, if it exists. This will be passed as a parameter to
168
+ # faraday.
169
+ uri = @options.fetch(:uri, nil)
170
+ @options.delete(:uri)
171
+
172
+ # Extract connection configuration
173
+ connection = @options.fetch(:connection, {})
174
+ @options.delete(:connection)
175
+
176
+ # Supplement connection configuration with the default adapter, if
177
+ # necessary.
178
+ if connection[:adapter].nil?
179
+ connection[:adapter] = ::Faraday.default_adapter
180
+ end
181
+
182
+ # Create connection object
183
+ @conn = ::Faraday.new(uri, @options) do |faraday|
184
+ # Pass adapter configurations to faraday
185
+ connection.each do |type, params|
186
+ p = params
187
+ if not params.is_a? Array
188
+ p = [params]
189
+ end
190
+
191
+ p.each do |args|
192
+ faraday.send(type, *args)
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end # class Driver
198
+
199
+ end # module Faraday
200
+ end # module Unobtainium
201
+
202
+ ::Unobtainium::Driver.register_implementation(
203
+ ::Unobtainium::Faraday::Driver,
204
+ __FILE__)
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+ #
3
+ # unobtainium-faraday
4
+ # https://github.com/jfinkhaeuser/unobtainium-faraday
5
+ #
6
+ # Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-faraday contributors.
7
+ # All rights reserved.
8
+ #
9
+ module Unobtainium
10
+ module Faraday
11
+ # The current release version
12
+ VERSION = "0.1.0".freeze
13
+ end # module Faraday
14
+ end # module Unobtainium
@@ -0,0 +1,23 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDxzCCAq+gAwIBAgIJALQLpUhlD21wMA0GCSqGSIb3DQEBCwUAMHoxCzAJBgNV
3
+ BAYTAkRFMRMwEQYDVQQIDApTb21lLVN0YXRlMR8wHQYDVQQKDBZmaW5raGFldXNl
4
+ ciBjb25zdWx0aW5nMREwDwYDVQQDDAh5b3Ugd2lzaDEiMCAGCSqGSIb3DQEJARYT
5
+ amVuc0BmaW5raGFldXNlci5kZTAeFw0xNjA0MjcyMDIyNDhaFw0xNzA0MjcyMDIy
6
+ NDhaMHoxCzAJBgNVBAYTAkRFMRMwEQYDVQQIDApTb21lLVN0YXRlMR8wHQYDVQQK
7
+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gDHEPPKjcIKudVEApYuio5HV27EO+A3+5d3/wP9z9DXtD+xZsbwbIoiVEEee/0W6
18
+ +gZ/2fKaqHdv0NpM1OeB+Z11yTX2CtNnRr1XuuBhC62Dk7dveeD5GsfiU8LoATS1
19
+ zW28CrtaGnUCgYBySLUThbhupCpNv5dn0nGveplgRa/XvXF4biXK0upLFtB60DRg
20
+ 8e3zyD2DEaZLaKPKXsFlCW6KAuYTGfr25KB0CFIKTawdB6tDily2MGX/WF58+pVi
21
+ 97vjD1otzUdrk9FLuAB9zdyGlGS43DaLMkSgYAsHm5eavLGk1ZhNMuU6oQKBgHOt
22
+ jLqvdZB9EHWgvU0QlS+aSh1gNDzC2ZixRDIdirbYM6x+JV6HG2dcpQwg1E8gmtLu
23
+ /3XUgoqEwqDRdz45WN0wLprTVwkQEDhyWz6xN/TLu0pDcm9vRC2NbLBRySAsCNQg
24
+ 5MEan8dvEaG26evEA9V8N5np9k631cglxXujfI79AoGAReVnML+WnKMa0cay2Q0R
25
+ PQHo/imm0kwx7aFZiJSB76MNevl0cHKNwmogIl36LmSuAzl5IV8EMaDb22CH9UDM
26
+ YdzeANsG316XJD0eWRa9rM9zhVMprOy8816aPIfKccVmc29BdQOXcMH7a5yGLWIU
27
+ f5OnvFvN9K+jIB+fsEVois8=
28
+ -----END PRIVATE KEY-----
@@ -0,0 +1,125 @@
1
+ # coding: utf-8
2
+ #
3
+ # unobtainium-faraday
4
+ # https://github.com/jfinkhaeuser/unobtainium-faraday
5
+ #
6
+ # Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-faraday contributors.
7
+ # All rights reserved.
8
+ #
9
+ require 'spec_helper'
10
+ require 'json'
11
+
12
+ describe 'Unobtainium::Faraday::Driver' do
13
+ it "passes unobtainium's interface checks" do
14
+ expect do
15
+ require 'unobtainium-faraday'
16
+ end.to_not raise_error(LoadError)
17
+ end
18
+
19
+ it "can be created" do
20
+ expect do
21
+ ::Unobtainium::Driver.create(:faraday)
22
+ end.to_not raise_error
23
+
24
+ drv = ::Unobtainium::Driver.create(:faraday)
25
+ expect(drv).to_not be_nil
26
+ end
27
+
28
+ it "can be created from an alias" do
29
+ expect do
30
+ ::Unobtainium::Driver.create(:api)
31
+ end.to_not raise_error
32
+
33
+ drv = ::Unobtainium::Driver.create(:api)
34
+ expect(drv).to_not be_nil
35
+ end
36
+
37
+ it "can be created with a URI" do
38
+ endpoint = 'http://apps.testinsane.com/rte'
39
+ drv = ::Unobtainium::Driver.create(:api, uri: endpoint)
40
+ expect(drv.options[:uri]).to eql endpoint
41
+ end
42
+
43
+ it "can be created with adapter parameters" do
44
+ drv = ::Unobtainium::Driver.create(:api, connection: { response: :logger })
45
+ expect(drv.options[:connection][:response]).to eql :logger
46
+ end
47
+
48
+ it "can perform GET requests without endpoint" do
49
+ drv = ::Unobtainium::Driver.create(:api)
50
+ res = drv.get 'http://apps.testinsane.com/rte/status/200'
51
+ expect(res.status).to eql 200
52
+ end
53
+
54
+ it "can perform GET requests with endpoint" do
55
+ endpoint = 'http://apps.testinsane.com/rte'
56
+ drv = ::Unobtainium::Driver.create(:api, uri: endpoint)
57
+ res = drv.get 'status/200'
58
+ expect(res.status).to eql 200
59
+ end
60
+
61
+ it "can perform POST requests without endpoint" do
62
+ drv = ::Unobtainium::Driver.create(:api)
63
+ res = drv.post 'http://apps.testinsane.com/rte/status/200' do |req|
64
+ req.headers['content-type'] = 'application/json; charset=utf-8'
65
+ req.body = JSON.dump(foo: 42)
66
+ end
67
+ expect(res.status).to eql 200
68
+ expect(res.body['foo']).to eql 42
69
+ end
70
+
71
+ it "can perform POST requests with endpoint" do
72
+ endpoint = 'http://apps.testinsane.com/rte'
73
+ drv = ::Unobtainium::Driver.create(:api, uri: endpoint)
74
+ res = drv.post 'status/200' do |req|
75
+ req.headers['content-type'] = 'application/json; charset=utf-8'
76
+ req.body = JSON.dump(foo: 42)
77
+ end
78
+ expect(res.status).to eql 200
79
+ expect(res.body['foo']).to eql 42
80
+ end
81
+
82
+ describe 'SSL/TLS' do
83
+ it 'fails on bad configuration values (bad string)' do
84
+ opts = {
85
+ ssl: {
86
+ client_cert: 'foo',
87
+ }
88
+ }
89
+
90
+ expect do
91
+ ::Unobtainium::Driver.create(:api, opts)
92
+ end.to raise_error(ArgumentError)
93
+ end
94
+
95
+ it 'fails on bad configuration values (bad type)' do
96
+ opts = {
97
+ ssl: {
98
+ client_cert: 42,
99
+ }
100
+ }
101
+
102
+ drv = ::Unobtainium::Driver.create(:api, opts)
103
+ expect do
104
+ drv.get 'https://apps.testinsane.com/rte/status/200'
105
+ end.to raise_error(TypeError)
106
+ end
107
+
108
+ it "can parse & use file SSL cert information from a file" do
109
+ # Also tests strings and pre-created objects due to the implementation of
110
+ # the driver.
111
+ opts = {
112
+ ssl: {
113
+ client_cert: 'spec/data/test.crt',
114
+ client_key: 'spec/data/test.key',
115
+ }
116
+ }
117
+ drv = ::Unobtainium::Driver.create(:api, opts)
118
+
119
+ # We expect the connection to fail due to the bad client certificate
120
+ expect do
121
+ drv.get 'https://apps.testinsane.com/rte/status/200'
122
+ end.to raise_error(::Faraday::ConnectionFailed)
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,11 @@
1
+ # Only start CodeClimate from travis
2
+ if ENV['CODECLIMATE_REPO_TOKEN']
3
+ require 'codeclimate-test-reporter'
4
+ CodeClimate::TestReporter.start
5
+ end
6
+
7
+ # Always start SimpleCov
8
+ require 'simplecov'
9
+ SimpleCov.start do
10
+ # add_filter 'unobtainium/drivers'
11
+ end
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ #
3
+ # unobtainium-faraday
4
+ # https://github.com/jfinkhaeuser/unobtainium-faraday
5
+ #
6
+ # Copyright (c) 2016 Jens Finkhaeuser and other unobtainium-faraday contributors.
7
+ # All rights reserved.
8
+ #
9
+
10
+ lib = File.expand_path('../lib', __FILE__)
11
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
12
+ require 'unobtainium-faraday/version'
13
+
14
+ # rubocop:disable Style/UnneededPercentQ, Style/ExtraSpacing
15
+ # rubocop:disable Style/SpaceAroundOperators
16
+ Gem::Specification.new do |spec|
17
+ spec.name = "unobtainium-faraday"
18
+ spec.version = Unobtainium::Faraday::VERSION
19
+ spec.authors = ["Jens Finkhaeuser"]
20
+ spec.email = ["jens@finkhaeuser.de"]
21
+ spec.description = %q(
22
+ The unobtainium-faraday gem is a faraday-based driver implementation for
23
+ unobtainium.
24
+
25
+ Unlike built-in driver implementations, it does not provide a Selenium-like
26
+ API, but rather one mostly identical to plain faraday.
27
+ )
28
+ spec.summary = %q(
29
+ The unobtainium-faraday gem is a faraday-based driver implementation for
30
+ unobtainium.
31
+ )
32
+ spec.homepage = "https://github.com/jfinkhaeuser/unobtainium-faraday"
33
+ spec.license = "MITNFA"
34
+
35
+ spec.files = `git ls-files -z`.split("\x0")
36
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
37
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
38
+ spec.require_paths = ["lib"]
39
+
40
+ spec.required_ruby_version = '>= 2.0'
41
+
42
+ spec.add_development_dependency "bundler", "~> 1.11"
43
+ spec.add_development_dependency "rubocop", "~> 0.39"
44
+ spec.add_development_dependency "rake", "~> 11.1"
45
+ spec.add_development_dependency "rspec", "~> 3.4"
46
+ spec.add_development_dependency "simplecov", "~> 0.11"
47
+ spec.add_development_dependency "yard", "~> 0.8"
48
+ spec.add_development_dependency "faraday"
49
+ spec.add_development_dependency "multi_xml"
50
+ spec.add_development_dependency "faraday_middleware"
51
+ spec.add_development_dependency "faraday_json"
52
+
53
+ spec.add_dependency "unobtainium", "~> 0.3", ">= 0.3.5"
54
+ end
55
+ # rubocop:enable Style/SpaceAroundOperators
56
+ # rubocop:enable Style/UnneededPercentQ, Style/ExtraSpacing
metadata ADDED
@@ -0,0 +1,230 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unobtainium-faraday
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jens Finkhaeuser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.39'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.39'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: multi_xml
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: faraday_middleware
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: faraday_json
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: unobtainium
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.3'
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 0.3.5
163
+ type: :runtime
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: '0.3'
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: 0.3.5
173
+ description: "\n The unobtainium-faraday gem is a faraday-based driver implementation
174
+ for\n unobtainium.\n\n Unlike built-in driver implementations, it does not
175
+ provide a Selenium-like\n API, but rather one mostly identical to plain faraday.\n
176
+ \ "
177
+ email:
178
+ - jens@finkhaeuser.de
179
+ executables: []
180
+ extensions: []
181
+ extra_rdoc_files: []
182
+ files:
183
+ - ".codeclimate.yml"
184
+ - ".gitignore"
185
+ - ".rubocop.yml"
186
+ - ".travis.yml"
187
+ - Gemfile
188
+ - Gemfile.lock
189
+ - LICENSE
190
+ - README.md
191
+ - Rakefile
192
+ - lib/unobtainium-faraday.rb
193
+ - lib/unobtainium-faraday/driver.rb
194
+ - lib/unobtainium-faraday/version.rb
195
+ - spec/data/test.crt
196
+ - spec/data/test.key
197
+ - spec/driver_spec.rb
198
+ - spec/spec_helper.rb
199
+ - unobtainium-faraday.gemspec
200
+ homepage: https://github.com/jfinkhaeuser/unobtainium-faraday
201
+ licenses:
202
+ - MITNFA
203
+ metadata: {}
204
+ post_install_message:
205
+ rdoc_options: []
206
+ require_paths:
207
+ - lib
208
+ required_ruby_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '2.0'
213
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ requirements: []
219
+ rubyforge_project:
220
+ rubygems_version: 2.4.5.1
221
+ signing_key:
222
+ specification_version: 4
223
+ summary: The unobtainium-faraday gem is a faraday-based driver implementation for
224
+ unobtainium.
225
+ test_files:
226
+ - spec/data/test.crt
227
+ - spec/data/test.key
228
+ - spec/driver_spec.rb
229
+ - spec/spec_helper.rb
230
+ has_rdoc: