framed_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +11 -0
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG +1 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +1 -0
  6. data/README.md +107 -0
  7. data/framed_rails.gemspec +37 -0
  8. data/lib/framed/client.rb +34 -0
  9. data/lib/framed/emitters.rb +113 -0
  10. data/lib/framed/example.rb +17 -0
  11. data/lib/framed/exceptions.rb +13 -0
  12. data/lib/framed/okjson.rb +602 -0
  13. data/lib/framed/rails.rb +43 -0
  14. data/lib/framed/railtie.rb +9 -0
  15. data/lib/framed/utils.rb +54 -0
  16. data/lib/framed/version.rb +4 -0
  17. data/lib/framed_rails.rb +71 -0
  18. data/vendor/gems/excon-0.45.3/data/cacert.pem +3860 -0
  19. data/vendor/gems/excon-0.45.3/lib/excon/connection.rb +469 -0
  20. data/vendor/gems/excon-0.45.3/lib/excon/constants.rb +142 -0
  21. data/vendor/gems/excon-0.45.3/lib/excon/errors.rb +155 -0
  22. data/vendor/gems/excon-0.45.3/lib/excon/extensions/uri.rb +33 -0
  23. data/vendor/gems/excon-0.45.3/lib/excon/headers.rb +83 -0
  24. data/vendor/gems/excon-0.45.3/lib/excon/middlewares/base.rb +24 -0
  25. data/vendor/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb +35 -0
  26. data/vendor/gems/excon-0.45.3/lib/excon/middlewares/escape_path.rb +11 -0
  27. data/vendor/gems/excon-0.45.3/lib/excon/middlewares/expects.rb +18 -0
  28. data/vendor/gems/excon-0.45.3/lib/excon/middlewares/idempotent.rb +33 -0
  29. data/vendor/gems/excon-0.45.3/lib/excon/middlewares/instrumentor.rb +34 -0
  30. data/vendor/gems/excon-0.45.3/lib/excon/middlewares/mock.rb +51 -0
  31. data/vendor/gems/excon-0.45.3/lib/excon/middlewares/redirect_follower.rb +56 -0
  32. data/vendor/gems/excon-0.45.3/lib/excon/middlewares/response_parser.rb +12 -0
  33. data/vendor/gems/excon-0.45.3/lib/excon/pretty_printer.rb +45 -0
  34. data/vendor/gems/excon-0.45.3/lib/excon/response.rb +212 -0
  35. data/vendor/gems/excon-0.45.3/lib/excon/socket.rb +310 -0
  36. data/vendor/gems/excon-0.45.3/lib/excon/ssl_socket.rb +151 -0
  37. data/vendor/gems/excon-0.45.3/lib/excon/standard_instrumentor.rb +27 -0
  38. data/vendor/gems/excon-0.45.3/lib/excon/unix_socket.rb +40 -0
  39. data/vendor/gems/excon-0.45.3/lib/excon/utils.rb +87 -0
  40. data/vendor/gems/excon-0.45.3/lib/excon.rb +234 -0
  41. metadata +91 -0
