stockboy 0.5.7 → 0.6.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/CHANGELOG.md +5 -0
- data/lib/stockboy/candidate_record.rb +16 -3
- data/lib/stockboy/providers/http.rb +33 -4
- data/lib/stockboy/version.rb +1 -1
- data/spec/stockboy/providers/http_spec.rb +18 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 025d746c97ca5ded5e263969f5faf3fa215dbaa6
|
4
|
+
data.tar.gz: febec727068f490b15846a93912d625f91ad048b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fa25cb4d7326baaa6de53c0b4160663a5f0523e5dc7a6132904e6f11bac32d72b69d7328c7a563129b17b37440756d704be45d5f7cfe3b57673f32bdb25e1cd
|
7
|
+
data.tar.gz: 9dd0a0bd18b9b5b198f8aff1a90e649a3ffc8acb4b62b7aa4fd305908de6e8a3826f439ea4894a82f195692e14578513c84ced4942a5818b57eade3afd1f1687
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.6.0 / 2014-02-06
|
4
|
+
|
5
|
+
* [FEATURE] Support HTTP basic authentication (@markedmondson)
|
6
|
+
* [ENHANCEMENT] Accept any duck-typed hash-like input when building a record
|
7
|
+
|
3
8
|
## 0.5.7 / 2013-12-13
|
4
9
|
|
5
10
|
* [BUGFIX] Fix IMAP search with missing search defaults
|
@@ -17,7 +17,7 @@ module Stockboy
|
|
17
17
|
#
|
18
18
|
def initialize(attrs, map)
|
19
19
|
@map = map
|
20
|
-
@table =
|
20
|
+
@table = reuse_frozen_hash_keys(attrs, map)
|
21
21
|
@tr_table = Hash.new
|
22
22
|
freeze
|
23
23
|
end
|
@@ -114,11 +114,24 @@ module Stockboy
|
|
114
114
|
@tr_table[col.to] = translated.public_send(col.to)
|
115
115
|
end
|
116
116
|
|
117
|
+
# Clean output values that are a subclass of a standard type
|
118
|
+
#
|
117
119
|
def sanitize(value)
|
118
|
-
|
120
|
+
case value
|
121
|
+
when String # e.g. Nori::StringWithAttributes
|
122
|
+
value.to_s
|
123
|
+
else
|
124
|
+
value
|
125
|
+
end
|
119
126
|
end
|
120
127
|
|
121
|
-
|
128
|
+
# Optimization to reuse the same hash key string instances
|
129
|
+
#
|
130
|
+
# The need for this is fixed for CSV in: https://bugs.ruby-lang.org/issues/9143
|
131
|
+
# (ruby >= 2.1) and can be managed by applying str.freeze in other readers.
|
132
|
+
#
|
133
|
+
def reuse_frozen_hash_keys(attrs, map)
|
134
|
+
return attrs unless attrs.is_a? Hash
|
122
135
|
attrs.reduce(Hash.new) do |new_hash, (field, value)|
|
123
136
|
key = map.attribute_from(field).from
|
124
137
|
new_hash[key] = value
|
@@ -42,9 +42,27 @@ module Stockboy::Providers
|
|
42
42
|
#
|
43
43
|
dsl_attr :method, attr_writer: false
|
44
44
|
|
45
|
+
# User name for basic auth connection credentials
|
46
|
+
#
|
47
|
+
# @!attribute [rw] username
|
48
|
+
# @return [String]
|
49
|
+
# @example
|
50
|
+
# username "arthur"
|
51
|
+
#
|
52
|
+
dsl_attr :username
|
53
|
+
|
54
|
+
# Password for basic auth connection credentials
|
55
|
+
#
|
56
|
+
# @!attribute [rw] password
|
57
|
+
# @return [String]
|
58
|
+
# @example
|
59
|
+
# password "424242"
|
60
|
+
#
|
61
|
+
dsl_attr :password
|
62
|
+
|
45
63
|
def uri
|
46
64
|
return nil if @uri.nil? || @uri.empty?
|
47
|
-
URI(@uri).tap { |u| u.query = URI.encode_www_form(@query) }
|
65
|
+
URI(@uri).tap { |u| u.query = URI.encode_www_form(@query) if @query }
|
48
66
|
end
|
49
67
|
|
50
68
|
def uri=(uri)
|
@@ -84,15 +102,25 @@ module Stockboy::Providers
|
|
84
102
|
@uri = uri
|
85
103
|
end
|
86
104
|
|
105
|
+
def username=(username)
|
106
|
+
@username = username
|
107
|
+
end
|
108
|
+
|
109
|
+
def password=(password)
|
110
|
+
@password = password
|
111
|
+
end
|
112
|
+
|
87
113
|
# @!endgroup
|
88
114
|
|
89
115
|
# Initialize an HTTP provider
|
90
116
|
#
|
91
117
|
def initialize(opts={}, &block)
|
92
118
|
super(opts, &block)
|
93
|
-
self.uri
|
94
|
-
self.method
|
95
|
-
self.query
|
119
|
+
self.uri = opts[:uri]
|
120
|
+
self.method = opts[:method] || :get
|
121
|
+
self.query = opts[:query] || Hash.new
|
122
|
+
self.username = opts[:username]
|
123
|
+
self.password = opts[:password]
|
96
124
|
DSL.new(self).instance_eval(&block) if block_given?
|
97
125
|
end
|
98
126
|
|
@@ -111,6 +139,7 @@ module Stockboy::Providers
|
|
111
139
|
def fetch_data
|
112
140
|
request = HTTPI::Request.new
|
113
141
|
request.url = uri
|
142
|
+
request.auth.basic(username, password) if username && password
|
114
143
|
response = HTTPI.send(method, request)
|
115
144
|
if response.error?
|
116
145
|
errors.add :response, "HTTP respone error: #{response.code}"
|
data/lib/stockboy/version.rb
CHANGED
@@ -33,6 +33,14 @@ module Stockboy
|
|
33
33
|
provider.method.should == :post
|
34
34
|
end
|
35
35
|
|
36
|
+
it "should assign basic auth parameters" do
|
37
|
+
provider.username = "username"
|
38
|
+
provider.password = "password"
|
39
|
+
|
40
|
+
provider.username.should == "username"
|
41
|
+
provider.password.should == "password"
|
42
|
+
end
|
43
|
+
|
36
44
|
describe ".new" do
|
37
45
|
its(:errors) { should be_empty }
|
38
46
|
|
@@ -78,6 +86,16 @@ module Stockboy
|
|
78
86
|
|
79
87
|
provider.data.should == '{"success":true}'
|
80
88
|
end
|
89
|
+
|
90
|
+
it "should setup basic auth if a username and password are supplied" do
|
91
|
+
provider.username = "username"
|
92
|
+
provider.password = "password"
|
93
|
+
|
94
|
+
allow(HTTPI).to receive(:request) { response }
|
95
|
+
expect_any_instance_of(HTTPI::Auth::Config).to receive(:basic).with("username", "password")
|
96
|
+
|
97
|
+
provider.data.should == '{"success":true}'
|
98
|
+
end
|
81
99
|
end
|
82
100
|
|
83
101
|
describe "#client" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stockboy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Vit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -249,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
249
249
|
version: '0'
|
250
250
|
requirements: []
|
251
251
|
rubyforge_project: stockboy
|
252
|
-
rubygems_version: 2.
|
252
|
+
rubygems_version: 2.2.1
|
253
253
|
signing_key:
|
254
254
|
specification_version: 4
|
255
255
|
summary: Multi-source data normalization library
|