conduit 1.1.3 → 1.4.0

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
- SHA1:
3
- metadata.gz: 13455d3175a2f4f12d437b0d5b98281100c34aea
4
- data.tar.gz: 67ccea510d9ab5d79dfa5f53aea8d8eaf43d4cc2
2
+ SHA256:
3
+ metadata.gz: '076538899ab77d0cedd2ce54f2ed7ebc32f2e8115c4fe4ab989d514eb95d898e'
4
+ data.tar.gz: 61f027e5162aa9795173276bf6fe8b09c8dac1227618f5926a1805920628ce1d
5
5
  SHA512:
6
- metadata.gz: 5704fbbd6096ca6d3dfed6b6487822f0cb1029ab4eb56f71e75adb75760d3c1bd0e4d91449b4cd5472e2cc3ae0288b83821028a392f6f416558fd3b1d4d2d423
7
- data.tar.gz: c42597f27b9d51696fbfc79fa106fc868eee60215909f5c27de28be273916f9f7f86b202c0597998efef138847c0756a1bfffbc1954cac8af52d2dde54384df3
6
+ metadata.gz: 03bd45482b484b23efb0e36b0c146ade9cf14bbf7664a85e641c2e3a6b7621b5f5cf11ec885f5bf94f176e2ac01002108859db277e1ca2232d95df1db5e7da12
7
+ data.tar.gz: 6d9fb2f3d7a637484ed4e3e915d688ec95cb46172788a957982825cd60714ad0e3be7397d01cfca7d01c902165b4d31e9f0b07f9b6fcf940aecaab5d98beb85c
@@ -1,11 +1,14 @@
1
1
  module Conduit
2
2
  class ApiResponse
3
- attr_reader :body, :parser, :raw_response
3
+ attr_reader :body, :parser, :raw_response, :http_status
4
4
 
5
5
  def initialize(options = {})
6
6
  @raw_response = options[:raw_response]
7
7
  @body = options[:body] ||= @raw_response.body
8
8
  @parser = options[:parser]
9
+ @http_status = options[:http_status] ||= begin
10
+ @raw_response.try(:http_status) || @raw_response.try(:status)
11
+ end
9
12
  end
10
13
  end
11
14
  end
data/lib/conduit/cli.rb CHANGED
@@ -113,14 +113,11 @@ module Conduit
113
113
  # add gemspec dependencies
114
114
  str = " # Dependencies\n"\
115
115
  " #\n"\
116
- " spec.add_dependency \"conduit\", \"~> 1.0.4\"\n"\
116
+ " spec.add_dependency \"conduit\", \"~> 1.0.6\"\n"\
117
117
  " # xml parser\n"\
118
- " spec.add_dependency \"nokogiri\"\n"\
119
- " # to get string inflectors\n"\
120
- " spec.add_dependency \"activesupport\"\n\n"\
118
+ " spec.add_dependency \"nokogiri\"\n\n"\
121
119
  " # Development Dependencies\n"\
122
120
  " #\n"\
123
- " spec.add_development_dependency \"shoulda-matchers\"\n"\
124
121
  " # to compare xml files in tests\n"\
125
122
  " spec.add_development_dependency \"equivalent-xml\"\n"\
126
123
  " spec.add_development_dependency \"rspec-its\"\n"\
@@ -77,7 +77,7 @@ module Conduit
77
77
  module InstanceMethods
78
78
  extend Forwardable
79
79
 
80
- def initialize(**options)
80
+ def initialize(options)
81
81
  @options = options
82
82
  validate!(options)
83
83
  end
@@ -129,15 +129,28 @@ module Conduit
129
129
 
130
130
  # Method called to make the actual request.
131
131
  #
132
- # Override to customize.
133
- #
134
132
  def perform_request
135
- response = request(body: view, method: :post)
133
+ response = request(request_options)
136
134
  parser_instance = parser_class.new(response.body)