@@ -0,0 +1,40 @@
1
+ module Excon
2
+ class UnixSocket < Excon::Socket
3
+
4
+ private
5
+
6
+ def connect
7
+ @socket = ::Socket.new(::Socket::AF_UNIX, ::Socket::SOCK_STREAM, 0)
8
+ # If a Unix proxy was specified, the :path option will be set for it,
9
+ # otherwise fall back to the :socket option.
10
+ proxy_path = @data[:proxy] ? @data[:proxy][:path] : nil
11
+ sockaddr = ::Socket.sockaddr_un(proxy_path || @data[:socket])
12
+ if @nonblock
13
+ begin
14
+ @socket.connect_nonblock(sockaddr)
15
+ rescue Errno::EINPROGRESS
16
+ unless IO.select(nil, [@socket], nil, @data[:connect_timeout])
17
+ raise(Excon::Errors::Timeout.new("connect timeout reached"))
18
+ end
19
+ begin
20
+ @socket.connect_nonblock(sockaddr)
21
+ rescue Errno::EISCONN
22
+ end
23
+ end
24
+ else
25
+ begin
26
+ Timeout.timeout(@data[:connect_timeout]) do
27
+ @socket.connect(sockaddr)
28
+ end
29
+ rescue Timeout::Error
30
+ raise Excon::Errors::Timeout.new('connect timeout reached')
31
+ end
32
+ end
33
+
34
+ rescue => error
35
+ @socket.close rescue nil if @socket
36
+ raise error
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,87 @@
1
+ module Excon
2
+ module Utils
3
+ extend self
4
+
5
+ CONTROL = (0x0..0x1f).map {|c| c.chr }.join + "\x7f"
6
+ DELIMS = '<>#%"'
7
+ UNWISE = '{}|\\^[]`'
8
+ NONASCII = (0x80..0xff).map {|c| c.chr }.join
9
+ UNESCAPED = /([#{ Regexp.escape(CONTROL + ' ' + DELIMS + UNWISE + NONASCII) }])/
10
+ ESCAPED = /%([0-9a-fA-F]{2})/
11
+
12
+ def connection_uri(datum = @data)
13
+ unless datum
14
+ raise ArgumentError, '`datum` must be given unless called on a Connection'
15
+ end
16
+ if datum[:scheme] == UNIX
17
+ '' << datum[:scheme] << '://' << datum[:socket]
18
+ else
19
+ '' << datum[:scheme] << '://' << datum[:host] << port_string(datum)
20
+ end
21
+ end
22
+
23
+ def request_uri(datum)
24
+ connection_uri(datum) << datum[:path] << query_string(datum)
25
+ end
26
+
27
+ def port_string(datum)
28
+ if datum[:port].nil? || (datum[:omit_default_port] && ((datum[:scheme].casecmp('http') == 0 && datum[:port] == 80) || (datum[:scheme].casecmp('https') == 0 && datum[:port] == 443)))
29
+ ''
30
+ else
31
+ ':' << datum[:port].to_s
32
+ end
33
+ end
34
+
35
+ def query_string(datum)
36
+ str = ''
37
+ case datum[:query]
38
+ when String
39
+ str << '?' << datum[:query]
40
+ when Hash
41
+ str << '?'
42
+ datum[:query].sort_by {|k,_| k.to_s }.each do |key, values|
43
+ if values.nil?
44
+ str << key.to_s << '&'
45
+ else
46
+ [values].flatten.each do |value|
47
+ str << key.to_s << '=' << CGI.escape(value.to_s) << '&'
48
+ end
49
+ end
50
+ end
51
+ str.chop! # remove trailing '&'
52
+ end
53
+ str
54
+ end
55
+
56
+ # Splits a header value +str+ according to HTTP specification.
57
+ def split_header_value(str)
58
+ return [] if str.nil?
59
+ str = str.dup.strip
60
+ str.force_encoding('BINARY') if FORCE_ENC
61
+ str.scan(%r'\G((?:"(?:\\.|[^"])+?"|[^",]+)+)
62
+ (?:,\s*|\Z)'xn).flatten
63
+ end
64
+
65
+ # Escapes HTTP reserved and unwise characters in +str+
66
+ def escape_uri(str)
67
+ str = str.dup
68
+ str.force_encoding('BINARY') if FORCE_ENC
69
+ str.gsub(UNESCAPED) { "%%%02X" % $1[0].ord }
70
+ end
71
+
72
+ # Unescapes HTTP reserved and unwise characters in +str+
73
+ def unescape_uri(str)
74
+ str = str.dup
75
+ str.force_encoding('BINARY') if FORCE_ENC
76
+ str.gsub(ESCAPED) { $1.hex.chr }
77
+ end
78
+
79
+ # Unescape form encoded values in +str+
80
+ def unescape_form(str)
81
+ str = str.dup
82
+ str.force_encoding('BINARY') if FORCE_ENC
83
+ str.gsub!(/\+/, ' ')
84
+ str.gsub(ESCAPED) { $1.hex.chr }
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,234 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'cgi'
5
+ require 'forwardable'
6
+ require 'openssl'
7
+ require 'rbconfig'
8
+ require 'socket'
9
+ require 'timeout'
10
+ require 'uri'
11
+ require 'zlib'
12
+ require 'stringio'
13
+
14
+ require 'excon/extensions/uri'
15
+
16
+ require 'excon/middlewares/base'
17
+ require 'excon/middlewares/expects'
18
+ require 'excon/middlewares/idempotent'
19
+ require 'excon/middlewares/instrumentor'
20
+ require 'excon/middlewares/mock'
21
+ require 'excon/middlewares/response_parser'
22
+
23
+ require 'excon/constants'
24
+ require 'excon/utils'
25
+
26
+ require 'excon/connection'
27
+ require 'excon/errors'
28
+ require 'excon/headers'
29
+ require 'excon/response'
30
+ require 'excon/middlewares/decompress'
31
+ require 'excon/middlewares/escape_path'
32
+ require 'excon/middlewares/redirect_follower'
33
+ require 'excon/pretty_printer'
34
+ require 'excon/socket'
35
+ require 'excon/ssl_socket'
36
+ require 'excon/standard_instrumentor'
37
+ require 'excon/unix_socket'
38
+
39
+ # Define defaults first so they will be available to other files
40
+ module Excon
41
+ class << self
42
+
43
+ # @return [Hash] defaults for Excon connections
44
+ def defaults
45
+ @defaults ||= DEFAULTS
46
+ end
47
+
48
+ # Change defaults for Excon connections
49
+ # @return [Hash] defaults for Excon connections
50
+ def defaults=(new_defaults)
51
+ @defaults = new_defaults
52
+ end
53
+
54
+ def display_warning(warning)
55
+ # Show warning if $VERBOSE or ENV['EXCON_DEBUG'] is set
56
+ if $VERBOSE || ENV['EXCON_DEBUG']
57
+ $stderr.puts '[excon][WARNING] ' << warning << "\n#{ caller.join("\n") }"
58
+ end
59
+ end
60
+
61
+ # Status of mocking
62
+ def mock
63
+ display_warning('Excon#mock is deprecated, use Excon.defaults[:mock] instead.')
64
+ self.defaults[:mock]
65
+ end
66
+
67
+ # Change the status of mocking
68
+ # false is the default and works as expected
69
+ # true returns a value from stubs or raises
70
+ def mock=(new_mock)
71
+ display_warning('Excon#mock is deprecated, use Excon.defaults[:mock]= instead.')
72
+ self.defaults[:mock] = new_mock
73
+ end
74
+
75
+ # @return [String] The filesystem path to the SSL Certificate Authority
76
+ def ssl_ca_path
77
+ display_warning('Excon#ssl_ca_path is deprecated, use Excon.defaults[:ssl_ca_path] instead.')
78
+ self.defaults[:ssl_ca_path]
79
+ end
80
+
81
+ # Change path to the SSL Certificate Authority
82
+ # @return [String] The filesystem path to the SSL Certificate Authority
83
+ def ssl_ca_path=(new_ssl_ca_path)
84
+ display_warning('Excon#ssl_ca_path= is deprecated, use Excon.defaults[:ssl_ca_path]= instead.')
85
+ self.defaults[:ssl_ca_path] = new_ssl_ca_path
86
+ end
87
+
88
+ # @return [true, false] Whether or not to verify the peer's SSL certificate / chain
89
+ def ssl_verify_peer
90
+ display_warning('Excon#ssl_verify_peer is deprecated, use Excon.defaults[:ssl_verify_peer] instead.')
91
+ self.defaults[:ssl_verify_peer]
92
+ end
93
+
94
+ # Change the status of ssl peer verification
95
+ # @see Excon#ssl_verify_peer (attr_reader)
96
+ def ssl_verify_peer=(new_ssl_verify_peer)
97
+ display_warning('Excon#ssl_verify_peer= is deprecated, use Excon.defaults[:ssl_verify_peer]= instead.')
98
+ self.defaults[:ssl_verify_peer] = new_ssl_verify_peer
99
+ end
100
+
101
+ # @see Connection#initialize
102
+ # Initializes a new keep-alive session for a given remote host
103
+ # @param [String] url The destination URL
104
+ # @param [Hash<Symbol, >] params One or more option params to set on the Connection instance
105
+ # @return [Connection] A new Excon::Connection instance
106
+ def new(url, params = {})
107
+ uri_parser = params[:uri_parser] || defaults[:uri_parser]
108
+ uri = uri_parser.parse(url)
109
+ unless uri.scheme
110
+ raise ArgumentError.new("Invalid URI: #{uri}")
111
+ end
112
+ params = {
113
+ :host => uri.host,
114
+ :hostname => uri.hostname,
115
+ :path => uri.path,
116
+ :port => uri.port,
117
+ :query => uri.query,
118
+ :scheme => uri.scheme
119
+ }.merge(params)
120
+ if uri.password
121
+ params[:password] = Utils.unescape_uri(uri.password)
122
+ end
123
+ if uri.user
124
+ params[:user] = Utils.unescape_uri(uri.user)
125
+ end
126
+ Excon::Connection.new(params)
127
+ end
128
+
129
+ # push an additional stub onto the list to check for mock requests
130
+ # @param [Hash<Symbol, >] request params to match against, omitted params match all
131
+ # @param [Hash<Symbol, >] response params to return from matched request or block to call with params
132
+ def stub(request_params = {}, response_params = nil)
133
+ if method = request_params.delete(:method)
134
+ request_params[:method] = method.to_s.downcase.to_sym
135
+ end
136
+ if url = request_params.delete(:url)
137
+ uri = URI.parse(url)
138
+ request_params = {
139
+ :host => uri.host,
140
+ :path => uri.path,
141
+ :port => uri.port,
142
+ :query => uri.query,
143
+ :scheme => uri.scheme
144
+ }.merge!(request_params)
145
+ if uri.user || uri.password
146
+ request_params[:headers] ||= {}
147
+ user, pass = Utils.unescape_form(uri.user.to_s), Utils.unescape_form(uri.password.to_s)
148
+ request_params[:headers]['Authorization'] ||= 'Basic ' << ['' << user << ':' << pass].pack('m').delete(Excon::CR_NL)
149
+ end
150
+ end
151
+ if request_params.has_key?(:headers)
152
+ headers = Excon::Headers.new
153
+ request_params[:headers].each do |key, value|
154
+ headers[key] = value
155
+ end
156
+ request_params[:headers] = headers
157
+ end
158
+ if block_given?
159
+ if response_params
160
+ raise(ArgumentError.new("stub requires either response_params OR a block"))
161
+ else
162
+ stub = [request_params, Proc.new]
163
+ end
164
+ elsif response_params
165
+ stub = [request_params, response_params]
166
+ else
167
+ raise(ArgumentError.new("stub requires either response_params OR a block"))
168
+ end
169
+ stubs.unshift(stub)
170
+ stub
171
+ end
172
+
173
+ # get a stub matching params or nil
174
+ # @param [Hash<Symbol, >] request params to match against, omitted params match all
175
+ # @return [Hash<Symbol, >] response params to return from matched request or block to call with params
176
+ def stub_for(request_params={})
177
+ if method = request_params.delete(:method)
178
+ request_params[:method] = method.to_s.downcase.to_sym
179
+ end
180
+ Excon.stubs.each do |stub, response_params|
181
+ captures = { :headers => {} }
182
+ headers_match = !stub.has_key?(:headers) || stub[:headers].keys.all? do |key|
183
+ case value = stub[:headers][key]
184
+ when Regexp
185
+ if match = value.match(request_params[:headers][key])
186
+ captures[:headers][key] = match.captures
187
+ end
188
+ match
189
+ else
190
+ value == request_params[:headers][key]
191
+ end
192
+ end
193
+ non_headers_match = (stub.keys - [:headers]).all? do |key|
194
+ case value = stub[key]
195
+ when Regexp
196
+ if match = value.match(request_params[key])
197
+ captures[key] = match.captures
198
+ end
199
+ match
200
+ else
201
+ value == request_params[key]
202
+ end
203
+ end
204
+ if headers_match && non_headers_match
205
+ request_params[:captures] = captures
206
+ return [stub, response_params]
207
+ end
208
+ end
209
+ nil
210
+ end
211
+
212
+ # get a list of defined stubs
213
+ def stubs
214
+ @stubs ||= []
215
+ end
216
+
217
+ # remove first/oldest stub matching request_params
218
+ # @param [Hash<Symbol, >] request params to match against, omitted params match all
219
+ # @return [Hash<Symbol, >] response params from deleted stub
220
+ def unstub(request_params = {})
221
+ stub = stub_for(request_params)
222
+ Excon.stubs.delete_at(Excon.stubs.index(stub))
223
+ end
224
+
225
+ # Generic non-persistent HTTP methods
226
+ HTTP_VERBS.each do |method|
227
+ module_eval <<-DEF, __FILE__, __LINE__ + 1
228
+ def #{method}(url, params = {}, &block)
229
+ new(url, params).request(:method => :#{method}, &block)
230
+ end
231
+ DEF
232
+ end
233
+ end
234
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: framed_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Dunck
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-08-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'TK
15
+
16
+ '
17
+ email: support@framed.io
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - CHANGELOG
22
+ - LICENSE
23
+ - README.md
24
+ files:
25
+ - .gitignore
26
+ - .ruby-version
27
+ - CHANGELOG
28
+ - Gemfile
29
+ - LICENSE
30
+ - README.md
31
+ - framed_rails.gemspec
32
+ - lib/framed/client.rb
33
+ - lib/framed/emitters.rb
34
+ - lib/framed/example.rb
35
+ - lib/framed/exceptions.rb
36
+ - lib/framed/okjson.rb
37
+ - lib/framed/rails.rb
38
+ - lib/framed/railtie.rb
39
+ - lib/framed/utils.rb
40
+ - lib/framed/version.rb
41
+ - lib/framed_rails.rb
42
+ - vendor/gems/excon-0.45.3/data/cacert.pem
43
+ - vendor/gems/excon-0.45.3/lib/excon.rb
44
+ - vendor/gems/excon-0.45.3/lib/excon/connection.rb
45
+ - vendor/gems/excon-0.45.3/lib/excon/constants.rb
46
+ - vendor/gems/excon-0.45.3/lib/excon/errors.rb
47
+ - vendor/gems/excon-0.45.3/lib/excon/extensions/uri.rb
48
+ - vendor/gems/excon-0.45.3/lib/excon/headers.rb
49
+ - vendor/gems/excon-0.45.3/lib/excon/middlewares/base.rb
50
+ - vendor/gems/excon-0.45.3/lib/excon/middlewares/decompress.rb
51
+ - vendor/gems/excon-0.45.3/lib/excon/middlewares/escape_path.rb
52
+ - vendor/gems/excon-0.45.3/lib/excon/middlewares/expects.rb
53
+ - vendor/gems/excon-0.45.3/lib/excon/middlewares/idempotent.rb
54
+ - vendor/gems/excon-0.45.3/lib/excon/middlewares/instrumentor.rb
55
+ - vendor/gems/excon-0.45.3/lib/excon/middlewares/mock.rb
56
+ - vendor/gems/excon-0.45.3/lib/excon/middlewares/redirect_follower.rb
57
+ - vendor/gems/excon-0.45.3/lib/excon/middlewares/response_parser.rb
58
+ - vendor/gems/excon-0.45.3/lib/excon/pretty_printer.rb
59
+ - vendor/gems/excon-0.45.3/lib/excon/response.rb
60
+ - vendor/gems/excon-0.45.3/lib/excon/socket.rb
61
+ - vendor/gems/excon-0.45.3/lib/excon/ssl_socket.rb
62
+ - vendor/gems/excon-0.45.3/lib/excon/standard_instrumentor.rb
63
+ - vendor/gems/excon-0.45.3/lib/excon/unix_socket.rb
64
+ - vendor/gems/excon-0.45.3/lib/excon/utils.rb
65
+ homepage: http://www.github.com/framed-data/framed_rails
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ - vendor/gems/excon-0.45.3/lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.8.7
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>'
83
+ - !ruby/object:Gem::Version
84
+ version: 1.3.1
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.23
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Framed.io data collector
91
+ test_files: []