conduit 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +0 -1
- data/lib/conduit.rb +14 -19
- data/lib/conduit/cli.rb +2 -2
- data/lib/conduit/configuration.rb +2 -2
- data/lib/conduit/core/action.rb +10 -13
- data/lib/conduit/core/connection.rb +4 -8
- data/lib/conduit/core/decorator.rb +2 -2
- data/lib/conduit/core/driver.rb +5 -7
- data/lib/conduit/core/parser.rb +6 -8
- data/lib/conduit/core/render.rb +3 -5
- data/lib/conduit/core/request_mocker.rb +5 -5
- data/lib/conduit/error.rb +1 -1
- data/lib/conduit/storage.rb +2 -4
- data/lib/conduit/storage/aws.rb +1 -4
- data/lib/conduit/storage/file.rb +3 -7
- data/lib/conduit/util.rb +3 -5
- data/lib/conduit/version.rb +1 -1
- data/spec/classes/core/action_spec.rb +29 -31
- data/spec/classes/core/driver_spec.rb +12 -15
- data/spec/classes/core/parser_spec.rb +17 -19
- data/spec/classes/core/request_mocker_spec.rb +17 -18
- data/spec/classes/util_spec.rb +6 -6
- data/spec/spec_helper.rb +8 -8
- data/spec/support/helper.rb +0 -2
- data/spec/support/my_driver/actions/foo.rb +1 -2
- data/spec/support/my_driver/driver.rb +0 -1
- data/spec/support/my_driver/parsers/foo.rb +7 -9
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db869d12c0bfe0b84b990b04a554c601a4e2730a
|
4
|
+
data.tar.gz: 0fc937f569573df1b4ea36080d4d37458546e9d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba53aa6aaee8504bfb0152e277dc6d11679182eaab78885725a30249123c0d0d8e063273811a6900524032f33aea1d4c4b21023531badfc04113517f3b1f36b1
|
7
|
+
data.tar.gz: 5ea5bfe00dd30d2a7106b2356c1d945ae16452288e4dec810cbed34f1ee17c73ce0bfe8c81ba7420d1a0d59a41eaa874d921aa948c526ea85fdf6e1e5994df2f
|
data/Rakefile
CHANGED
data/lib/conduit.rb
CHANGED
@@ -1,37 +1,34 @@
|
|
1
1
|
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
2
|
|
3
|
-
require
|
3
|
+
require "conduit/configuration"
|
4
4
|
|
5
5
|
module Conduit
|
6
|
-
|
7
6
|
# Autoload the Conduit base classes
|
8
7
|
# NOTE: Autoloading should be
|
9
8
|
# concurrency-safe
|
10
9
|
#
|
11
|
-
autoload :Storage,
|
12
|
-
autoload :Util,
|
13
|
-
autoload :ApiResponse,
|
14
|
-
autoload :ConnectionError,
|
15
|
-
autoload :TimeOut,
|
16
|
-
autoload :Error,
|
10
|
+
autoload :Storage, "conduit/storage"
|
11
|
+
autoload :Util, "conduit/util"
|
12
|
+
autoload :ApiResponse, "conduit/api_response"
|
13
|
+
autoload :ConnectionError, "conduit/connection_error"
|
14
|
+
autoload :TimeOut, "conduit/time_out"
|
15
|
+
autoload :Error, "conduit/error"
|
17
16
|
|
18
17
|
module Core
|
19
|
-
|
20
18
|
# Autoload the Conduit::Core base classes
|
21
19
|
# NOTE: Autoloading should be
|
22
20
|
# concurrency-safe
|
23
21
|
#
|
24
|
-
autoload :Connection,
|
25
|
-
autoload :Render,
|
26
|
-
autoload :Decorator,
|
27
|
-
autoload :RequestMocker,
|
28
|
-
autoload :Action,
|
29
|
-
autoload :Parser,
|
30
|
-
autoload :Driver,
|
22
|
+
autoload :Connection, "conduit/core/connection"
|
23
|
+
autoload :Render, "conduit/core/render"
|
24
|
+
autoload :Decorator, "conduit/core/decorator"
|
25
|
+
autoload :RequestMocker, "conduit/core/request_mocker"
|
26
|
+
autoload :Action, "conduit/core/action"
|
27
|
+
autoload :Parser, "conduit/core/parser"
|
28
|
+
autoload :Driver, "conduit/core/driver"
|
31
29
|
end
|
32
30
|
|
33
31
|
module Driver
|
34
|
-
|
35
32
|
class << self
|
36
33
|
# Store a list of available drivers
|
37
34
|
#
|
@@ -56,8 +53,6 @@ module Conduit
|
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
59
|
-
|
60
56
|
end
|
61
57
|
end
|
62
|
-
|
63
58
|
end
|
data/lib/conduit/cli.rb
CHANGED
@@ -16,7 +16,7 @@ module Conduit
|
|
16
16
|
It will add the base `action`, `decorator`, `parser` and `request_mocker`
|
17
17
|
files along with generators and other basic files.
|
18
18
|
LONGDESC
|
19
|
-
def generate_driver
|
19
|
+
def generate_driver(driver_name)
|
20
20
|
@driver_name = driver_name
|
21
21
|
@dasherized_name = ActiveSupport::Inflector.dasherize driver_name
|
22
22
|
@classified_name = ActiveSupport::Inflector.classify driver_name
|
@@ -62,7 +62,7 @@ module Conduit
|
|
62
62
|
|
63
63
|
Bundler.with_clean_env do
|
64
64
|
inside(@base_path) do
|
65
|
-
full_command = %
|
65
|
+
full_command = %("#{Gem.ruby}" "#{_bundle_command}" install)
|
66
66
|
run(full_command)
|
67
67
|
end
|
68
68
|
end
|
@@ -12,7 +12,7 @@ module Conduit
|
|
12
12
|
@configuration ||= Configuration.new
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.configure
|
15
|
+
def self.configure
|
16
16
|
yield configuration
|
17
17
|
end
|
18
18
|
|
@@ -20,7 +20,7 @@ module Conduit
|
|
20
20
|
attr_accessor :storage_config, :driver_paths
|
21
21
|
|
22
22
|
def storage
|
23
|
-
path = File.join(__dir__,
|
23
|
+
path = File.join(__dir__, "../", "tmp", "conduit")
|
24
24
|
@storage_config ||= { provider: :file, file_path: path }
|
25
25
|
end
|
26
26
|
|
data/lib/conduit/core/action.rb
CHANGED
@@ -12,17 +12,16 @@
|
|
12
12
|
# => action.perform
|
13
13
|
#
|
14
14
|
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
15
|
+
require "active_support"
|
16
|
+
require "active_support/inflector"
|
17
|
+
require "active_support/core_ext/object"
|
18
|
+
require "forwardable"
|
19
|
+
require "ostruct"
|
20
|
+
require "set"
|
21
21
|
|
22
22
|
module Conduit
|
23
23
|
module Core
|
24
24
|
class Action
|
25
|
-
|
26
25
|
def self.inherited(base)
|
27
26
|
base.send :include, Conduit::Core::Connection
|
28
27
|
base.send :include, Conduit::Core::Render
|
@@ -41,7 +40,6 @@ module Conduit
|
|
41
40
|
end
|
42
41
|
|
43
42
|
module ClassMethods
|
44
|
-
|
45
43
|
attr_accessor :_action_path
|
46
44
|
|
47
45
|
# Set required attributes
|
@@ -74,7 +72,6 @@ module Conduit
|
|
74
72
|
def attributes
|
75
73
|
@attributes ||= Set.new
|
76
74
|
end
|
77
|
-
|
78
75
|
end
|
79
76
|
|
80
77
|
module InstanceMethods
|
@@ -119,14 +116,14 @@ module Conduit
|
|
119
116
|
# Can be overriden per class.
|
120
117
|
#
|
121
118
|
def view_path
|
122
|
-
File.join(File.dirname(action_path),
|
119
|
+
File.join(File.dirname(action_path), "views")
|
123
120
|
end
|
124
121
|
|
125
122
|
# Return the rendered view
|
126
123
|
#
|
127
124
|
def view
|
128
125
|
tpl = self.class.name.demodulize
|
129
|
-
|
126
|
+
.underscore.downcase
|
130
127
|
render(tpl)
|
131
128
|
end
|
132
129
|
|
@@ -169,7 +166,7 @@ module Conduit
|
|
169
166
|
def validate!(options)
|
170
167
|
missing_keys = (requirements.to_a - options.keys)
|
171
168
|
either_keys = requirements.select { |key| key.is_a?(Array) }
|
172
|
-
missing_keys.reject! { |
|
169
|
+
missing_keys.reject! { |_key| either_keys.any? { |either| (either & options.keys).present? } }
|
173
170
|
if missing_keys.any?
|
174
171
|
raise ArgumentError,
|
175
172
|
"Missing keys: #{missing_keys.join(', ')}"
|
@@ -220,7 +217,7 @@ module Conduit
|
|
220
217
|
# Indicates whether the request should be mocked or not.
|
221
218
|
#
|
222
219
|
def mock_mode?
|
223
|
-
@options.
|
220
|
+
@options.key?(:mock_status) && (!@options[:mock_status].nil? && !@options[:mock_status].empty?)
|
224
221
|
end
|
225
222
|
end
|
226
223
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# communication rom Conduit to a remote host.
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
6
|
+
require "conduit/version"
|
7
|
+
require "forwardable"
|
8
|
+
require "excon"
|
9
9
|
|
10
10
|
module Conduit
|
11
11
|
module Core
|
@@ -16,7 +16,6 @@ module Conduit
|
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
19
|
-
|
20
19
|
# Define a remote_url
|
21
20
|
#
|
22
21
|
# e.g.
|
@@ -25,7 +24,6 @@ module Conduit
|
|
25
24
|
def remote_url(host = nil)
|
26
25
|
@remote_url ||= host
|
27
26
|
end
|
28
|
-
|
29
27
|
end
|
30
28
|
|
31
29
|
module InstanceMethods
|
@@ -48,7 +46,7 @@ module Conduit
|
|
48
46
|
#
|
49
47
|
def request(params, &block)
|
50
48
|
params[:headers] ||= {}
|
51
|
-
params[:headers][
|
49
|
+
params[:headers]["User-Agent"] ||= "conduit/#{Conduit::VERSION}"
|
52
50
|
connection.request(params, &block)
|
53
51
|
rescue Excon::Errors::Timeout => timeout
|
54
52
|
raise(Conduit::TimeOut, timeout.message)
|
@@ -82,9 +80,7 @@ module Conduit
|
|
82
80
|
def connection(**params)
|
83
81
|
@excon ||= Excon.new(remote_url, params)
|
84
82
|
end
|
85
|
-
|
86
83
|
end
|
87
|
-
|
88
84
|
end
|
89
85
|
end
|
90
86
|
end
|
data/lib/conduit/core/driver.rb
CHANGED
@@ -17,14 +17,13 @@
|
|
17
17
|
# => end
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
20
|
+
require "set"
|
21
21
|
|
22
22
|
module Conduit
|
23
23
|
module Core
|
24
24
|
module Driver
|
25
|
-
|
26
25
|
def self.extended(base)
|
27
|
-
base.instance_variable_set(
|
26
|
+
base.instance_variable_set("@_driver_path",
|
28
27
|
File.dirname(caller.first[/^[^:]+/]))
|
29
28
|
end
|
30
29
|
|
@@ -72,8 +71,8 @@ module Conduit
|
|
72
71
|
# => action :purchase
|
73
72
|
#
|
74
73
|
def action(action_name)
|
75
|
-
require File.join(@_driver_path,
|
76
|
-
require File.join(@_driver_path,
|
74
|
+
require File.join(@_driver_path, "actions", action_name.to_s)
|
75
|
+
require File.join(@_driver_path, "parsers", action_name.to_s)
|
77
76
|
actions << action_name
|
78
77
|
end
|
79
78
|
|
@@ -116,7 +115,7 @@ module Conduit
|
|
116
115
|
# => "fusion"
|
117
116
|
#
|
118
117
|
def driver_name
|
119
|
-
|
118
|
+
name.demodulize.underscore.downcase
|
120
119
|
end
|
121
120
|
|
122
121
|
# Returns the current set of required attributes
|
@@ -130,7 +129,6 @@ module Conduit
|
|
130
129
|
def optional_attribute_set
|
131
130
|
@optional_attribute_set ||= Set.new
|
132
131
|
end
|
133
|
-
|
134
132
|
end
|
135
133
|
end
|
136
134
|
end
|
data/lib/conduit/core/parser.rb
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
# predictably consumed.
|
5
5
|
#
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
7
|
+
require "active_support"
|
8
|
+
require "active_support/core_ext/object"
|
9
|
+
require "forwardable"
|
10
|
+
require "set"
|
11
11
|
|
12
12
|
module Conduit
|
13
13
|
module Core
|
@@ -15,7 +15,6 @@ module Conduit
|
|
15
15
|
extend Forwardable
|
16
16
|
|
17
17
|
class << self
|
18
|
-
|
19
18
|
# Define an attribute that will be publically exposed
|
20
19
|
# when dealing with conduit responses.
|
21
20
|
#
|
@@ -29,7 +28,6 @@ module Conduit
|
|
29
28
|
def attributes
|
30
29
|
@attributes ||= Set.new
|
31
30
|
end
|
32
|
-
|
33
31
|
end
|
34
32
|
|
35
33
|
def_delegator :'self.class', :attributes
|
@@ -47,14 +45,14 @@ module Conduit
|
|
47
45
|
# Should be overwritten by parser implementation.
|
48
46
|
#
|
49
47
|
def response_status
|
50
|
-
raise NoMethodError,
|
48
|
+
raise NoMethodError, "Please define response_status in your parser."
|
51
49
|
end
|
52
50
|
|
53
51
|
# Default response error container.
|
54
52
|
# Should be overwritten by parser implementation.
|
55
53
|
#
|
56
54
|
def response_errors
|
57
|
-
raise NoMethodError,
|
55
|
+
raise NoMethodError, "Please define response_errors in your parser."
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
data/lib/conduit/core/render.rb
CHANGED
@@ -5,19 +5,18 @@
|
|
5
5
|
# methods to be of any use.
|
6
6
|
#
|
7
7
|
|
8
|
-
require
|
8
|
+
require "tilt"
|
9
9
|
|
10
10
|
module Conduit
|
11
11
|
module Core
|
12
12
|
module Render
|
13
|
-
|
14
13
|
# Create instance variables, any of these can
|
15
14
|
# be overriden within the including class.
|
16
15
|
#
|
17
16
|
# view_path: Location where the view files are stored
|
18
17
|
# view_context: Object that contains the variables used in the template
|
19
18
|
#
|
20
|
-
def self.included(
|
19
|
+
def self.included(_base)
|
21
20
|
attr_accessor :view_path, :view_context
|
22
21
|
end
|
23
22
|
|
@@ -30,7 +29,7 @@ module Conduit
|
|
30
29
|
# => render :purchase
|
31
30
|
#
|
32
31
|
def render(file, layout: true)
|
33
|
-
raise ViewPathNotDefined,
|
32
|
+
raise ViewPathNotDefined, "" unless view_path
|
34
33
|
layout ? render_with_layout(file) : render_template(file)
|
35
34
|
end
|
36
35
|
|
@@ -63,7 +62,6 @@ module Conduit
|
|
63
62
|
end
|
64
63
|
|
65
64
|
class ViewPathNotDefined < StandardError; end
|
66
|
-
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
@@ -10,9 +10,9 @@
|
|
10
10
|
# the action with its value being the returned status.
|
11
11
|
#
|
12
12
|
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
13
|
+
require "erb"
|
14
|
+
require "excon"
|
15
|
+
require "tilt"
|
16
16
|
|
17
17
|
module Conduit
|
18
18
|
module Core
|
@@ -29,7 +29,7 @@ module Conduit
|
|
29
29
|
#
|
30
30
|
def mock
|
31
31
|
Excon.defaults[:mock] = true
|
32
|
-
Excon.stub({},
|
32
|
+
Excon.stub({}, body: response, status: @http_status)
|
33
33
|
end
|
34
34
|
|
35
35
|
# Ends mocking, override if using something different than
|
@@ -59,7 +59,7 @@ module Conduit
|
|
59
59
|
# Directory where fixtures are stored.
|
60
60
|
#
|
61
61
|
def fixtures_path
|
62
|
-
raise NoMethodError,
|
62
|
+
raise NoMethodError, "Please define fixtures_path in your request mocker."
|
63
63
|
end
|
64
64
|
|
65
65
|
def fixture
|
data/lib/conduit/error.rb
CHANGED
data/lib/conduit/storage.rb
CHANGED
@@ -5,12 +5,11 @@
|
|
5
5
|
# TODO: Support multiple storage providers
|
6
6
|
#
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
8
|
+
require "conduit/storage/aws"
|
9
|
+
require "conduit/storage/file"
|
10
10
|
|
11
11
|
module Conduit
|
12
12
|
module Storage
|
13
|
-
|
14
13
|
# Wrapper around the configuration object
|
15
14
|
#
|
16
15
|
# Configurable in:
|
@@ -32,6 +31,5 @@ module Conduit
|
|
32
31
|
#
|
33
32
|
storage_provider_module = const_get(provider.to_s.humanize)
|
34
33
|
extend storage_provider_module
|
35
|
-
|
36
34
|
end
|
37
35
|
end
|
data/lib/conduit/storage/aws.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# TODO: Support multiple storage providers
|
6
6
|
#
|
7
7
|
|
8
|
-
require
|
8
|
+
require "aws-sdk"
|
9
9
|
|
10
10
|
module Conduit
|
11
11
|
module Storage
|
@@ -18,7 +18,6 @@ module Conduit
|
|
18
18
|
end
|
19
19
|
|
20
20
|
module ClassMethods
|
21
|
-
|
22
21
|
# Configure AWS::S3 with credentials if provided, else, assume
|
23
22
|
# IAM will provide them.
|
24
23
|
#
|
@@ -87,9 +86,7 @@ module Conduit
|
|
87
86
|
rescue AWS::S3::Errors::NoSuchKey
|
88
87
|
nil
|
89
88
|
end
|
90
|
-
|
91
89
|
end
|
92
|
-
|
93
90
|
end
|
94
91
|
end
|
95
92
|
end
|
data/lib/conduit/storage/file.rb
CHANGED
@@ -5,13 +5,12 @@
|
|
5
5
|
# TODO: Support multiple storage providers
|
6
6
|
#
|
7
7
|
|
8
|
-
require
|
9
|
-
require
|
8
|
+
require "fileutils"
|
9
|
+
require "pathname"
|
10
10
|
|
11
11
|
module Conduit
|
12
12
|
module Storage
|
13
13
|
module File
|
14
|
-
|
15
14
|
#
|
16
15
|
# TODO: Rename this, I originally used file,
|
17
16
|
# not considering the fact that it's
|
@@ -23,7 +22,6 @@ module Conduit
|
|
23
22
|
end
|
24
23
|
|
25
24
|
module ClassMethods
|
26
|
-
|
27
25
|
# Return a Pathname object for the
|
28
26
|
# configured file path
|
29
27
|
#
|
@@ -40,7 +38,7 @@ module Conduit
|
|
40
38
|
full_path = storage_path.join(key)
|
41
39
|
FileUtils.mkdir_p(::File.dirname(full_path))
|
42
40
|
|
43
|
-
::File.open(full_path,
|
41
|
+
::File.open(full_path, "wb") do |f|
|
44
42
|
f.write(content)
|
45
43
|
end
|
46
44
|
end
|
@@ -66,9 +64,7 @@ module Conduit
|
|
66
64
|
rescue Errno::ENOENT, Errno::EPERM
|
67
65
|
nil
|
68
66
|
end
|
69
|
-
|
70
67
|
end
|
71
|
-
|
72
68
|
end
|
73
69
|
end
|
74
70
|
end
|
data/lib/conduit/util.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Conduit
|
2
2
|
module Util
|
3
|
-
|
4
3
|
# Instantiate the action class with options
|
5
4
|
#
|
6
5
|
# returns:
|
@@ -12,13 +11,12 @@ module Conduit
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def self.find_driver!(*args)
|
15
|
-
driver = args.map(&:to_s).map(&:camelize).join(
|
14
|
+
driver = args.map(&:to_s).map(&:camelize).join("::")
|
16
15
|
Conduit::Driver.const_get(driver)
|
17
16
|
rescue NameError => error
|
18
|
-
message = "Unable to find driver with arguments: #{args.join ','}. "
|
17
|
+
message = "Unable to find driver with arguments: #{args.join ','}. " \
|
19
18
|
"Expected #{error.name} to be implemented"
|
20
|
-
raise NameError
|
19
|
+
raise NameError, message
|
21
20
|
end
|
22
|
-
|
23
21
|
end
|
24
22
|
end
|
data/lib/conduit/version.rb
CHANGED
@@ -1,28 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
shared_examples_for Conduit::Core::Action do
|
4
|
-
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:response) { read_support_file('xml/xml_response.xml') }
|
4
|
+
let(:request) { read_support_file("xml/xml_request.xml") }
|
5
|
+
let(:modified_request) { read_support_file("xml/xml_modified_request.xml") }
|
6
|
+
let(:response) { read_support_file("xml/xml_response.xml") }
|
8
7
|
|
9
8
|
subject do
|
10
9
|
described_class.new(request_attributes)
|
11
10
|
end
|
12
11
|
|
13
|
-
context
|
12
|
+
context "without an instance" do
|
14
13
|
its(:class) { should respond_to(:remote_url) }
|
15
14
|
its(:class) { should respond_to(:required_attributes) }
|
16
15
|
its(:class) { should respond_to(:optional_attributes) }
|
17
16
|
|
18
|
-
describe
|
19
|
-
it
|
17
|
+
describe ".requirements" do
|
18
|
+
it "returns an array of required attributes" do
|
20
19
|
subject.class.requirements.should == [:foo, :bar, :baz, [:either, :or]].to_set
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
describe
|
25
|
-
it
|
23
|
+
describe ".attributes" do
|
24
|
+
it "returns an array of known attributes" do
|
26
25
|
subject.class.requirements.should == [:foo, :bar, :baz, [:either, :or]].to_set
|
27
26
|
end
|
28
27
|
end
|
@@ -43,14 +42,14 @@ shared_examples_for Conduit::Core::Action do
|
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
|
-
context
|
47
|
-
describe
|
48
|
-
context
|
45
|
+
context "with an instance" do
|
46
|
+
describe "#attributes_with_values" do
|
47
|
+
context "with optional attribute not set" do
|
49
48
|
let (:attrs) { request_attributes.merge(buz: nil, or: nil) }
|
50
49
|
its(:attributes_with_values) { should include(attrs) }
|
51
50
|
end
|
52
51
|
|
53
|
-
context
|
52
|
+
context "with optional attribute set" do
|
54
53
|
let (:attrs) { request_attributes.merge(buz: "value for buz", or: nil) }
|
55
54
|
subject { described_class.new(attrs) }
|
56
55
|
its(:attributes_with_values) { should include(attrs) }
|
@@ -61,26 +60,26 @@ shared_examples_for Conduit::Core::Action do
|
|
61
60
|
end
|
62
61
|
end
|
63
62
|
|
64
|
-
describe
|
63
|
+
describe "#view" do
|
65
64
|
before do
|
66
65
|
Excon.stub({}, body: request, status: 200)
|
67
66
|
end
|
68
67
|
|
69
|
-
it
|
70
|
-
a = subject.view.gsub(/\s+/,
|
71
|
-
b = request.gsub(/\s+/,
|
68
|
+
it "returns a rendered view for an action" do
|
69
|
+
a = subject.view.gsub(/\s+/, "")
|
70
|
+
b = request.gsub(/\s+/, "")
|
72
71
|
a.should == b
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
76
|
-
describe
|
77
|
-
context
|
78
|
-
it
|
75
|
+
describe "#view_context" do
|
76
|
+
context "without decorator class" do
|
77
|
+
it "returns an instance of core decorator" do
|
79
78
|
subject.view_context.should be_a_kind_of(Conduit::Core::Decorator)
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
83
|
-
context
|
82
|
+
context "with decorator class" do
|
84
83
|
let(:driver) { subject.class.name.deconstantize.demodulize }
|
85
84
|
let(:action) { subject.class.name.demodulize }
|
86
85
|
|
@@ -114,31 +113,30 @@ shared_examples_for Conduit::Core::Action do
|
|
114
113
|
Excon.stub({}, body: modified_request, status: 200)
|
115
114
|
end
|
116
115
|
|
117
|
-
it
|
118
|
-
subject.view_context.should be_a_kind_of(Conduit.const_get(driver)::Decorators
|
116
|
+
it "returns an instance of core decorator" do
|
117
|
+
subject.view_context.should be_a_kind_of(Conduit.const_get(driver)::Decorators.const_get("#{action}Decorator"))
|
119
118
|
end
|
120
119
|
|
121
|
-
it
|
122
|
-
a = subject.view.gsub(/\s+/,
|
123
|
-
b = modified_request.gsub(/\s+/,
|
120
|
+
it "returns a new rendered view for an action" do
|
121
|
+
a = subject.view.gsub(/\s+/, "")
|
122
|
+
b = modified_request.gsub(/\s+/, "")
|
124
123
|
a.should == b
|
125
124
|
end
|
126
125
|
end
|
127
126
|
end
|
128
127
|
|
129
|
-
describe
|
128
|
+
describe "#perform" do
|
130
129
|
before { Excon.stub({}, body: response, status: 200) }
|
131
130
|
|
132
|
-
it
|
131
|
+
it "returns a response wrapper" do
|
133
132
|
subject.perform.should be_a_kind_of(Conduit::ApiResponse)
|
134
133
|
end
|
135
134
|
|
136
|
-
it
|
135
|
+
it "should return the raw_content" do
|
137
136
|
subject.perform.body.should_not be_nil
|
138
137
|
end
|
139
138
|
end
|
140
139
|
end
|
141
|
-
|
142
140
|
end
|
143
141
|
|
144
142
|
describe Conduit::Driver::MyDriver::Foo do
|
@@ -1,40 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
shared_examples_for Conduit::Core::Driver do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
it 'returns an array of required credentials' do
|
4
|
+
context "without an instance" do
|
5
|
+
describe ".credentials" do
|
6
|
+
it "returns an array of required credentials" do
|
8
7
|
subject.credentials.should == [:username, :password].to_set
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
12
|
-
describe
|
13
|
-
it
|
11
|
+
describe ".actions" do
|
12
|
+
it "returns an array of known action" do
|
14
13
|
subject.actions.should == [:foo].to_set
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
|
-
describe
|
19
|
-
it
|
17
|
+
describe ".permitted_attributes" do
|
18
|
+
it "returns the union of required and optional attributes" do
|
20
19
|
subject.permitted_attributes.should == [:subdomain, :mock].to_set
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
describe
|
25
|
-
it
|
23
|
+
describe "required_attributes" do
|
24
|
+
it "should return only the required attributes" do
|
26
25
|
subject.required_attributes.should eql [:subdomain].to_set
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
describe
|
31
|
-
it
|
29
|
+
describe "optional_attributes" do
|
30
|
+
it "should return only the optional attributes" do
|
32
31
|
subject.optional_attributes.should eql [:mock].to_set
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
36
34
|
end
|
37
|
-
|
38
35
|
end
|
39
36
|
|
40
37
|
describe Conduit::Driver::MyDriver do
|
@@ -1,50 +1,48 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
shared_examples_for Conduit::Core::Parser do
|
4
|
-
|
5
|
-
let(:response) { read_support_file('xml/xml_response.xml') }
|
4
|
+
let(:response) { read_support_file("xml/xml_response.xml") }
|
6
5
|
|
7
6
|
subject do
|
8
7
|
described_class.new(response)
|
9
8
|
end
|
10
9
|
|
11
|
-
context
|
10
|
+
context "without an instance" do
|
12
11
|
its(:class) { should respond_to(:attribute) }
|
13
12
|
its(:class) { should respond_to(:attributes) }
|
14
13
|
end
|
15
14
|
|
16
|
-
context
|
17
|
-
describe
|
18
|
-
it
|
15
|
+
context "with an instance" do
|
16
|
+
describe "#attributes" do
|
17
|
+
it "returns an array of known attributes" do
|
19
18
|
subject.attributes.should == [:foo, :bar, :baz].to_set
|
20
19
|
end
|
21
20
|
|
22
|
-
it
|
23
|
-
subject.foo.should ==
|
21
|
+
it "defines a method for foo" do
|
22
|
+
subject.foo.should == "foo"
|
24
23
|
end
|
25
24
|
|
26
|
-
it
|
27
|
-
subject.bar.should ==
|
25
|
+
it "defines a method for bar" do
|
26
|
+
subject.bar.should == "bar"
|
28
27
|
end
|
29
28
|
|
30
|
-
it
|
31
|
-
subject.baz.should ==
|
29
|
+
it "defines a method for baz" do
|
30
|
+
subject.baz.should == "baz"
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
describe
|
36
|
-
it
|
37
|
-
subject.response_status.should ==
|
34
|
+
describe "#response_status" do
|
35
|
+
it "should respond with success" do
|
36
|
+
subject.response_status.should == "success"
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
describe
|
42
|
-
it
|
40
|
+
describe "#response_errors" do
|
41
|
+
it "should respond with an empty array" do
|
43
42
|
subject.response_errors.should == []
|
44
43
|
end
|
45
44
|
end
|
46
45
|
end
|
47
|
-
|
48
46
|
end
|
49
47
|
|
50
48
|
describe Conduit::Driver::MyDriver::Foo::Parser do
|
@@ -1,40 +1,39 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "excon"
|
3
3
|
|
4
4
|
shared_examples_for Conduit::Core::RequestMocker do
|
5
|
-
|
6
|
-
let(:
|
7
|
-
let(:failure) { read_support_file('xml/failure_mock.xml') }
|
5
|
+
let(:success) { read_support_file("xml/success_mock.xml") }
|
6
|
+
let(:failure) { read_support_file("xml/failure_mock.xml") }
|
8
7
|
let(:fake_action) do
|
9
8
|
class FakeAction
|
10
9
|
def view_context
|
11
|
-
OpenStruct.new(
|
10
|
+
OpenStruct.new(value: "Yay!")
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
14
|
FakeAction.new
|
16
15
|
end
|
17
16
|
|
18
|
-
context
|
19
|
-
subject { described_class.new(fake_action,
|
20
|
-
let(:response) { subject.with_mocking { Excon.new(
|
21
|
-
it
|
17
|
+
context "success mocking" do
|
18
|
+
subject { described_class.new(fake_action, mock_status: "success") }
|
19
|
+
let(:response) { subject.with_mocking { Excon.new("http://example.com").request }.body }
|
20
|
+
it "return success response" do
|
22
21
|
response.should eq(success)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
context
|
27
|
-
subject { described_class.new(fake_action,
|
28
|
-
let(:response) { subject.with_mocking { Excon.new(
|
29
|
-
it
|
25
|
+
context "failure mocking" do
|
26
|
+
subject { described_class.new(fake_action, mock_status: "failure") }
|
27
|
+
let(:response) { subject.with_mocking { Excon.new("http://example.com").request }.body }
|
28
|
+
it "return failure response" do
|
30
29
|
response.should eq(failure)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
|
-
context
|
35
|
-
subject { described_class.new(fake_action,
|
36
|
-
let(:response) { subject.with_mocking { Excon.new(
|
37
|
-
it
|
33
|
+
context "with disallowed response status" do
|
34
|
+
subject { described_class.new(fake_action, mock_status: "fake_status") }
|
35
|
+
let(:response) { subject.with_mocking { Excon.new("http://example.com").request }.body }
|
36
|
+
it "raises and error" do
|
38
37
|
lambda { response }.should raise_error(ArgumentError)
|
39
38
|
end
|
40
39
|
end
|
data/spec/classes/util_spec.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Conduit::Util do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe "find_driver" do
|
5
|
+
it "should find MyDriver" do
|
6
6
|
driver = Conduit::Util.find_driver(:my_driver)
|
7
7
|
driver.should_not be_nil
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it "should not throw exception for missing driver" do
|
11
11
|
driver = Conduit::Util.find_driver(:missing)
|
12
12
|
driver.should be_nil
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
17
|
-
it
|
16
|
+
describe "find_driver!" do
|
17
|
+
it "should throw NameError if it driver not found" do
|
18
18
|
lambda do
|
19
19
|
Conduit::Util.find_driver!(:not_really_there)
|
20
20
|
end.should raise_error(NameError)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# Require Files
|
2
2
|
#
|
3
|
-
require
|
3
|
+
require "bundler/setup"
|
4
4
|
Bundler.setup
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
6
|
+
require "rspec"
|
7
|
+
require "rspec/its"
|
8
|
+
require "shoulda/matchers"
|
9
|
+
require "conduit"
|
10
10
|
|
11
11
|
# Load all of the _spec.rb files
|
12
12
|
#
|
13
|
-
Dir[File.join(File.dirname(__FILE__),
|
13
|
+
Dir[File.join(File.dirname(__FILE__), "support", "**", "*.rb")].each { |f| require f }
|
14
14
|
|
15
15
|
# Rspec Configuration
|
16
16
|
#
|
@@ -24,9 +24,9 @@ RSpec.configure do |config|
|
|
24
24
|
config.before(:suite) do
|
25
25
|
Excon.defaults[:mock] = true
|
26
26
|
Conduit.configure do |c|
|
27
|
-
c.driver_paths << File.join(__dir__,
|
27
|
+
c.driver_paths << File.join(__dir__, "support")
|
28
28
|
end
|
29
29
|
|
30
30
|
Conduit::Driver.load_drivers
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
data/spec/support/helper.rb
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require "nokogiri"
|
2
2
|
|
3
3
|
module Conduit::Driver::MyDriver
|
4
4
|
class Foo::Parser < Conduit::Core::Parser
|
5
|
-
|
6
5
|
def initialize(xml)
|
7
6
|
@xml = xml
|
8
7
|
end
|
9
8
|
|
10
9
|
attribute :foo do
|
11
|
-
|
10
|
+
"foo"
|
12
11
|
end
|
13
12
|
|
14
13
|
attribute :bar do
|
15
|
-
|
14
|
+
"bar"
|
16
15
|
end
|
17
16
|
|
18
17
|
attribute :baz do
|
19
|
-
|
18
|
+
"baz"
|
20
19
|
end
|
21
20
|
|
22
21
|
# Return "success/failure". This gets
|
@@ -24,7 +23,7 @@ module Conduit::Driver::MyDriver
|
|
24
23
|
# as a type of notification
|
25
24
|
#
|
26
25
|
def response_status
|
27
|
-
string_path(
|
26
|
+
string_path("/BeQuick/response/@status")
|
28
27
|
end
|
29
28
|
|
30
29
|
# Return an array of error objects
|
@@ -34,8 +33,8 @@ module Conduit::Driver::MyDriver
|
|
34
33
|
# => [{"code"=>nil, "message"=>"Unable to locate telephone by MDN"}]
|
35
34
|
#
|
36
35
|
def response_errors
|
37
|
-
object_path(
|
38
|
-
Hash.from_xml(error.to_s)[
|
36
|
+
object_path("/BeQuick/response/errors/error").map do |error|
|
37
|
+
Hash.from_xml(error.to_s)["error"]
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
@@ -70,6 +69,5 @@ module Conduit::Driver::MyDriver
|
|
70
69
|
def string_path(path, node = doc)
|
71
70
|
object_path(path, node).to_s
|
72
71
|
end
|
73
|
-
|
74
72
|
end
|
75
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conduit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Kelley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: aws-sdk
|
28
|
+
name: aws-sdk-v1
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
version: '0'
|
238
238
|
requirements: []
|
239
239
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.
|
240
|
+
rubygems_version: 2.2.2
|
241
241
|
signing_key:
|
242
242
|
specification_version: 4
|
243
243
|
summary: Conduit is an interface for debit platforms.
|
@@ -262,4 +262,3 @@ test_files:
|
|
262
262
|
- spec/support/xml/xml_modified_request.xml
|
263
263
|
- spec/support/xml/xml_request.xml
|
264
264
|
- spec/support/xml/xml_response.xml
|
265
|
-
has_rdoc:
|