137
-
138
135
  Conduit::ApiResponse.new(raw_response: response, parser: parser_instance)
139
136
  end
140
137
 
138
+ def request_options
139
+ { body: http_body, method: http_method, headers: http_headers }
140
+ end
141
+
142
+ def http_body
143
+ view
144
+ end
145
+
146
+ def http_method
147
+ :post
148
+ end
149
+
150
+ def http_headers
151
+ {}
152
+ end
153
+
141
154
  # Entry method. Calls either the mocker or the `perform_request`
142
155
  # method.
143
156
  #
@@ -164,12 +177,16 @@ module Conduit
164
177
  # an ArgumentError listing missing attributes.
165
178
  #
166
179
  def validate!(options)
167
- missing_keys = (requirements.to_a - options.keys)
168
- either_keys = requirements.select { |key| key.is_a?(Array) }
169
- missing_keys.reject! { |_key| either_keys.any? { |either| (either & options.keys).present? } }
180
+ missing_keys = requirements.reject do |required_attribute|
181
+ if required_attribute.is_a?(Array)
182
+ (required_attribute & options.keys).present?
183
+ else
184
+ options.keys.include?(required_attribute)
185
+ end
186
+ end
187
+
170
188
  if missing_keys.any?
171
- raise ArgumentError,
172
- "Missing keys: #{missing_keys.join(', ')}"
189
+ raise ArgumentError, "Missing keys: #{missing_keys}"
173
190
  end
174
191
  end
175
192
 
@@ -205,9 +222,8 @@ module Conduit
205
222
  # In ruby 2.0.0 we can't do `const_defined? MyDriver::Decorators::FooDecorator`
206
223
  # so we have to check each module one by one.
207
224
  if Conduit.const_defined?(driver_name.classify) &&
208
- Conduit.const_get(driver_name.classify).const_defined?("Decorators") &&
209
- Conduit.const_get("#{driver_name.classify}::Decorators").const_defined?("#{action_name}Decorator")
210
-
225
+ Conduit.const_get(driver_name.classify).const_defined?("Decorators") &&
226
+ Conduit.const_get("#{driver_name.classify}::Decorators").const_defined?("#{action_name}Decorator")
211
227
  Conduit.const_get("#{driver_name.classify}::Decorators::#{action_name}Decorator")
212
228
  else
213
229
  Conduit::Core::Decorator
@@ -217,7 +233,7 @@ module Conduit
217
233
  # Indicates whether the request should be mocked or not.
218
234
  #
219
235
  def mock_mode?
220
- @options.key?(:mock_status) && (!@options[:mock_status].nil? && !@options[:mock_status].empty?)
236
+ @options.key?(:mock_status) && @options[:mock_status].present?
221
237
  end
222
238
  end
223
239
  end
@@ -40,7 +40,7 @@ module Conduit
40
40
  Excon.stubs.clear
41
41
  end
42
42
 
43
- # Wrapps the block inside a mocking state.
43
+ # Wraps the block inside a mocking state.
44
44
  #
45
45
  def with_mocking
46
46
  mock and yield.tap { unmock }
@@ -77,7 +77,7 @@ module Conduit
77
77
 
78
78
  # Allowed statuses.
79
79
  def response_statuses
80
- %i(success failure error)
80
+ %i[success failure error]
81
81
  end
82
82
 
83
83
  # Mocked error response.
data/lib/conduit/error.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Conduit
2
2
  class Error < OpenStruct
3
- def initialize(message:, **attributes)
4
- super(message: message, **attributes)
3
+ def initialize(message:, code: nil)
4
+ super(message: message, code: code)
5
5
  end
6
6
 
7
7
  def to_s
@@ -2,10 +2,7 @@
2
2
  # The job of this class is to provide storage
3
3
  # functionality for conduit.
4
4
  #
5
- # TODO: Support multiple storage providers
6
- #
7
-
8
- require "aws-sdk"
5
+ require "aws-sdk-s3"
9
6
 
