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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aef71bc68a9d9085d6cdae58a21a60cb6709124b
4
- data.tar.gz: 6e9d85b0aa5a0ec98fb1a3ac90bfcd5833d8a88b
3
+ metadata.gz: 3152108f595eb0bd81712bbdc9dae55fe09d3771
4
+ data.tar.gz: 75290c49ca35147c1f4a9dc35d753f51f60e2655
5
5
  SHA512:
6
- metadata.gz: 95d5163cf0ae501b624e37d2f95b76503b4c7683338319c1bc1fcf03e4e7796c3e550d093164209828688a6ee4187adf464e15de9637d50022871f30b85e117e
7
- data.tar.gz: 88a27616a8fc3a67fa5042520386c3d445f87611bcfa8cf1ad15dea54de6942083a6ad56e584e832b9a3959b9c8b7afdde65fdbeebeb4d8247e6f85f52b7b7f2
6
+ metadata.gz: 65e9a1464fe147247106035fad8ac057551ddbb90f8e34af1a3b7923175fd8e468b75983769a7d879e9050bee744d42be2aec6890a019f8413de46c96edd40ca
7
+ data.tar.gz: 5999fe406736a0d60b2f494677bd423115c15e6b91d9534185a7163b630d4290e0bb60b2c68210a3aee9afc3fec79b06964fb78dc0b3d3efe3f71ef3281b574b
data/lib/conduit.rb CHANGED
@@ -1,4 +1,4 @@
1
- $:.unshift File.dirname(__FILE__)
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, 'conduit/storage'
12
- autoload :Util, 'conduit/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.exists?(dir)
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.exists?(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
@@ -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
- # Ensures that all required attributes are present
134
- # If not all attributes are present, will raise
135
- # an ArgumentError listing missing attributes
136
- #
137
- def validate!(options)
138
- missing_keys = (requirements.to_a - options.keys)
139
- if missing_keys.any?
140
- raise ArgumentError,
141
- "Missing keys: #{missing_keys.join(', ')}"
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
- # Connection that will be used
59
- #
60
- # @param [Hash] params
61
- # @option params [String] :body Default text to be sent over a socket. Only used if :body absent in Connection#request params
62
- # @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
63
- # @option params [String] :host The destination host's reachable DNS name or IP, in the form of a String
64
- # @option params [String] :path Default path; appears after 'scheme://host:port/'. Only used if params[:path] is not supplied to Connection#request
65
- # @option params [Fixnum] :port The port on which to connect, to the destination host
66
- # @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
67
- # @option params [String] :scheme The protocol; 'https' causes OpenSSL to be used
68
- # @option params [String] :proxy Proxy server; e.g. 'http://myproxy.com:8888'
69
- # @option params [Fixnum] :retry_limit Set how many times we'll retry a failed request. (Default 4)
70
- # @option params [Class] :instrumentor Responds to #instrument as in ActiveSupport::Notifications
71
- # @option params [String] :instrumentor_name Name prefix for #instrument events. Defaults to 'excon'
72
- #
73
- # @return [Excon::Response]
74
- #
75
- # @raise [Excon::Errors::StubNotFound]
76
- # @raise [Excon::Errors::Timeout]
77
- # @raise [Excon::Errors::SocketError]
78
- #
79
- def connection(**params)
80
- @excon ||= Excon.new(remote_url, params)
81
- end
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
@@ -22,7 +22,7 @@ module Conduit
22
22
  module Driver
23
23
 
24
24
  def self.extended(base)
25
- base.instance_variable_set("@_driver_path",
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
- # 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
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
@@ -45,14 +45,14 @@ module Conduit
45
45
  # Should be overwritten by parser implementation.
46
46
  #
47
47
  def response_status
48
- raise NoMethodError, "Please define response_status in your parser."
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, "Please define response_errors in your parser."
55
+ raise NoMethodError, 'Please define response_errors in your parser.'
56
56
  end
57
57
  end
58
58
  end
@@ -30,7 +30,7 @@ module Conduit
30
30
  # => render :purchase
31
31
  #
32
32
  def render(file, layout: true)
33
- raise ViewPathNotDefined, "" unless view_path
33
+ raise ViewPathNotDefined, '' unless view_path
34
34
  layout ? render_with_layout(file) : render_template(file)
35
35
  end
36
36
 
@@ -0,0 +1,11 @@
1
+ module Conduit
2
+ class Response
3
+ attr_reader :body, :parser, :raw_response
4
+
5
+ def initialize(options = {})
6
+ @raw_response = options[:raw_response]
7
+ @body = options.fetch(:body, raw_response.body)
8
+ @parser = options[:parser]
9
+ end
10
+ end
11
+ end
@@ -19,16 +19,17 @@ module Conduit
19
19
 
20
20
  module ClassMethods
21
21
 
22
- # Configure AWS::S3 if we have explicit config
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.has_key?(key) }
30
- AWS.config(:access_key_id => config[:aws_access_key_id],
31
- :secret_access_key => config[:aws_access_secret])
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
 
@@ -0,0 +1,4 @@
1
+ module Conduit
2
+ class TimeOut < StandardError
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module Conduit
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -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 200 status' do
47
- subject.perform.status.should == 200
46
+ it 'returns a response wrapper' do
47
+ subject.perform.should be_a_kind_of(Conduit::Response)
48
48
  end
49
49
 
50
- it 'returns a response body' do
51
- a = subject.perform.body.gsub(/\s+/, '')
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
@@ -4,7 +4,7 @@ module Helper
4
4
  {
5
5
  foo: 'value for foo',
6
6
  bar: 'value for bar',
7
- baz: 'value for baz',
7
+ baz: 'value for baz'
8
8
  }
9
9
  end
10
10
 
@@ -12,4 +12,4 @@ module Helper
12
12
  IO.read(File.join(File.dirname(__FILE__), name))
13
13
  end
14
14
 
15
- end
15
+ end
@@ -6,5 +6,10 @@ module Conduit::Driver::MyDriver
6
6
  required_attributes :foo, :bar, :baz
7
7
  optional_attributes :buz
8
8
 
9
+ private
10
+
11
+ def response_class
12
+ Conduit::Driver::MyDriver::Response
13
+ end
9
14
  end
10
15
  end
@@ -8,15 +8,15 @@ module Conduit::Driver::MyDriver
8
8
  end
9
9
 
10
10
  attribute :foo do
11
- "foo"
11
+ 'foo'
12
12
  end
13
13
 
14
14
  attribute :bar do
15
- "bar"
15
+ 'bar'
16
16
  end
17
17
 
18
18
  attribute :baz do
19
- "baz"
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.1
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-06-17 00:00:00.000000000 Z
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