quicky 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .idea/
2
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ quicky (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ test-unit (2.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ quicky!
16
+ test-unit
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012, Iron.io, Inc. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice,
7
+ this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright notice,
9
+ this list of conditions and the following disclaimer in the documentation
10
+ and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
19
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
21
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ Rest Wrapper
2
+ -------------
3
+
4
+ HTTP/REST client wrapper that provides a standard interface for making http requests using different http clients.
5
+ If no client is specified it will choose the best one you have installed.
6
+
7
+ Getting Started
8
+ ==============
9
+
10
+ Install the gem:
11
+
12
+ gem install rest
13
+
14
+ Create an Rest client:
15
+
16
+ @rest = Rest::Client.new()
17
+
18
+ To choose a specific underlying http client lib:
19
+
20
+ @rest = Rest::Client.new(:gem=>:typhoeus)
21
+
22
+ Supported http libraries are:
23
+
24
+ * rest-client
25
+ * net-http-persistent
26
+ * typhoeus
27
+
28
+ Then use it:
29
+
30
+ GET
31
+ =========
32
+
33
+ @rest.get(url, options...)
34
+
35
+ options:
36
+
37
+ - :params => query params for url
38
+ - :headers => headers
39
+
40
+ POST
41
+ ======
42
+
43
+ @rest.post(url, options...)
44
+
45
+ options:
46
+
47
+ - :body => POST body
48
+ - :headers => headers
49
+
50
+ PUT
51
+ ======
52
+
53
+ @rest.put(url, options...)
54
+
55
+ options:
56
+
57
+ - :body => POST body
58
+ - :headers => headers
59
+
60
+ DELETE
61
+ ======
62
+
63
+ @rest.delete(url, options...)
64
+
65
+
66
+
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
12
+
13
+ require 'rdoc/task'
14
+ Rake::RDocTask.new do |rdoc|
15
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
16
+
17
+ rdoc.rdoc_dir = 'doc'
18
+ rdoc.title = "iron_mq #{version}"
19
+ rdoc.rdoc_files.include('README*')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
data/lib/quicky.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative 'quicky/timer'
@@ -0,0 +1,65 @@
1
+ module Quicky
2
+
3
+ class Timer
4
+
5
+ def initialize
6
+ @collector = {}
7
+ end
8
+
9
+ def loop(name, x, &blk)
10
+ x.times do |i|
11
+ time(name, &blk)
12
+ end
13
+ end
14
+
15
+ def time(name, &blk)
16
+ t = Time.now
17
+ yield
18
+ duration = Time.now.to_f - t.to_f
19
+ #puts 'duration=' + duration.to_s
20
+ r = TimeResult.new(duration)
21
+ @collector[name] ||= TimeCollector.new(name)
22
+ @collector[name] << r
23
+ r
24
+ end
25
+
26
+ def results(name=nil)
27
+ if name
28
+ return @collector[name]
29
+ end
30
+ @collector
31
+ end
32
+ end
33
+
34
+ class TimeCollector
35
+ attr_accessor :name
36
+ def initialize(name)
37
+ @name = name
38
+ @collector = []
39
+ @total_duration = 0.0
40
+ end
41
+
42
+ def <<(val)
43
+ # pull out duration for totals
44
+ @total_duration += val.duration
45
+ @collector << val
46
+ end
47
+
48
+ def duration
49
+ @total_duration / @collector.size
50
+ end
51
+
52
+ def total_duration
53
+ @total_duration
54
+ end
55
+ end
56
+
57
+ class TimeResult
58
+
59
+ attr_accessor :duration
60
+
61
+ def initialize(duration)
62
+ @duration = duration
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module Quicky
2
+ VERSION = "0.0.1"
3
+ end
data/quicky.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../lib/quicky/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Travis Reeder"]
5
+ gem.email = ["treeder@gmail.com"]
6
+ gem.description = "Rest client wrapper that chooses best installed client."
7
+ gem.summary = "Rest client wrapper that chooses best installed client."
8
+ gem.homepage = "https://github.com/iron-io/quicky"
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "quicky"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Quicky::VERSION
16
+
17
+ gem.required_rubygems_version = ">= 1.3.6"
18
+ gem.required_ruby_version = Gem::Requirement.new(">= 1.9")
19
+
20
+ gem.add_development_dependency "test-unit"
21
+
22
+ end
23
+
data/test/test_base.rb ADDED
@@ -0,0 +1,18 @@
1
+ gem 'test-unit'
2
+ require 'test/unit'
3
+ require 'yaml'
4
+ begin
5
+ require File.join(File.dirname(__FILE__), '../lib/quicky')
6
+ rescue Exception => ex
7
+ puts "Could NOT load gem: " + ex.message
8
+ raise ex
9
+ end
10
+
11
+
12
+ class TestBase < Test::Unit::TestCase
13
+ def setup
14
+ puts 'setup'
15
+
16
+
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ # Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
2
+
3
+ gem 'test-unit'
4
+ require 'test/unit'
5
+ require 'yaml'
6
+ require_relative 'test_base'
7
+
8
+ class TestBasics < TestBase
9
+ def setup
10
+ super
11
+ end
12
+
13
+ def test_basics
14
+ quicky = Quicky::Timer.new
15
+ quicky.time(:test1) do
16
+ sleep 2
17
+ end
18
+ p quicky.results(:test1).duration
19
+ assert quicky.results(:test1).duration > 2
20
+
21
+ quicky = Quicky::Timer.new
22
+ quicky.loop(:test2, 10) do |i|
23
+ puts 'sleeping'
24
+ sleep 1
25
+ end
26
+ p quicky.results(:test2).inspect
27
+ p quicky.results(:test2).duration
28
+ assert quicky.results(:test2).duration >= 1 && quicky.results(:test2).duration < 2
29
+ assert quicky.results(:test2).total_duration >= 10
30
+
31
+ end
32
+
33
+ end
34
+
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quicky
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Travis Reeder
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: test-unit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Rest client wrapper that chooses best installed client.
31
+ email:
32
+ - treeder@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - lib/quicky.rb
44
+ - lib/quicky/timer.rb
45
+ - lib/quicky/version.rb
46
+ - quicky.gemspec
47
+ - test/test_base.rb
48
+ - test/test_basics.rb
49
+ homepage: https://github.com/iron-io/quicky
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '1.9'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.6
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Rest client wrapper that chooses best installed client.
73
+ test_files:
74
+ - test/test_base.rb
75
+ - test/test_basics.rb