10
7
  module Conduit
11
8
  module Storage
@@ -18,29 +15,28 @@ module Conduit
18
15
  end
19
16
 
20
17
  module ClassMethods
21
- # Configure AWS::S3 with credentials if provided, else, assume
18
+ # Configure Aws::S3 with credentials if provided, else, assume
22
19
  # IAM will provide them.
23
20
  #
24
21
  def configure
25
- if [:aws_access_key_id, :aws_access_secret].all? { |key| config.key?(key) }
26
- AWS.config(
27
- access_key_id: config[:aws_access_key_id],
28
- secret_access_key: config[:aws_access_secret]
29
- )
22
+ if %i[aws_access_key_id aws_access_secret].all? { |key| config.key?(key) }
23
+ credentials = ::Aws::Credentials.new(config[:aws_access_key_id],
24
+ config[:aws_access_secret])
25
+ ::Aws.config.update(credentials: credentials)
30
26
  else
31
- AWS.config
27
+ ::Aws.config
32
28
  end
33
29
  end
34
30
 
35
- # Primary connection object to AWS::S3
31
+ # Primary connection object to Aws::S3
36
32
  #
37
33
  # Configurable in:
38
34
  # config/initializers/conduit.rb
39
35
  # TODO: Update how conduit gets
40
36
  # the credentials for s3
41
37
  #
42
- def connection
43
- @connection ||= AWS::S3.new
38
+ def s3
39
+ @s3 ||= ::Aws::S3::Resource.new
44
40
  end
45
41
 
46
42
  # Bucket we want to work with
@@ -50,40 +46,46 @@ module Conduit
50
46
  #
51
47
  def bucket
52
48
  @bucket ||= begin
53
- bucket = config[:bucket]
54
- connection.buckets.create(bucket) unless connection.buckets[bucket].exists?
55
- connection.buckets[bucket]
49
+ bucket_name = config[:bucket]
50
+ bucket = s3.bucket(bucket_name)
51
+
52
+ if bucket.exists?
53
+ bucket
54
+ else
55
+ s3.buckets.create(bucket)
56
+ s3.bucket(bucket)
57
+ end
56
58
  end
57
59
  end
58
60
 
59
- # Write a file to AWS::S3
61
+ # Write a file to Aws::S3
60
62
  #
61
63
  # e.g.
62
64
  # => Conduit::Storage.write('/path/to/file', 'foo')
63
65
  #
64
66
  def write(key, content)
65
- bucket.objects[key].write(content)
67
+ bucket.object(key).put(body: content)
66
68
  end
67
69
 
68
- # Read a file from AWS::S3
70
+ # Read a file from Aws::S3
69
71
  #
70
72
  # e.g.
71
73
  # => Conduit::Storage.read('/path/to/file')
72
74
  #
73
75
  def read(key)
74
- bucket.objects[key].read
75
- rescue AWS::S3::Errors::NoSuchKey
76
+ bucket.object(key).get.body.read
77
+ rescue ::Aws::S3::Errors::NoSuchKey
76
78
  nil
77
79
  end
78
80
 
79
- # Delete a file from AWS::S3
81
+ # Delete a file from Aws::S3
80
82
  #
81
83
  # e.g.
82
84
  # => Conduit::Storage.delete('/path/to/file')
83
85
  #
84
86
  def delete(key)
85
- bucket.objects[key].delete
86
- rescue AWS::S3::Errors::NoSuchKey
87
+ bucket.object(key).delete
88
+ rescue ::Aws::S3::Errors::NoSuchKey
87
89
  nil
88
90
  end
89
91
  end
@@ -1,3 +1,3 @@
1
1
  module Conduit
2
- VERSION = "1.1.3".freeze
2
+ VERSION = "1.4.0".freeze
3
3
  end
@@ -16,19 +16,20 @@ shared_examples_for Conduit::Core::Action do
16
16
 
17
17
  describe ".requirements" do
18
18
  it "returns an array of required attributes" do
