http_streaming_client 0.8.1

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.
@@ -0,0 +1,78 @@
1
+ ###########################################################################
2
+ ##
3
+ ## http_streaming_client
4
+ ##
5
+ ## Ruby HTTP client with support for HTTP 1.1 streaming, GZIP compressed
6
+ ## streams, and chunked transfer encoding. Includes extensible OAuth
7
+ ## support for the Adobe Analytics Firehose and Twitter Streaming APIs.
8
+ ##
9
+ ## David Tompkins -- 11/8/2013
10
+ ## tompkins@adobe_dot_com
11
+ ##
12
+ ###########################################################################
13
+ ##
14
+ ## Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
15
+ ##
16
+ ## Licensed under the Apache License, Version 2.0 (the "License");
17
+ ## you may not use this file except in compliance with the License.
18
+ ## You may obtain a copy of the License at
19
+ ##
20
+ ## http://www.apache.org/licenses/LICENSE-2.0
21
+ ##
22
+ ## Unless required by applicable law or agreed to in writing, software
23
+ ## distributed under the License is distributed on an "AS IS" BASIS,
24
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ ## See the License for the specific language governing permissions and
26
+ ## limitations under the License.
27
+ ##
28
+ ###########################################################################
29
+
30
+ require 'bundler/setup'
31
+ require 'openssl'
32
+ require 'base64'
33
+ require 'uri'
34
+ require 'json'
35
+
36
+ require 'http_streaming_client/oauth/base'
37
+
38
+ module HttpStreamingClient
39
+ module Oauth
40
+
41
+ class Adobe < Base
42
+
43
+ def self.generate_authorization(uri, username, password, clientId, clientSecret)
44
+
45
+ logger.debug "generate_authorization: #{uri}"
46
+
47
+ params = Hash.new
48
+ params['grant_type'] = "password"
49
+ params['username'] = username
50
+ params['password'] = password
51
+ params_string = sort_and_percent_encode(params)
52
+
53
+ logger.debug "params_string: #{params_string}"
54
+
55
+ basicAuth = "#{clientId}:#{clientSecret}"
56
+ basicAuth = Base64.encode64(basicAuth).chomp.gsub(/\n/, '')
57
+
58
+ logger.debug "base64 encoded authorization: #{basicAuth}"
59
+
60
+ uri = URI.parse(uri) if uri.is_a?(String)
61
+ url_string = "#{uri.scheme}://#{uri.host}#{uri.path}"
62
+
63
+ # POST to uri
64
+ response = HttpStreamingClient::Client.post(uri, params_string, {:headers => {'Authorization' => "Basic #{basicAuth}"}})
65
+ response_json = JSON.parse(response)
66
+
67
+ logger.debug "token API response: #{response_json}"
68
+
69
+ authorization = response_json['access_token']
70
+
71
+ logger.debug "authorization header: #{authorization}"
72
+
73
+ return authorization
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,70 @@
1
+ ###########################################################################
2
+ ##
3
+ ## http_streaming_client
4
+ ##
5
+ ## Ruby HTTP client with support for HTTP 1.1 streaming, GZIP compressed
6
+ ## streams, and chunked transfer encoding. Includes extensible OAuth
7
+ ## support for the Adobe Analytics Firehose and Twitter Streaming APIs.
8
+ ##
9
+ ## David Tompkins -- 11/8/2013
10
+ ## tompkins@adobe_dot_com
11
+ ##
12
+ ###########################################################################
13
+ ##
14
+ ## Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
15
+ ##
16
+ ## Licensed under the Apache License, Version 2.0 (the "License");
17
+ ## you may not use this file except in compliance with the License.
18
+ ## You may obtain a copy of the License at
19
+ ##
20
+ ## http://www.apache.org/licenses/LICENSE-2.0
21
+ ##
22
+ ## Unless required by applicable law or agreed to in writing, software
23
+ ## distributed under the License is distributed on an "AS IS" BASIS,
24
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ ## See the License for the specific language governing permissions and
26
+ ## limitations under the License.
27
+ ##
28
+ ###########################################################################
29
+
30
+ require 'bundler/setup'
31
+ require 'logger'
32
+ require 'uri'
33
+ require 'securerandom'
34
+
35
+ require "http_streaming_client/custom_logger"
36
+
37
+ module HttpStreamingClient
38
+
39
+ module Oauth
40
+
41
+ class Base
42
+
43
+ def self.logger
44
+ HttpStreamingClient.logger
45
+ end
46
+
47
+ protected
48
+
49
+ def self.percent_encode(s)
50
+ return URI.escape(s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]") ).gsub('*', '%2A').gsub('!', '%21')
51
+ end
52
+
53
+ # lexigraphically sort query params with percent encoding applied
54
+ def self.sort_and_percent_encode(params_hash)
55
+ pairs = []
56
+ params_hash.sort.each { |key, val| pairs.push("#{percent_encode(key)}=#{percent_encode(val.to_s)}") }
57
+ return pairs.join('&')
58
+ end
59
+
60
+ def self.generate_nonce
61
+ return SecureRandom.hex
62
+ end
63
+
64
+ def self.generate_timestamp
65
+ return Time.new.to_i.to_s
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,94 @@
1
+ ###########################################################################
2
+ ##
3
+ ## http_streaming_client
4
+ ##
5
+ ## Ruby HTTP client with support for HTTP 1.1 streaming, GZIP compressed
6
+ ## streams, and chunked transfer encoding. Includes extensible OAuth
7
+ ## support for the Adobe Analytics Firehose and Twitter Streaming APIs.
8
+ ##
9
+ ## David Tompkins -- 11/8/2013
10
+ ## tompkins@adobe_dot_com
11
+ ##
12
+ ###########################################################################
13
+ ##
14
+ ## Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
15
+ ##
16
+ ## Licensed under the Apache License, Version 2.0 (the "License");
17
+ ## you may not use this file except in compliance with the License.
18
+ ## You may obtain a copy of the License at
19
+ ##
20
+ ## http://www.apache.org/licenses/LICENSE-2.0
21
+ ##
22
+ ## Unless required by applicable law or agreed to in writing, software
23
+ ## distributed under the License is distributed on an "AS IS" BASIS,
24
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ ## See the License for the specific language governing permissions and
26
+ ## limitations under the License.
27
+ ##
28
+ ###########################################################################
29
+
30
+ require 'bundler/setup'
31
+ require 'openssl'
32
+ require 'base64'
33
+ require 'uri'
34
+
35
+ require 'http_streaming_client/oauth/base'
36
+
37
+ module HttpStreamingClient
38
+ module Oauth
39
+
40
+ class Twitter < Base
41
+
42
+ def self.generate_authorization(uri, method, params_hash, oauth_consumer_key, oauth_consumer_secret, oauth_token, oauth_token_secret, oauth_nonce = nil, oauth_timestamp = nil)
43
+
44
+ logger.debug "generate_twitter_authorization: #{uri}"
45
+
46
+ oauth_nonce = generate_nonce unless !oauth_nonce.nil?
47
+ oauth_timestamp = generate_timestamp unless !oauth_timestamp.nil?
48
+ oauth_signature_method = "HMAC-SHA1"
49
+ oauth_version = "1.0"
50
+
51
+ params = Hash.new
52
+ params['oauth_consumer_key'] = oauth_consumer_key
53
+ params['oauth_nonce'] = oauth_nonce
54
+ params['oauth_signature_method'] = oauth_signature_method
55
+ params['oauth_timestamp'] = oauth_timestamp
56
+ params['oauth_token'] = oauth_token
57
+ params['oauth_version'] = oauth_version
58
+ params.merge! params_hash unless params_hash.nil?
59
+ params_string = sort_and_percent_encode(params)
60
+
61
+ logger.debug "params_string: #{params_string}"
62
+
63
+ uri = URI.parse(uri) if uri.is_a?(String)
64
+ url_string = "#{uri.scheme}://#{uri.host}#{uri.path}"
65
+
66
+ signature_base = "#{method.upcase}&"
67
+ signature_base << "#{percent_encode(url_string)}&"
68
+ signature_base << "#{percent_encode(params_string)}"
69
+
70
+ logger.debug "signature base string: #{signature_base}"
71
+
72
+ digest = OpenSSL::Digest::Digest.new('sha1')
73
+ hmac = OpenSSL::HMAC.digest(digest, "#{percent_encode(oauth_consumer_secret)}&#{percent_encode(oauth_token_secret)}", signature_base)
74
+ oauth_signature = Base64.encode64(hmac).chomp.gsub(/\n/, '')
75
+
76
+ logger.debug "oauth signature: #{oauth_signature}"
77
+
78
+ authorization = 'OAuth '
79
+ authorization << "oauth_consumer_key=\"#{percent_encode(oauth_consumer_key)}\", "
80
+ authorization << "oauth_nonce=\"#{percent_encode(oauth_nonce)}\", "
81
+ authorization << "oauth_signature=\"#{percent_encode(oauth_signature)}\", "
82
+ authorization << "oauth_signature_method=\"#{percent_encode(oauth_signature_method)}\", "
83
+ authorization << "oauth_timestamp=\"#{percent_encode(oauth_timestamp)}\", "
84
+ authorization << "oauth_token=\"#{percent_encode(oauth_token)}\", "
85
+ authorization << "oauth_version=\"#{percent_encode(oauth_version)}\""
86
+
87
+ logger.debug "authorization header: #{authorization}"
88
+
89
+ return authorization
90
+ end
91
+
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,34 @@
1
+ ###########################################################################
2
+ ##
3
+ ## http_streaming_client
4
+ ##
5
+ ## Ruby HTTP client with support for HTTP 1.1 streaming, GZIP compressed
6
+ ## streams, and chunked transfer encoding. Includes extensible OAuth
7
+ ## support for the Adobe Analytics Firehose and Twitter Streaming APIs.
8
+ ##
9
+ ## David Tompkins -- 11/8/2013
10
+ ## tompkins@adobe_dot_com
11
+ ##
12
+ ###########################################################################
13
+ ##
14
+ ## Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
15
+ ##
16
+ ## Licensed under the Apache License, Version 2.0 (the "License");
17
+ ## you may not use this file except in compliance with the License.
18
+ ## You may obtain a copy of the License at
19
+ ##
20
+ ## http://www.apache.org/licenses/LICENSE-2.0
21
+ ##
22
+ ## Unless required by applicable law or agreed to in writing, software
23
+ ## distributed under the License is distributed on an "AS IS" BASIS,
24
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ ## See the License for the specific language governing permissions and
26
+ ## limitations under the License.
27
+ ##
28
+ ###########################################################################
29
+
30
+ module HttpStreamingClient
31
+ require 'http_streaming_client/oauth/base'
32
+ require 'http_streaming_client/oauth/twitter'
33
+ require 'http_streaming_client/oauth/adobe'
34
+ end
@@ -0,0 +1,38 @@
1
+ ###########################################################################
2
+ ##
3
+ ## http_streaming_client
4
+ ##
5
+ ## Ruby HTTP client with support for HTTP 1.1 streaming, GZIP compressed
6
+ ## streams, and chunked transfer encoding. Includes extensible OAuth
7
+ ## support for the Adobe Analytics Firehose and Twitter Streaming APIs.
8
+ ##
9
+ ## David Tompkins -- 11/8/2013
10
+ ## tompkins@adobe_dot_com
11
+ ##
12
+ ###########################################################################
13
+ ##
14
+ ## Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
15
+ ##
16
+ ## Licensed under the Apache License, Version 2.0 (the "License");
17
+ ## you may not use this file except in compliance with the License.
18
+ ## You may obtain a copy of the License at
19
+ ##
20
+ ## http://www.apache.org/licenses/LICENSE-2.0
21
+ ##
22
+ ## Unless required by applicable law or agreed to in writing, software
23
+ ## distributed under the License is distributed on an "AS IS" BASIS,
24
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ ## See the License for the specific language governing permissions and
26
+ ## limitations under the License.
27
+ ##
28
+ ###########################################################################
29
+
30
+ require 'http_streaming_client'
31
+
32
+ module HttpStreamingClient
33
+ class Railties < ::Rails::Railtie
34
+ initializer 'railties.configure_rails_initialization' do
35
+ HttpStreamingClient.logger = Rails.logger
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ ###########################################################################
2
+ ##
3
+ ## http_streaming_client
4
+ ##
5
+ ## Ruby HTTP client with support for HTTP 1.1 streaming, GZIP compressed
6
+ ## streams, and chunked transfer encoding. Includes extensible OAuth
7
+ ## support for the Adobe Analytics Firehose and Twitter Streaming APIs.
8
+ ##
9
+ ## David Tompkins -- 11/8/2013
10
+ ## tompkins@adobe_dot_com
11
+ ##
12
+ ###########################################################################
13
+ ##
14
+ ## Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
15
+ ##
16
+ ## Licensed under the Apache License, Version 2.0 (the "License");
17
+ ## you may not use this file except in compliance with the License.
18
+ ## You may obtain a copy of the License at
19
+ ##
20
+ ## http://www.apache.org/licenses/LICENSE-2.0
21
+ ##
22
+ ## Unless required by applicable law or agreed to in writing, software
23
+ ## distributed under the License is distributed on an "AS IS" BASIS,
24
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ ## See the License for the specific language governing permissions and
26
+ ## limitations under the License.
27
+ ##
28
+ ###########################################################################
29
+
30
+ module HttpStreamingClient
31
+ VERSION = "0.8.1"
32
+ end
@@ -0,0 +1,36 @@
1
+ ###########################################################################
2
+ ##
3
+ ## http_streaming_client
4
+ ##
5
+ ## Ruby HTTP client with support for HTTP 1.1 streaming, GZIP compressed
6
+ ## streams, and chunked transfer encoding. Includes extensible OAuth
7
+ ## support for the Adobe Analytics Firehose and Twitter Streaming APIs.
8
+ ##
9
+ ## David Tompkins -- 11/8/2013
10
+ ## tompkins@adobe_dot_com
11
+ ##
12
+ ###########################################################################
13
+ ##
14
+ ## Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
15
+ ##
16
+ ## Licensed under the Apache License, Version 2.0 (the "License");
17
+ ## you may not use this file except in compliance with the License.
18
+ ## You may obtain a copy of the License at
19
+ ##
20
+ ## http://www.apache.org/licenses/LICENSE-2.0
21
+ ##
22
+ ## Unless required by applicable law or agreed to in writing, software
23
+ ## distributed under the License is distributed on an "AS IS" BASIS,
24
+ ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ ## See the License for the specific language governing permissions and
26
+ ## limitations under the License.
27
+ ##
28
+ ###########################################################################
29
+
30
+ module HttpStreamingClient
31
+ require 'http_streaming_client/version'
32
+ require 'http_streaming_client/client'
33
+ require 'http_streaming_client/custom_logger'
34
+ require 'http_streaming_client/oauth'
35
+ require 'http_streaming_client/railtie' if defined?(Rails)
36
+ end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+ require 'zlib'
4
+ require 'uri'
5
+ require 'timeout'
6
+
7
+ require 'http_streaming_client/credentials/adobe'
8
+ include HttpStreamingClient::Credentials::Adobe
9
+
10
+ describe HttpStreamingClient do
11
+
12
+ describe "adobe firehose streaming get test, no compression" do
13
+
14
+ url = TOKENAPIHOST
15
+ authorization = HttpStreamingClient::Oauth::Adobe.generate_authorization(url, USERNAME, PASSWORD, CLIENTID, CLIENTSECRET)
16
+
17
+ subject { authorization }
18
+ it { should_not be_nil}
19
+ it { should be_instance_of(String) }
20
+
21
+ line_count = 0
22
+
23
+ it "should successfully retrieve JSON records from the firehose" do
24
+ expect {
25
+ client = HttpStreamingClient::Client.new(compression: false)
26
+ begin
27
+ status = Timeout::timeout(TIMEOUT_SEC) {
28
+ response = client.get(STREAMURL, {:headers => {'Authorization' => "Bearer #{authorization}" }}) { |line|
29
+
30
+ if line.nil? then
31
+ logger.debug "error:nil line received"
32
+ next
33
+ end
34
+
35
+ if line.size == 0 then
36
+ logger.debug "error:zero length line received"
37
+ next
38
+ end
39
+
40
+ line_count = line_count + 1
41
+
42
+ if line.eql? "\r\n" then
43
+ logger.debug "Server ping received"
44
+ else
45
+ logger.debug "#{JSON.parse(line).to_s}"
46
+ end
47
+
48
+ client.interrupt if line_count > NUM_JSON_RECORDS_TO_RECEIVE }
49
+ }
50
+ rescue Timeout::Error
51
+ logger.debug "Timeout occurred, #{TIMEOUT_SEC} seconds elapsed"
52
+ client.interrupt
53
+ end
54
+ }.to_not raise_error
55
+ end
56
+ end
57
+
58
+ describe "adobe firehose streaming get test, no compression, no block" do
59
+
60
+ url = TOKENAPIHOST
61
+ authorization = HttpStreamingClient::Oauth::Adobe.generate_authorization(url, USERNAME, PASSWORD, CLIENTID, CLIENTSECRET)
62
+
63
+ subject { authorization }
64
+ it { should_not be_nil}
65
+ it { should be_instance_of(String) }
66
+
67
+ line_count = 0
68
+
69
+ it "should successfully retrieve JSON records from the firehose" do
70
+ expect {
71
+ client = HttpStreamingClient::Client.new(compression: false)
72
+ begin
73
+ status = Timeout::timeout(TIMEOUT_SEC) {
74
+ response = client.get(STREAMURL, {:headers => {'Authorization' => "Bearer #{authorization}" }})
75
+ }
76
+ rescue Timeout::Error
77
+ logger.debug "Timeout occurred, #{TIMEOUT_SEC} seconds elapsed"
78
+ client.interrupt
79
+ end
80
+ }.to_not raise_error
81
+ end
82
+ end
83
+
84
+ describe "adobe firehose streaming get test, GZIP compression" do
85
+
86
+ url = TOKENAPIHOST
87
+ authorization = HttpStreamingClient::Oauth::Adobe.generate_authorization(url, USERNAME, PASSWORD, CLIENTID, CLIENTSECRET)
88
+
89
+ subject { authorization }
90
+ it { should_not be_nil}
91
+ it { should be_instance_of(String) }
92
+
93
+ line_count = 0
94
+
95
+ it "should successfully retrieve decompressed JSON records from the firehose" do
96
+ expect {
97
+ client = HttpStreamingClient::Client.new(compression: true)
98
+ begin
99
+ status = Timeout::timeout(TIMEOUT_SEC) {
100
+ response = client.get(STREAMURL, {:headers => {'Authorization' => "Bearer #{authorization}" }}) { |line|
101
+
102
+ if line.nil? then
103
+ logger.debug "error:nil line received"
104
+ next
105
+ end
106
+
107
+ if line.size == 0 then
108
+ logger.debug "error:zero length line received"
109
+ next
110
+ end
111
+
112
+ line_count = line_count + 1
113
+
114
+ if line.eql? "\r\n" then
115
+ logger.debug "Server ping received"
116
+ else
117
+ logger.debug "#{JSON.parse(line).to_s}"
118
+ end
119
+
120
+ client.interrupt if line_count > NUM_JSON_RECORDS_TO_RECEIVE }
121
+ }
122
+ rescue Timeout::Error
123
+ logger.debug "Timeout occurred, #{TIMEOUT_SEC} seconds elapsed"
124
+ client.interrupt
125
+ end
126
+ }.to_not raise_error
127
+ end
128
+
129
+ end
130
+
131
+ #describe "adobe firehose streaming get unauthorized failure" do
132
+ #it "should fail if authorization not provided" do
133
+ #expect { get STREAMURL }.to raise_error(HttpError)
134
+ #end
135
+ #end
136
+
137
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpStreamingClient do
4
+
5
+ describe "static get test" do
6
+ response = HttpStreamingClient::Client.get "http://www.google.com/"
7
+ logger.debug "response: #{response}"
8
+ subject { response }
9
+ it { should_not be_nil}
10
+ end
11
+
12
+ describe "client instance get test" do
13
+ client = HttpStreamingClient::Client.new
14
+ response = client.get "http://www.google.com/"
15
+ logger.debug "response: #{response}"
16
+ subject { response }
17
+ it { should_not be_nil}
18
+ end
19
+
20
+ describe "client instance get test with basic auth in URL" do
21
+ client = HttpStreamingClient::Client.new
22
+ response = client.get "http://a:b@www.google.com/"
23
+ logger.debug "response: #{response}"
24
+ subject { response }
25
+ it { should_not be_nil}
26
+ end
27
+
28
+ describe "client instance get test, chunked transfer, GZIP compression, no block" do
29
+ client = HttpStreamingClient::Client.new(compression: true)
30
+ response = client.get "http://www.yahoo.com/"
31
+ logger.debug "response: #{response}"
32
+ subject { response }
33
+ it { should_not be_nil}
34
+ end
35
+
36
+ describe "static get test HTTPS, no compression" do
37
+ response = HttpStreamingClient::Client.get("https://www.google.com/", compression: false) { |chunk| logger.debug "got a chunk" }
38
+ logger.debug "response: #{response}"
39
+ subject { response }
40
+ it { should_not be_nil}
41
+ end
42
+
43
+ describe "static get test HTTPS with compression" do
44
+ response = HttpStreamingClient::Client.get("https://www.google.com/", compression: true)
45
+ logger.debug "response: #{response}"
46
+ subject { response }
47
+ it { should_not be_nil}
48
+ end
49
+
50
+ describe "static get test HTTPS with compression and block" do
51
+ response = HttpStreamingClient::Client.get("https://www.google.com/", compression: true) { |chunk| logger.debug "got a chunk" }
52
+ logger.debug "response: #{response}"
53
+ subject { response }
54
+ it { should_not be_nil}
55
+ end
56
+
57
+ describe "static get failure test" do
58
+ it "should fail if host not found" do
59
+ expect { HttpStreamingClient::Client.get "http://www.blooglefailure.com/" }.to raise_error(SocketError)
60
+ end
61
+ end
62
+
63
+ describe "static post test" do
64
+ response = HttpStreamingClient::Client.post "http://posttestserver.com/post.php", "v=1.0&rsz=large&hl=en&geo=25187&key=ABQIAAAAh-n5SAB-cUnY3DufmfhdwBQuvo9pmDsxzxSHtaSRC_4ezr2lsRTOljpJVo81DJYBcnI00Fwk9xTdWQ"
65
+ logger.debug "response: #{response}"
66
+ subject { response }
67
+ it { should_not be_nil}
68
+ end
69
+
70
+ describe "client instance post test, no compression" do
71
+ client = HttpStreamingClient::Client.new(compression: false)
72
+ response = client.post "http://posttestserver.com/post.php", "v=1.0&rsz=large&hl=en&geo=25187&key=ABQIAAAAh-n5SAB-cUnY3DufmfhdwBQuvo9pmDsxzxSHtaSRC_4ezr2lsRTOljpJVo81DJYBcnI00Fwk9xTdWQ"
73
+ logger.debug "response: #{response}"
74
+ subject { response }
75
+ it { should_not be_nil}
76
+ end
77
+
78
+ describe "client instance post test with compression" do
79
+ client = HttpStreamingClient::Client.new(compression: true)
80
+ response = client.post "http://posttestserver.com/post.php", "v=1.0&rsz=large&hl=en&geo=25187&key=ABQIAAAAh-n5SAB-cUnY3DufmfhdwBQuvo9pmDsxzxSHtaSRC_4ezr2lsRTOljpJVo81DJYBcnI00Fwk9xTdWQ"
81
+ logger.debug "response: #{response}"
82
+ subject { response }
83
+ it { should_not be_nil}
84
+ end
85
+
86
+ describe "client instance post test with hash" do
87
+ client = HttpStreamingClient::Client.new
88
+ params = Hash.new
89
+ params['v'] = "1.0"
90
+ params['rsz'] = "large"
91
+ params['hl'] = "geo"
92
+ params['geo'] = "25187"
93
+ response = client.post "http://posttestserver.com/post.php", params
94
+ subject { response }
95
+ it { should_not be_nil}
96
+ end
97
+
98
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpStreamingClient::Oauth do
4
+
5
+ describe "generate_twitter_authorization test" do
6
+
7
+ # using test values from https://dev.twitter.com/docs/auth/authorizing-request
8
+ url = "https://api.twitter.com/1/statuses/update.json"
9
+ method = "post"
10
+ params_hash = {'include_entities' => true, 'status' => 'Hello Ladies + Gentlemen, a signed OAuth request!'}
11
+ oauth_consumer_key = "xvz1evFS4wEEPTGEFPHBog"
12
+ oauth_consumer_secret = "kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw"
13
+ oauth_signature = "tnnArxj06cWHq44gCs1OSKk/jLY="
14
+ oauth_token = "370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb"
15
+ oauth_token_secret = "LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE"
16
+ oauth_nonce = "kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg"
17
+ oauth_timestamp = "1318622958"
18
+
19
+ valid_authorization = 'OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318622958", oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", oauth_version="1.0"'
20
+
21
+ authorization = HttpStreamingClient::Oauth::Twitter.generate_authorization(url, method, params_hash, oauth_consumer_key, oauth_consumer_secret, oauth_token, oauth_token_secret, oauth_nonce, oauth_timestamp)
22
+
23
+ subject { authorization }
24
+ it { should_not be_nil }
25
+ it { should eq valid_authorization }
26
+ end
27
+
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'bundler/setup'
2
+ require 'logger'
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear! if ENV["COVERALLS"]
6
+
7
+ require 'simplecov'
8
+ SimpleCov.start do
9
+ add_filter "/spec/"
10
+ add_filter "/lib/http_streaming_client/credentials/"
11
+ end
12
+
13
+ require 'http_streaming_client'
14
+
15
+ NUM_JSON_RECORDS_TO_RECEIVE = 5
16
+ TIMEOUT_SEC = 90
17
+
18
+ RSpec.configure do |config|
19
+
20
+ HttpStreamingClient.logger.console = true
21
+ HttpStreamingClient.logger.level = Logger::DEBUG
22
+ HttpStreamingClient.logger.logfile = true
23
+
24
+ end
25
+
26
+ def logger
27
+ HttpStreamingClient.logger
28
+ end