http_streaming_client 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/lib/http_streaming_client/client.rb +12 -0
- data/lib/http_streaming_client/version.rb +1 -1
- data/spec/adobe_spec.rb +46 -5
- data/spec/client_spec.rb +28 -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: 1f099e670dbe8489354b9f9cf4e18e128f5d306c
|
4
|
+
data.tar.gz: 05bbb9d7f4fad342c7eb75e9f008cf0d344d3195
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5faa8a7b53b8847cb4001253d8d88d703f9a3e254086ce04edf710a42017c4b986e9c71245e93a3dda4e01c3bf04266e024e512360433d644d5376388addda84
|
7
|
+
data.tar.gz: 2cb8e74c582736974f100499c28e573e69049b9fe0f5bd63b26efe6d723ebcf8bbd85629cc0c97953412ef00917669193d4e14bf4aee4cd80fca14c83a259025
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
http_streaming_client 0.9.1 (04.30.2014)
|
2
|
+
========================================
|
3
|
+
* added support for dynamic HTTP header and client option generation via a duck-typed factory parameter
|
4
|
+
|
1
5
|
http_streaming_client 0.9.0 (04.28.2014)
|
2
6
|
========================================
|
3
7
|
* Tested and fixed for MRI ruby-2.0.0-p451 and JRuby jruby-1.7.12
|
@@ -124,6 +124,18 @@ module HttpStreamingClient
|
|
124
124
|
uri = URI.parse(uri)
|
125
125
|
end
|
126
126
|
|
127
|
+
options_factory = opts.delete(:options_factory)
|
128
|
+
if !options_factory.nil? then
|
129
|
+
if options_factory.respond_to? "get_options" then
|
130
|
+
logger.debug("Client::request:options_factory detected")
|
131
|
+
generated_options = options_factory.get_options
|
132
|
+
logger.debug("Client::request:options_factory:#{generated_options}")
|
133
|
+
opts.merge!(generated_options || {})
|
134
|
+
else
|
135
|
+
logger.warn("Client::request:options_factory detected, but does not respond to get_options(). Ignoring.")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
127
139
|
default_headers = {
|
128
140
|
"User-Agent" => opts["User-Agent"] || "HttpStreamingClient #{HttpStreamingClient::VERSION}",
|
129
141
|
"Accept" => "*/*",
|
data/spec/adobe_spec.rb
CHANGED
@@ -7,6 +7,13 @@ require 'timeout'
|
|
7
7
|
require 'http_streaming_client/credentials/adobe'
|
8
8
|
include HttpStreamingClient::Credentials::Adobe
|
9
9
|
|
10
|
+
class HttpStreamingClientOptions
|
11
|
+
def get_options
|
12
|
+
authorization = HttpStreamingClient::Oauth::Adobe.generate_authorization(TOKENAPIHOST, USERNAME, PASSWORD, CLIENTID, CLIENTSECRET)
|
13
|
+
{ :headers => {'Authorization' => "Bearer #{authorization}" } }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
10
17
|
describe HttpStreamingClient do
|
11
18
|
|
12
19
|
describe "adobe firehose streaming get test, GZIP compression" do
|
@@ -56,10 +63,44 @@ describe HttpStreamingClient do
|
|
56
63
|
|
57
64
|
end
|
58
65
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
describe "adobe firehose streaming get test, GZIP compressionu, authorization options factory" do
|
67
|
+
|
68
|
+
line_count = 0
|
69
|
+
|
70
|
+
it "should successfully retrieve decompressed JSON records from the firehose, authorization options factory" do
|
71
|
+
expect {
|
72
|
+
client = HttpStreamingClient::Client.new(compression: true)
|
73
|
+
begin
|
74
|
+
status = Timeout::timeout(TIMEOUT_SEC) {
|
75
|
+
response = client.get(STREAMURL, {:options_factory => HttpStreamingClientOptions.new}) { |line|
|
76
|
+
|
77
|
+
if line.nil? then
|
78
|
+
logger.debug "error:nil line received"
|
79
|
+
next
|
80
|
+
end
|
81
|
+
|
82
|
+
if line.size == 0 then
|
83
|
+
logger.debug "error:zero length line received"
|
84
|
+
next
|
85
|
+
end
|
86
|
+
|
87
|
+
line_count = line_count + 1
|
88
|
+
|
89
|
+
if line.eql? "\r\n" or line.eql? "\r\n\r\n" then
|
90
|
+
logger.debug "Server ping received"
|
91
|
+
else
|
92
|
+
logger.debug "#{JSON.parse(line).to_s}"
|
93
|
+
end
|
94
|
+
|
95
|
+
client.interrupt if line_count > NUM_JSON_RECORDS_TO_RECEIVE }
|
96
|
+
}
|
97
|
+
rescue Timeout::Error
|
98
|
+
logger.debug "Timeout occurred, #{TIMEOUT_SEC} seconds elapsed"
|
99
|
+
client.interrupt
|
100
|
+
end
|
101
|
+
}.to_not raise_error
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
64
105
|
|
65
106
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -103,4 +103,32 @@ describe HttpStreamingClient do
|
|
103
103
|
it { should_not be_nil}
|
104
104
|
end
|
105
105
|
|
106
|
+
describe "client instance get test with generated options" do
|
107
|
+
|
108
|
+
class OptionsFactory
|
109
|
+
def get_options
|
110
|
+
{ :headers => { :test_header => "TestHeader" } }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
client = HttpStreamingClient::Client.new(compression: false)
|
115
|
+
response = client.get "http://posttestserver.com/post.php", { :options_factory => OptionsFactory.new }
|
116
|
+
subject { response }
|
117
|
+
it { should_not be_nil}
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "client instance get test with generated options, failure test for bad factory object" do
|
121
|
+
|
122
|
+
class BadOptionsFactory
|
123
|
+
def get_options_incorrectly
|
124
|
+
{ :headers => { :test_header => "TestHeader" } }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
client = HttpStreamingClient::Client.new(compression: false)
|
129
|
+
response = client.get "http://posttestserver.com/post.php", { :options_factory => BadOptionsFactory.new }
|
130
|
+
subject { response }
|
131
|
+
it { should_not be_nil}
|
132
|
+
end
|
133
|
+
|
106
134
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_streaming_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Tompkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
requirements: []
|
160
160
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.2.2
|
162
162
|
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: a streaming HTTP protocol client
|