19
- subject.class.requirements.should == [:foo, :bar, :baz, [:either, :or]].to_set
19
+ subject.class.requirements.should == [:foo, :bar, :baz, %i[either or]].to_set
20
20
  end
21
21
  end
22
22
 
23
23
  describe ".attributes" do
24
24
  it "returns an array of known attributes" do
25
- subject.class.requirements.should == [:foo, :bar, :baz, [:either, :or]].to_set
25
+ subject.class.requirements.should == [:foo, :bar, :baz, %i[either or]].to_set
26
26
  end
27
27
  end
28
28
  end
29
29
 
30
30
  context "action has an array in its required_attibutes field" do
31
31
  let(:attrs) { request_attributes }
32
+
32
33
  it "raises an error if missing both of the keys" do
33
34
  attrs.delete(:either)
34
35
  attrs.delete(:or)
@@ -135,6 +136,10 @@ shared_examples_for Conduit::Core::Action do
135
136
  it "should return the raw_content" do
136
137
  subject.perform.body.should_not be_nil
137
138
  end
139
+
140
+ it "returns http_status" do
141
+ subject.perform.http_status.should eql 200
142
+ end
138
143
  end
139
144
  end
140
145
  end
@@ -4,7 +4,7 @@ shared_examples_for Conduit::Core::Driver do
4
4
  context "without an instance" do
5
5
  describe ".credentials" do
6
6
  it "returns an array of required credentials" do
7
- subject.credentials.should == [:username, :password].to_set
7
+ subject.credentials.should == %i[username password].to_set
8
8
  end
9
9
  end
10
10
 
@@ -16,7 +16,7 @@ shared_examples_for Conduit::Core::Driver do
16
16
 
17
17
  describe ".permitted_attributes" do
18
18
  it "returns the union of required and optional attributes" do
19
- subject.permitted_attributes.should == [:subdomain, :mock].to_set
19
+ subject.permitted_attributes.should == %i[subdomain mock].to_set
20
20
  end
21
21
  end
22
22
 
@@ -15,7 +15,7 @@ shared_examples_for Conduit::Core::Parser do
15
15
  context "with an instance" do
16
16
  describe "#attributes" do
17
17
  it "returns an array of known attributes" do
18
- subject.attributes.should == [:foo, :bar, :baz].to_set
18
+ subject.attributes.should == %i[foo bar baz].to_set
19
19
  end
20
20
 
21
21
  it "defines a method for foo" do
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ Bundler.setup
5
5
 
6
6
  require "rspec"
7
7
  require "rspec/its"
8
- require "shoulda/matchers"
8
+ require "pry"
9
9
  require "conduit"
10
10
 
11
11
  # Load all of the _spec.rb files
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+ require "aws-sdk-s3"
3
+
4
+ describe "Conduit::Storage::Aws" do
5
+ before do
6
+ stub_aws_responses
7
+
8
+ Conduit.configure do |config|
9
+ config.storage_config = { provider: :aws, bucket: "my-bucket" }
10
+ end
11
+ end
12
+
13
+ def stub_aws_responses
14
+ Aws.config = {
15
+ stub_responses: true,
16
+ s3: {
17
+ stub_responses: {
18
+ list_buckets: { buckets: [{ name: "my-bucket" }] },
19
+ get_object: { body: "data" }
20
+ }
21
+ }
22
+ }
23
+ end
24
+
25
+ describe "#write" do
26
+ it "writes an s3 object to the bucket" do
27
+ Conduit::Storage.write("foo.txt", "data").
28
+ should be_a(Aws::S3::Types::PutObjectOutput)
29
+ end
30
+ end
31
+
32
+ describe "#read" do
33
+ it "reads from an s3 object" do
34
+ Conduit::Storage.read("foo.txt").should eql("data")
35
+ end
36
+ end
37
+
38
+ describe "#delete" do
39
+ it "deletes an s3 object" do
40
+ Conduit::Storage.delete("foo.txt").
41
+ should be_a(Aws::S3::Types::DeleteObjectOutput)
42
+ end
43
+ end
44
+ end
@@ -2,7 +2,7 @@ module Conduit::Driver::MyDriver
2
2
  class Foo < Conduit::Core::Action
