httparty-timed 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d739152feda1a6897e3d333d646a75cef5add19a
4
+ data.tar.gz: b1d074ac3b8f4019ddc6b4e1b2e9734b94df3fc2
5
+ SHA512:
6
+ metadata.gz: 3eaee415e66d19131dd033a9c7745895d6caacd477bab1a659bfbf3fc392ea50561624fdb460e530d5a5c9067754d270910cc99f61a2b6119612b02176a8a875
7
+ data.tar.gz: 3eba45d8deafbdfb29c4d614eb1d87083ef04cd5ff6495650601a16c0f04553dbdaa7d919fac9f21e33a817d25a42a406b027cb80b9652e3e569c31ac1f6e529
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Silva, Arthur
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Httparty::Timmed
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'httparty-timmed'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install httparty-timmed
18
+
19
+ ## Usage
20
+
21
+ This is very simple to use, just require the gem:
22
+ "require 'httparty/timed"
23
+
24
+ and whenever you make a request with http you'll have the #duration method:
25
+ res = HTTParty.get 'http://google.com'
26
+ puts res.duration
27
+
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+
4
+ hello = lambda do
5
+ {hello: :world}.to_json
6
+ end
7
+
8
+ [:get, :post, :delete, :put].each do | method_sym |
9
+ send( method_sym,'/hello', &hello )
10
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'httparty/timed/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "httparty-timed"
8
+ spec.version = Httparty::Timed::VERSION
9
+ spec.authors = ["Silva, Arthur"]
10
+ spec.email = ["awls99@gmail.com"]
11
+ spec.description = %q{HTTParty with Response#duration method}
12
+ spec.summary = %q{This gem consist mostly of monkey patching to get Net::HTTP to record the call's duration and
13
+ pass it along HTTParty for easy usage}
14
+ spec.homepage = "https://github.com/awls99/httparty-timed"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "httparty"
23
+ spec.add_development_dependency "sinatra"
24
+ spec.add_development_dependency "rspec"
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'httparty'
2
+
3
+ class Net::HTTP
4
+ alias_method :original_begin_transport, :begin_transport
5
+ alias_method :original_end_transport, :end_transport
6
+
7
+ def begin_transport req
8
+ original_begin_transport req
9
+ @init_time = Time.now
10
+ end
11
+
12
+ def end_transport(req, res)
13
+ res.duration = ( (Time.now - @init_time) * 1000 ).to_i
14
+ original_end_transport(req, res)
15
+ end
16
+
17
+ end
18
+
19
+ class HTTParty::Response
20
+ def duration
21
+ @response.duration
22
+ end
23
+ end
24
+
25
+ class Net::HTTPResponse
26
+ attr :duration, true
27
+ end
@@ -0,0 +1,5 @@
1
+ module Httparty
2
+ module Timed
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'rspec'
8
+ require_relative File.join(*%w[.. lib httparty timed])
9
+
10
+ RSpec.configure do |config|
11
+ # Run specs in random order to surface order dependencies. If you find an
12
+ # order dependency and want to debug it, you can fix the order by providing
13
+ # the seed, which is printed after each run.
14
+ # --seed 1234
15
+ config.order = 'random'
16
+ end
17
+
18
+
19
+ describe "HTTParty timed" do
20
+ [:get, :post, :delete, :put].each do | method_sym |
21
+ it "#{method_sym.to_s.capitalize}: Makes a request and times it" do
22
+ res = HTTParty.method( method_sym).call( 'http://localhost:4567/hello', {:headers => {'Content-Length' => '0'}})
23
+ res.success?.should eq true
24
+ res.duration.class.should eq Fixnum
25
+ end
26
+
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httparty-timed
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Silva, Arthur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: HTTParty with Response#duration method
56
+ email:
57
+ - awls99@gmail.com
58
+ executables:
59
+ - server.rb
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - LICENSE.txt
65
+ - README.md
66
+ - bin/server.rb
67
+ - httparty-timed.gemspec
68
+ - lib/httparty/timed.rb
69
+ - lib/httparty/timed/version.rb
70
+ - spec/spec.rb
71
+ homepage: https://github.com/awls99/httparty-timed
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.1.11
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: This gem consist mostly of monkey patching to get Net::HTTP to record the
95
+ call's duration and pass it along HTTParty for easy usage
96
+ test_files:
97
+ - spec/spec.rb