stockboy 0.10.0 → 0.11.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.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.0 / 2015-04-13
4
+
5
+ * [FEATURE] Options to set POST body and headers
6
+
3
7
  ## 0.10.0 / 2015-01-23
4
8
 
5
9
  * [FEATURE] Option to ignore unwanted attributes from output
data/lib/stockboy/dsl.rb CHANGED
@@ -36,10 +36,13 @@ module Stockboy
36
36
  class_eval <<-___, __FILE__, __LINE__
37
37
  class DSL < Stockboy::ConfiguratorBlock
38
38
  def #{attr}(*arg)
39
- if arg.empty?
39
+ case arg.size
40
+ when 0
40
41
  @instance.#{attr}
41
- else
42
+ when 1
42
43
  @instance.#{attr} = arg.first
44
+ else
45
+ @instance.#{attr} = *arg
43
46
  end
44
47
  end
45
48
  def #{attr}=(arg)
@@ -42,6 +42,24 @@ module Stockboy::Providers
42
42
  #
43
43
  dsl_attr :method, attr_writer: false
44
44
 
45
+ # HTTP request headers
46
+ #
47
+ # @!attribute [rw] headers
48
+ # @return [String]
49
+ # @example
50
+ # headers content_type: "text/json"
51
+ #
52
+ dsl_attr :headers
53
+
54
+ # HTTP request body
55
+ #
56
+ # @!attribute [rw] body
57
+ # @return [String]
58
+ # @example
59
+ # body "<getData></getData>"
60
+ #
61
+ dsl_attr :body
62
+
45
63
  # User name for basic auth connection credentials
46
64
  #
47
65
  # @!attribute [rw] username
@@ -119,6 +137,8 @@ module Stockboy::Providers
119
137
  self.uri = opts[:uri]
120
138
  self.method = opts[:method] || :get
121
139
  self.query = opts[:query] || Hash.new
140
+ self.headers = opts[:headers] || Hash.new
141
+ self.body = opts[:body]
122
142
  self.username = opts[:username]
123
143
  self.password = opts[:password]
124
144
  DSL.new(self).instance_eval(&block) if block_given?
@@ -128,6 +148,8 @@ module Stockboy::Providers
128
148
  orig_logger, HTTPI.logger = HTTPI.logger, logger
129
149
  req = HTTPI::Request.new.tap { |c| c.url = uri }
130
150
  req.auth.basic(username, password) if username && password
151
+ req.headers = headers
152
+ req.body = body
131
153
  block_given? ? yield(req) : req
132
154
  ensure
133
155
  HTTPI.logger = orig_logger
@@ -138,6 +160,7 @@ module Stockboy::Providers
138
160
  def validate
139
161
  errors << "uri must be specified" unless uri
140
162
  errors << "method (:get, :post) must be specified" unless method
163
+ errors << "body must be specified" if [:post, :put, :patch].include?(method)
141
164
  errors.empty?
142
165
  end
143
166
 
@@ -1,3 +1,3 @@
1
1
  module Stockboy
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'stockboy/dsl'
3
+
4
+ module Stockboy
5
+ describe DSL do
6
+
7
+ class Dummy
8
+ extend Stockboy::DSL
9
+ dsl_attr :flag, attr_writer: false
10
+ dsl_attr :options
11
+ dsl_attr :setter_only, attr_reader: false
12
+ dsl_attr :undefined, attr_accessor: false
13
+ end
14
+
15
+ let(:instance) { Dummy.new }
16
+ subject(:dsl) { Dummy::DSL.new(instance) }
17
+
18
+ it "rejects assignment syntax when attr_writer is disabled" do
19
+ expect { dsl.flag = :disable }.to raise_error NoMethodError
20
+ end
21
+
22
+ it "passes through to instance with no arguments" do
23
+ expect(instance).to receive(:flag).with no_args
24
+ dsl.flag
25
+ end
26
+
27
+ it "passes a value to writer with one argument" do
28
+ expect(instance).to receive(:flag=).with :disable
29
+ dsl.flag :disable
30
+ end
31
+
32
+ it "passes an array of values to writer with two arguments" do
33
+ expect(instance).to receive(:options=).with [:one, :two]
34
+ dsl.options :one, :two
35
+ end
36
+
37
+ it "passes through to writer with an array argument" do
38
+ expect(instance).to receive(:options=).with [:one, :two]
39
+ dsl.options [:one, :two]
40
+ end
41
+
42
+ it "requires assignment syntax when attr_reader is disabled" do
43
+ expect { dsl.setter_only }.to raise_error NoMethodError
44
+ end
45
+
46
+ it "rejects both reader and writer syntax when attr_accessor is disabled" do
47
+ expect { dsl.undefined }.to raise_error NoMethodError
48
+ expect { dsl.undefined = :one }.to raise_error NoMethodError
49
+ end
50
+
51
+ end
52
+ end
@@ -33,6 +33,18 @@ module Stockboy
33
33
  provider.method.should == :post
34
34
  end
35
35
 
36
+ it "should assign parameters from :headers" do
37
+ provider.headers = {"Content-Type" => "test/xml"}
38
+
39
+ provider.headers["Content-Type"].should == "test/xml"
40
+ end
41
+
42
+ it "should assign parameters from :body" do
43
+ provider.body = "<somexml></somexml>"
44
+
45
+ provider.body.should == "<somexml></somexml>"
46
+ end
47
+
36
48
  it "should assign basic auth parameters" do
37
49
  provider.username = "username"
38
50
  provider.password = "password"
