conduit 0.4.1 → 0.5.0
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/lib/conduit.rb +7 -6
- data/lib/conduit/core/action.rb +23 -12
- data/lib/conduit/core/connection.rb +28 -27
- data/lib/conduit/core/driver.rb +10 -10
- data/lib/conduit/core/parser.rb +2 -2
- data/lib/conduit/core/render.rb +1 -1
- data/lib/conduit/response.rb +11 -0
- data/lib/conduit/storage/aws.rb +9 -8
- data/lib/conduit/time_out.rb +4 -0
- data/lib/conduit/version.rb +1 -1
- data/spec/classes/core/action_spec.rb +4 -6
- data/spec/support/helper.rb +2 -2
- data/spec/support/my_driver/actions/foo.rb +5 -0
- data/spec/support/my_driver/parsers/foo.rb +5 -5
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3152108f595eb0bd81712bbdc9dae55fe09d3771
|
4
|
+
data.tar.gz: 75290c49ca35147c1f4a9dc35d753f51f60e2655
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e9a1464fe147247106035fad8ac057551ddbb90f8e34af1a3b7923175fd8e468b75983769a7d879e9050bee744d42be2aec6890a019f8413de46c96edd40ca
|
7
|
+
data.tar.gz: 5999fe406736a0d60b2f494677bd423115c15e6b91d9534185a7163b630d4290e0bb60b2c68210a3aee9afc3fec79b06964fb78dc0b3d3efe3f71ef3281b574b
|
data/lib/conduit.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
2
2
|
|
3
3
|
require 'conduit/configuration'
|
4
4
|
|
@@ -8,8 +8,10 @@ module Conduit
|
|
8
8
|
# NOTE: Autoloading should be
|
9
9
|
# concurrency-safe
|
10
10
|
#
|
11
|
-
autoload :Storage,
|
12
|
-
autoload :Util,
|
11
|
+
autoload :Storage, 'conduit/storage'
|
12
|
+
autoload :Util, 'conduit/util'
|
13
|
+
autoload :Response, 'conduit/response'
|
14
|
+
autoload :TimeOut, 'conduit/time_out'
|
13
15
|
|
14
16
|
module Core
|
15
17
|
|
@@ -22,7 +24,6 @@ module Conduit
|
|
22
24
|
autoload :Action, 'conduit/core/action'
|
23
25
|
autoload :Parser, 'conduit/core/parser'
|
24
26
|
autoload :Driver, 'conduit/core/driver'
|
25
|
-
|
26
27
|
end
|
27
28
|
|
28
29
|
module Driver
|
@@ -42,9 +43,9 @@ module Conduit
|
|
42
43
|
#
|
43
44
|
def load_drivers
|
44
45
|
Conduit.configuration.driver_paths.each do |dir|
|
45
|
-
raise "Directory not found: #{dir}" unless File.
|
46
|
+
raise "Directory not found: #{dir}" unless File.exist?(dir)
|
46
47
|
Dir["#{dir}/**/driver.rb"].each do |file|
|
47
|
-
raise "File not found: #{file}" unless File.
|
48
|
+
raise "File not found: #{file}" unless File.exist?(file)
|
48
49
|
name = File.dirname(file).split(File::SEPARATOR).last.classify.to_sym
|
49
50
|
index << name.downcase
|
50
51
|
autoload name, file
|
data/lib/conduit/core/action.rb
CHANGED
@@ -98,7 +98,7 @@ module Conduit
|
|
98
98
|
# used.
|
99
99
|
#
|
100
100
|
def view_context
|
101
|
-
OpenStruct.new(@options.select do |k,v|
|
101
|
+
OpenStruct.new(@options.select do |k, v|
|
102
102
|
attributes.include?(k)
|
103
103
|
end)
|
104
104
|
end
|
@@ -125,23 +125,34 @@ module Conduit
|
|
125
125
|
# Override to customize.
|
126
126
|
#
|
127
127
|
def perform
|
128
|
-
request(body: view, method: :post)
|
128
|
+
response = request(body: view, method: :post)
|
129
|
+
parser = parser_class.new(response.body)
|
130
|
+
|
131
|
+
Conduit::Response.new(raw_response: response,
|
132
|
+
parser: parser)
|
129
133
|
end
|
130
134
|
|
131
135
|
private
|
132
136
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
137
|
+
# Ensures that all required attributes are present
|
138
|
+
# If not all attributes are present, will raise
|
139
|
+
# an ArgumentError listing missing attributes
|
140
|
+
#
|
141
|
+
def validate!(options)
|
142
|
+
missing_keys = (requirements.to_a - options.keys)
|
143
|
+
if missing_keys.any?
|
144
|
+
raise ArgumentError,
|
145
|
+
"Missing keys: #{missing_keys.join(', ')}"
|
143
146
|
end
|
147
|
+
end
|
144
148
|
|
149
|
+
# Returns the parser for this action
|
150
|
+
# subclasses responsible for providing the
|
151
|
+
# response_body and response_status.
|
152
|
+
#
|
153
|
+
def parser_class
|
154
|
+
self.class.const_get(:Parser)
|
155
|
+
end
|
145
156
|
end
|
146
157
|
|
147
158
|
end
|
@@ -10,7 +10,6 @@ require 'excon'
|
|
10
10
|
module Conduit
|
11
11
|
module Core
|
12
12
|
module Connection
|
13
|
-
|
14
13
|
def self.included(base)
|
15
14
|
base.extend ClassMethods
|
16
15
|
base.send :include, InstanceMethods
|
@@ -23,7 +22,7 @@ module Conduit
|
|
23
22
|
# e.g.
|
24
23
|
# remote_url 'http://myapi.com/endpoint'
|
25
24
|
#
|
26
|
-
def remote_url(host=nil)
|
25
|
+
def remote_url(host = nil)
|
27
26
|
@remote_url ||= host
|
28
27
|
end
|
29
28
|
|
@@ -51,37 +50,39 @@ module Conduit
|
|
51
50
|
params[:headers] ||= {}
|
52
51
|
params[:headers]['User-Agent'] ||= "conduit/#{Conduit::VERSION}"
|
53
52
|
connection.request(params, &block)
|
53
|
+
rescue Excon::Errors::Timeout => timeout
|
54
|
+
raise(Conduit::Errors::Timeout, timeout.message)
|
54
55
|
end
|
55
56
|
|
56
57
|
private
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
59
|
+
# Connection that will be used
|
60
|
+
#
|
61
|
+
# @param [Hash] params
|
62
|
+
# @option params [String] :body Default text to be sent over a socket. Only used if :body absent in Connection#request params
|
63
|
+
# @option params [Hash<Symbol, String>] :headers The default headers to supply in a request. Only used if params[:headers] is not supplied to Connection#request
|
64
|
+
# @option params [String] :host The destination host's reachable DNS name or IP, in the form of a String
|
65
|
+
# @option params [String] :path Default path; appears after 'scheme://host:port/'. Only used if params[:path] is not supplied to Connection#request
|
66
|
+
# @option params [Fixnum] :port The port on which to connect, to the destination host
|
67
|
+
# @option params [Hash] :query Default query; appended to the 'scheme://host:port/path/' in the form of '?key=value'. Will only be used if params[:query] is not supplied to Connection#request
|
68
|
+
# @option params [String] :scheme The protocol; 'https' causes OpenSSL to be used
|
69
|
+
# @option params [String] :proxy Proxy server; e.g. 'http://myproxy.com:8888'
|
70
|
+
# @option params [Fixnum] :retry_limit Set how many times we'll retry a failed request. (Default 4)
|
71
|
+
# @option params [Class] :instrumentor Responds to #instrument as in ActiveSupport::Notifications
|
72
|
+
# @option params [String] :instrumentor_name Name prefix for #instrument events. Defaults to 'excon'
|
73
|
+
#
|
74
|
+
# @return [Excon::Response]
|
75
|
+
#
|
76
|
+
# @raise [Excon::Errors::StubNotFound]
|
77
|
+
# @raise [Excon::Errors::Timeout]
|
78
|
+
# @raise [Excon::Errors::SocketError]
|
79
|
+
#
|
80
|
+
def connection(**params)
|
81
|
+
@excon ||= Excon.new(remote_url, params)
|
82
|
+
end
|
82
83
|
|
83
84
|
end
|
84
85
|
|
85
86
|
end
|
86
87
|
end
|
87
|
-
end
|
88
|
+
end
|
data/lib/conduit/core/driver.rb
CHANGED
@@ -22,7 +22,7 @@ module Conduit
|
|
22
22
|
module Driver
|
23
23
|
|
24
24
|
def self.extended(base)
|
25
|
-
base.instance_variable_set(
|
25
|
+
base.instance_variable_set('@_driver_path',
|
26
26
|
File.dirname(caller.first[/^[^:]+/]))
|
27
27
|
end
|
28
28
|
|
@@ -68,15 +68,15 @@ module Conduit
|
|
68
68
|
|
69
69
|
private
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
71
|
+
# Return the name of the driver
|
72
|
+
#
|
73
|
+
# e.g.
|
74
|
+
# Conduit::Drivers::Fusion.name
|
75
|
+
# => "fusion"
|
76
|
+
#
|
77
|
+
def driver_name
|
78
|
+
self.name.demodulize.underscore.downcase
|
79
|
+
end
|
80
80
|
|
81
81
|
end
|
82
82
|
end
|
data/lib/conduit/core/parser.rb
CHANGED
@@ -45,14 +45,14 @@ module Conduit
|
|
45
45
|
# Should be overwritten by parser implementation.
|
46
46
|
#
|
47
47
|
def response_status
|
48
|
-
raise NoMethodError,
|
48
|
+
raise NoMethodError, 'Please define response_status in your parser.'
|
49
49
|
end
|
50
50
|
|
51
51
|
# Default response error container.
|
52
52
|
# Should be overwritten by parser implementation.
|
53
53
|
#
|
54
54
|
def response_errors
|
55
|
-
raise NoMethodError,
|
55
|
+
raise NoMethodError, 'Please define response_errors in your parser.'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
data/lib/conduit/core/render.rb
CHANGED
data/lib/conduit/storage/aws.rb
CHANGED
@@ -19,16 +19,17 @@ module Conduit
|
|
19
19
|
|
20
20
|
module ClassMethods
|
21
21
|
|
22
|
-
# Configure AWS::S3 if
|
23
|
-
#
|
24
|
-
# TODO: This needs to be tested against AWS IAM.
|
25
|
-
# I'm thinking this being a "module"
|
26
|
-
# might cause issues.
|
22
|
+
# Configure AWS::S3 with credentials if provided, else, assume
|
23
|
+
# IAM will provide them.
|
27
24
|
#
|
28
25
|
def configure
|
29
|
-
if [:aws_access_key_id, :aws_access_secret].all? { |key| config.
|
30
|
-
AWS.config(
|
31
|
-
:
|
26
|
+
if [:aws_access_key_id, :aws_access_secret].all? { |key| config.key?(key) }
|
27
|
+
AWS.config(
|
28
|
+
access_key_id: config[:aws_access_key_id],
|
29
|
+
secret_access_key: config[:aws_access_secret]
|
30
|
+
)
|
31
|
+
else
|
32
|
+
AWS.config
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
data/lib/conduit/version.rb
CHANGED
@@ -43,14 +43,12 @@ shared_examples_for Conduit::Core::Action do
|
|
43
43
|
describe '#perform' do
|
44
44
|
before { Excon.stub({}, body: response, status: 200) }
|
45
45
|
|
46
|
-
it 'returns a
|
47
|
-
subject.perform.
|
46
|
+
it 'returns a response wrapper' do
|
47
|
+
subject.perform.should be_a_kind_of(Conduit::Response)
|
48
48
|
end
|
49
49
|
|
50
|
-
it '
|
51
|
-
|
52
|
-
b = response.gsub(/\s+/, '')
|
53
|
-
a.should == b
|
50
|
+
it 'should return the raw_content' do
|
51
|
+
subject.perform.body.should_not be_nil
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
data/spec/support/helper.rb
CHANGED
@@ -8,15 +8,15 @@ module Conduit::Driver::MyDriver
|
|
8
8
|
end
|
9
9
|
|
10
10
|
attribute :foo do
|
11
|
-
|
11
|
+
'foo'
|
12
12
|
end
|
13
13
|
|
14
14
|
attribute :bar do
|
15
|
-
|
15
|
+
'bar'
|
16
16
|
end
|
17
17
|
|
18
18
|
attribute :baz do
|
19
|
-
|
19
|
+
'baz'
|
20
20
|
end
|
21
21
|
|
22
22
|
# Return "success/failure". This gets
|
@@ -57,7 +57,7 @@ module Conduit::Driver::MyDriver
|
|
57
57
|
# object_path('//resources/@timestamp')
|
58
58
|
# => [#<Nokogiri::XML::Attr:0x3fca8b040818 name="timestamp" value="20140130180057">]
|
59
59
|
#
|
60
|
-
def object_path(path, node=doc)
|
60
|
+
def object_path(path, node = doc)
|
61
61
|
node.xpath(path)
|
62
62
|
end
|
63
63
|
|
@@ -67,7 +67,7 @@ module Conduit::Driver::MyDriver
|
|
67
67
|
# string_path('//resources/@timestamp')
|
68
68
|
# => 20140130180057
|
69
69
|
#
|
70
|
-
def string_path(path, node=doc)
|
70
|
+
def string_path(path, node = doc)
|
71
71
|
object_path(path, node).to_s
|
72
72
|
end
|
73
73
|
|
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: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Kelley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -136,9 +136,11 @@ files:
|
|
136
136
|
- lib/conduit/core/parser.rb
|
137
137
|
- lib/conduit/core/render.rb
|
138
138
|
- lib/conduit/drivers/keep
|
139
|
+
- lib/conduit/response.rb
|
139
140
|
- lib/conduit/storage/aws.rb
|
140
141
|
- lib/conduit/storage/file.rb
|
141
142
|
- lib/conduit/storage.rb
|
143
|
+
- lib/conduit/time_out.rb
|
142
144
|
- lib/conduit/util.rb
|
143
145
|
- lib/conduit/version.rb
|
144
146
|
- lib/conduit.rb
|