achetepe 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +51 -0
- data/achetepe.gemspec +24 -0
- data/lib/achetepe.rb +17 -0
- data/rakefile +38 -0
- data/test/get_test.rb +42 -0
- data/test/helper.rb +36 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 47ec06bb484234f0d4b3f8ea850463f0dfc36669
|
4
|
+
data.tar.gz: fddfdb1d0847184309f913234db4dbd81301614f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a153b193691fa10305ee4f762515ed904c46930852ec48e117259b155fb606480d78e770ad4bd8e9dab3ea81df6c016025dc14c11dd8940cb40d9cec07325232
|
7
|
+
data.tar.gz: 96e15f8a88d3bb0c3b3af5bb4b71afb8cd244efb7c7fd6ab086f72a30631df49d3a5ed6df045dd2d7b29455dcf3f5c06ac293f5fc26fe3986f0892fb703b2893
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
achetepe
|
2
|
+
========
|
3
|
+
|
4
|
+
Asynchronous HTTP Requests using Threads
|
5
|
+
|
6
|
+
## Dependencies
|
7
|
+
|
8
|
+
`achetepe` requires Ruby 1.9 or later.
|
9
|
+
|
10
|
+
Install dependencies using `dep` is easy as run:
|
11
|
+
|
12
|
+
dep install
|
13
|
+
|
14
|
+
### Development and Testing dependencies
|
15
|
+
|
16
|
+
Start test server
|
17
|
+
|
18
|
+
rake test:start_server
|
19
|
+
|
20
|
+
Run tests
|
21
|
+
|
22
|
+
rake
|
23
|
+
|
24
|
+
Stop test server
|
25
|
+
|
26
|
+
rake test:stop_server
|
27
|
+
|
28
|
+
## Instalation
|
29
|
+
|
30
|
+
As simple as
|
31
|
+
|
32
|
+
$ gem install ork
|
33
|
+
|
34
|
+
|
35
|
+
## Getting started
|
36
|
+
|
37
|
+
`achetepe` makes an HTTP request to run in background using __Threads__ and when you get a response, it will execute a block (a.k.a _callback function_)
|
38
|
+
|
39
|
+
|
40
|
+
### GET
|
41
|
+
|
42
|
+
Achetepe.get('https://github.com/emancu/achetepe') do |response|
|
43
|
+
puts response
|
44
|
+
end
|
45
|
+
|
46
|
+
# => #<Thread:0x007fd2b413b530 sleep>
|
47
|
+
# => #<Net::HTTPOK:0x007fd2b5959f68>
|
48
|
+
|
49
|
+
### POST
|
50
|
+
|
51
|
+
Coming soon..
|
data/achetepe.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'achetepe'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
5
|
+
s.summary = 'Asynchronous HTTP Requests using Threads'
|
6
|
+
s.description = '`achetepe` is a small and simple library to execute a block of code after an asynchronous HTTP request.'
|
7
|
+
s.authors = ['Emiliano Mancuso']
|
8
|
+
s.email = ['emiliano.mancuso@gmail.com']
|
9
|
+
s.homepage = 'http://github.com/emancu/achetepe'
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.files = Dir[
|
13
|
+
'README.md',
|
14
|
+
'rakefile',
|
15
|
+
'lib/**/*.rb',
|
16
|
+
'*.gemspec'
|
17
|
+
]
|
18
|
+
s.test_files = Dir['test/*.*']
|
19
|
+
|
20
|
+
s.add_development_dependency 'protest'
|
21
|
+
s.add_development_dependency 'cuba'
|
22
|
+
end
|
23
|
+
|
24
|
+
|
data/lib/achetepe.rb
ADDED
data/rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
task :default => 'test:run'
|
2
|
+
|
3
|
+
TEST_APP_PID = '/tmp/achetepe_test_server.pid'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
|
7
|
+
desc 'Start TestApp server'
|
8
|
+
task :start_server do
|
9
|
+
unless File.exist?(TEST_APP_PID)
|
10
|
+
require File.expand_path("./test/helper", File.dirname(__FILE__))
|
11
|
+
|
12
|
+
puts 'Starting TestApp server'
|
13
|
+
|
14
|
+
$pid = fork do
|
15
|
+
Rack::Server.start app: TestApp, Port: 9494, daemonize: true
|
16
|
+
end
|
17
|
+
|
18
|
+
system "echo #{$pid} > #{TEST_APP_PID}"
|
19
|
+
|
20
|
+
sleep(1.5)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Run tests'
|
25
|
+
task :run => [:start_server] do
|
26
|
+
require File.expand_path("./test/helper", File.dirname(__FILE__))
|
27
|
+
|
28
|
+
Dir["test/**/*_test.rb"].each { |file| load file }
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Stop TestApp Server'
|
32
|
+
task :stop_server do
|
33
|
+
puts "Stopping TestApp Server"
|
34
|
+
pid = File.read(TEST_APP_PID).to_i
|
35
|
+
Process.kill('SIGINT', pid)
|
36
|
+
system "rm #{TEST_APP_PID}"
|
37
|
+
end
|
38
|
+
end
|
data/test/get_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative './helper'
|
2
|
+
|
3
|
+
Protest.describe 'Get' do
|
4
|
+
|
5
|
+
it 'return a Net::HTTPOK on a valid url' do
|
6
|
+
response = Achetepe.get('http://localhost:9494/') do |response|
|
7
|
+
assert response.class.ancestors.include?(Net::HTTPResponse)
|
8
|
+
end
|
9
|
+
|
10
|
+
assert_equal Thread, response.class
|
11
|
+
response.join
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'return a Net::HTTPNotFound' do
|
15
|
+
response = Achetepe.get('http://localhost:9494/not_found') do |response|
|
16
|
+
assert response.class.ancestors.include?(Net::HTTPResponse)
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_equal Thread, response.class
|
20
|
+
response.join
|
21
|
+
end
|
22
|
+
|
23
|
+
it "executes the block as soon as a response is received" do
|
24
|
+
ordered_responses = []
|
25
|
+
|
26
|
+
get1 = Achetepe.get(TestApp.url + 'slow_request') do |response|
|
27
|
+
ordered_responses << 'slow_request'
|
28
|
+
end
|
29
|
+
|
30
|
+
sleep(1)
|
31
|
+
|
32
|
+
get2 = Achetepe.get(TestApp.url) do |response|
|
33
|
+
ordered_responses << 'root'
|
34
|
+
end
|
35
|
+
|
36
|
+
get1.join
|
37
|
+
get2.join
|
38
|
+
|
39
|
+
assert_equal ['root', 'slow_request'], ordered_responses
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
2
|
+
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "protest"
|
6
|
+
require "achetepe"
|
7
|
+
require "cuba"
|
8
|
+
|
9
|
+
Protest.report_with(:progress)
|
10
|
+
|
11
|
+
class TestApp < Cuba
|
12
|
+
def self.url
|
13
|
+
'http://localhost:9494/'
|
14
|
+
end
|
15
|
+
|
16
|
+
define do
|
17
|
+
on get do
|
18
|
+
on root do
|
19
|
+
res.write "Hello achetepe!"
|
20
|
+
end
|
21
|
+
|
22
|
+
on "redirects" do
|
23
|
+
res.redirect "/"
|
24
|
+
end
|
25
|
+
|
26
|
+
on "slow_request" do
|
27
|
+
sleep(2)
|
28
|
+
res.write "It takes too much"
|
29
|
+
end
|
30
|
+
|
31
|
+
on default do
|
32
|
+
res.status = 404
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: achetepe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emiliano Mancuso
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: protest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: cuba
|
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
|
+
description: '`achetepe` is a small and simple library to execute a block of code
|
42
|
+
after an asynchronous HTTP request.'
|
43
|
+
email:
|
44
|
+
- emiliano.mancuso@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- README.md
|
50
|
+
- rakefile
|
51
|
+
- lib/achetepe.rb
|
52
|
+
- achetepe.gemspec
|
53
|
+
- test/get_test.rb
|
54
|
+
- test/helper.rb
|
55
|
+
homepage: http://github.com/emancu/achetepe
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Asynchronous HTTP Requests using Threads
|
79
|
+
test_files:
|
80
|
+
- test/get_test.rb
|
81
|
+
- test/helper.rb
|