@@ -70,6 +82,13 @@ module Stockboy
70
82
  provider.should_not be_valid
71
83
  provider.errors.first.should match /uri/
72
84
  end
85
+
86
+ it "should require a body for post" do
87
+ provider.uri = "http://example.com"
88
+ provider.method = :post
89
+ provider.should_not be_valid
90
+ provider.errors.first.should match /body/
91
+ end
73
92
  end
74
93
 
75
94
  describe "#client" do
metadata CHANGED
@@ -1,125 +1,142 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stockboy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Andrew Vit
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-01-23 00:00:00.000000000 Z
12
+ date: 2015-04-13 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - ">="
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - ">="
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rspec
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - ">="
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - ">="
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rspec-its
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - ">="
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - ">="
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: roo
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - ">="
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: 1.12.2
62
70
  type: :runtime
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - ">="
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: 1.12.2
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: savon
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
- - - ">="
83
+ - - ! '>='
74
84
  - !ruby/object:Gem::Version
75
85
  version: 2.3.0
76
86
  type: :runtime
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
- - - ">="
91
+ - - ! '>='
81
92
  - !ruby/object:Gem::Version
82
93
  version: 2.3.0
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: httpi
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
- - - ">="
99
+ - - ! '>='
88
100
  - !ruby/object:Gem::Version
89
101
  version: '0'
90
102
  type: :runtime
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
- - - ">="
107
+ - - ! '>='
95
108
  - !ruby/object:Gem::Version
96
109
  version: '0'
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: mail
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
- - - ">="
115
+ - - ! '>='
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
- - - ">="
123
+ - - ! '>='
109
124
  - !ruby/object:Gem::Version
110
125
  version: '0'
111
126
  - !ruby/object:Gem::Dependency
112
127
  name: activesupport
113
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
114
130
  requirements:
115
- - - ">="
131
+ - - ! '>='
116
132
  - !ruby/object:Gem::Version
117
133
  version: '3.0'
118
134
  type: :runtime
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
121
138
  requirements:
122
- - - ">="
139
+ - - ! '>='
123
140
  - !ruby/object:Gem::Version
124
141
  version: '3.0'
125
142
  description: Supports importing data over various transports with key-value remapping
@@ -130,10 +147,10 @@ executables: []
130
147
  extensions: []
131
148
  extra_rdoc_files: []
132
149
  files:
133
- - ".gitignore"
134
- - ".rspec"
135
- - ".travis.yml"
136
- - ".yardopts"
150
+ - .gitignore
151
+ - .rspec
152
+ - .travis.yml
153
+ - .yardopts
137
154
  - CHANGELOG.md
138
155
  - Gemfile
139
156
  - Guardfile
@@ -209,6 +226,7 @@ files:
209
226
  - spec/stockboy/candidate_record_spec.rb
210
227
  - spec/stockboy/configuration_spec.rb
211
228
  - spec/stockboy/configurator_spec.rb
229
+ - spec/stockboy/dsl_spec.rb
212
230
  - spec/stockboy/filter_chain_spec.rb
213
231
  - spec/stockboy/filter_spec.rb
214
232
  - spec/stockboy/filters/missing_email_spec.rb
@@ -252,26 +270,27 @@ files:
252
270
  homepage: https://github.com/avit/stockboy
253
271
  licenses:
254
272
  - MIT
255
- metadata: {}
256
273
  post_install_message:
257
274
  rdoc_options: []
258
275
  require_paths:
259
276
  - lib
260
277
  required_ruby_version: !ruby/object:Gem::Requirement
278
+ none: false
261
279
  requirements:
262
- - - ">="
280
+ - - ! '>='
263
281
  - !ruby/object:Gem::Version
264
282
  version: '0'
265
283
  required_rubygems_version: !ruby/object:Gem::Requirement
284
+ none: false
266
285
  requirements:
267
- - - ">="
286
+ - - ! '>='
268
287
  - !ruby/object:Gem::Version
269
288
  version: '0'
270
289
  requirements: []
271
290
  rubyforge_project: stockboy
272
- rubygems_version: 2.2.2
291
+ rubygems_version: 1.8.23.2
273
292
  signing_key:
274
- specification_version: 4
293
+ specification_version: 3
275
294
  summary: Multi-source data normalization library
276
295
  test_files:
277
296
  - spec/fixtures/.gitkeep
@@ -292,6 +311,7 @@ test_files:
292
311
  - spec/stockboy/candidate_record_spec.rb
293
312
  - spec/stockboy/configuration_spec.rb
294
313
  - spec/stockboy/configurator_spec.rb
314
+ - spec/stockboy/dsl_spec.rb
295
315
  - spec/stockboy/filter_chain_spec.rb
296
316
  - spec/stockboy/filter_spec.rb
297
317
  - spec/stockboy/filters/missing_email_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: f39685f84983ede11ee77ffe5ab39982e37ddac7
4
- data.tar.gz: c16642a9c384a71c72def32658d8e4764ab46b14
5
- SHA512:
6
- metadata.gz: 3d7f4377f7973b9e88d91ea807c12987385e594ca9f55b1594dbdc652ad8aea3cf674e431394ed840d60b11454404975cf4d9dc77b3a8a3409a760b1668316ef
7
- data.tar.gz: 7dd65ee93fbf9a6df91f052b5505fe13d2b4d1ae2901a612a7ccd87589f1f5662cf8154f5d7d397a4d59779c23cd4ddf4abbee5c70f78a0204130c9cd329e9f5