3
3
  remote_url "http://foo.com/api.xml"
4
4
 
5
- required_attributes :foo, :bar, :baz, [:either, :or]
5
+ required_attributes :foo, :bar, :baz, %i[either or]
6
6
  optional_attributes :buz
7
7
 
8
8
  private
@@ -1,4 +1,5 @@
1
1
  require "nokogiri"
2
+ require_relative "../actions/foo.rb"
2
3
 
3
4
  module Conduit::Driver::MyDriver
4
5
  class Foo::Parser < Conduit::Core::Parser
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conduit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.4.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: 2017-03-20 00:00:00.000000000 Z
11
+ date: 2020-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: aws-sdk-s3
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: aws-sdk-v1
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -80,76 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: bundler
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: shoulda-matchers
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: rspec-its
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: nokogiri
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: rspec
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
83
  description:
154
84
  email:
155
85
  - mike@codezombie.org
@@ -204,6 +134,7 @@ files:
204
134
  - spec/classes/core/request_mocker_spec.rb
205
135
  - spec/classes/util_spec.rb
206
136
  - spec/spec_helper.rb
137
+ - spec/storage/aws_spec.rb
207
138
  - spec/support/helper.rb
208
139
  - spec/support/my_driver/actions/foo.rb
209
140
  - spec/support/my_driver/driver.rb
@@ -236,29 +167,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
167
  - !ruby/object:Gem::Version
237
168
  version: '0'
238
169
  requirements: []
239
- rubyforge_project:
240
- rubygems_version: 2.5.1
170
+ rubygems_version: 3.1.2
241
171
  signing_key:
242
172
  specification_version: 4
243
173
  summary: Conduit is an interface for debit platforms.
244
174
  test_files:
245
- - spec/classes/core/action_spec.rb
175
+ - spec/spec_helper.rb
176
+ - spec/classes/core/request_mocker_spec.rb
246
177
  - spec/classes/core/driver_spec.rb
247
178
  - spec/classes/core/parser_spec.rb
248
- - spec/classes/core/request_mocker_spec.rb
179
+ - spec/classes/core/action_spec.rb
249
180
  - spec/classes/util_spec.rb
250
- - spec/spec_helper.rb
181
+ - spec/storage/aws_spec.rb
251
182
  - spec/support/helper.rb
252
- - spec/support/my_driver/actions/foo.rb
253
- - spec/support/my_driver/driver.rb
254
183
  - spec/support/my_driver/parsers/foo.rb
255
- - spec/support/my_driver/request_mockers/fixtures/foo/failure.xml.erb
256
- - spec/support/my_driver/request_mockers/fixtures/foo/success.xml.erb
184
+ - spec/support/my_driver/driver.rb
185
+ - spec/support/my_driver/actions/foo.rb
257
186
  - spec/support/my_driver/request_mockers/foo.rb
258
- - spec/support/my_driver/views/foo.erb
187
+ - spec/support/my_driver/request_mockers/fixtures/foo/success.xml.erb
188
+ - spec/support/my_driver/request_mockers/fixtures/foo/failure.xml.erb
259
189
  - spec/support/my_driver/views/layout.erb
260
- - spec/support/xml/failure_mock.xml
261
- - spec/support/xml/success_mock.xml
262
- - spec/support/xml/xml_modified_request.xml
190
+ - spec/support/my_driver/views/foo.erb
263
191
  - spec/support/xml/xml_request.xml
192
+ - spec/support/xml/xml_modified_request.xml
264
193
  - spec/support/xml/xml_response.xml
194
+ - spec/support/xml/success_mock.xml
195
+ - spec/support/xml/failure_mock.xml