httpalooza 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Rakefile +4 -0
- data/lib/httpalooza.rb +3 -0
- data/lib/httpalooza/api.rb +35 -0
- data/lib/httpalooza/lineup.rb +13 -0
- data/lib/httpalooza/players.rb +3 -0
- data/lib/httpalooza/players/base.rb +9 -0
- data/lib/httpalooza/request.rb +20 -0
- data/lib/httpalooza/response.rb +11 -0
- data/lib/httpalooza/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 015fd22c665878d26dcb1513a726bbef678dd5a0
|
4
|
+
data.tar.gz: 96d5562f0f346c9b08b2459d07e93058caa34609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dacbfe38f88bbf6ceb9b725784a76b7fcaf04a1581e9dc7cf08a439babb29b3e541352292519e8e8dfd8d55e20b5fb717dad9a102479c45fe0dcc1954f7feef
|
7
|
+
data.tar.gz: 8360c36ddf32eb93dd13cd43e33bd70c74cc387a011ec01bb7a351bb382e13fc699ec6581d061efe244aaab4017cb82c04fc60beff115bd6f07a4246927c49cb
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
data/lib/httpalooza.rb
CHANGED
data/lib/httpalooza/api.rb
CHANGED
@@ -1,21 +1,56 @@
|
|
1
1
|
module HTTPalooza
|
2
2
|
module API
|
3
|
+
# Peform an HTTP GET request with the assembled Lineup.
|
4
|
+
#
|
5
|
+
# @param [String] url the URL to request.
|
6
|
+
# options [Hash] the request options
|
7
|
+
# @option options [Hash] :headers request headers
|
8
|
+
# @option options [Hash] :params URL parameters
|
9
|
+
# @option options [String] :payload the request body
|
3
10
|
def get(url, options = {}, &block)
|
4
11
|
run! Request.new(url, :get, options.slice(:headers, :params, :payload), &block)
|
5
12
|
end
|
6
13
|
|
14
|
+
# Peform an HTTP POST request with the assembled Lineup.
|
15
|
+
#
|
16
|
+
# @param [String] url the URL to request.
|
17
|
+
# options [Hash] the request options
|
18
|
+
# @option options [Hash] :headers request headers
|
19
|
+
# @option options [Hash] :params URL parameters
|
20
|
+
# @option options [String] :payload the request body
|
7
21
|
def post(url, options = {}, &block)
|
8
22
|
run! Request.new(url, :post, options.slice(:headers, :params, :payload), &block)
|
9
23
|
end
|
10
24
|
|
25
|
+
# Peform an HTTP PUT request with the assembled Lineup.
|
26
|
+
#
|
27
|
+
# @param [String] url the URL to request.
|
28
|
+
# options [Hash] the request options
|
29
|
+
# @option options [Hash] :headers request headers
|
30
|
+
# @option options [Hash] :params URL parameters
|
31
|
+
# @option options [String] :payload the request body
|
11
32
|
def put(url, options = {}, &block)
|
12
33
|
run! Request.new(url, :put, options.slice(:headers, :params, :payload), &block)
|
13
34
|
end
|
14
35
|
|
36
|
+
# Peform an HTTP DELETE request with the assembled Lineup.
|
37
|
+
#
|
38
|
+
# @param [String] url the URL to request.
|
39
|
+
# options [Hash] the request options
|
40
|
+
# @option options [Hash] :headers request headers
|
41
|
+
# @option options [Hash] :params URL parameters
|
42
|
+
# @option options [String] :payload the request body
|
15
43
|
def delete(url, options = {}, &block)
|
16
44
|
run! Request.new(url, :delete, options.slice(:headers, :params, :payload), &block)
|
17
45
|
end
|
18
46
|
|
47
|
+
# Peform an HTTP HEAD request with the assembled Lineup.
|
48
|
+
#
|
49
|
+
# @param [String] url the URL to request.
|
50
|
+
# options [Hash] the request options
|
51
|
+
# @option options [Hash] :headers request headers
|
52
|
+
# @option options [Hash] :params URL parameters
|
53
|
+
# @option options [String] :payload the request body
|
19
54
|
def head(url, options = {}, &block)
|
20
55
|
run! Request.new(url, :head, options.slice(:headers, :params, :payload), &block)
|
21
56
|
end
|
data/lib/httpalooza/lineup.rb
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
module HTTPalooza
|
2
|
+
# A Lineup assembles a set of Players to perform HTTP requests.
|
3
|
+
#
|
4
|
+
# @example Perform a request with curb
|
5
|
+
# lineup = HTTPalooza::Lineup.new.with_curb
|
6
|
+
# response = lineup.get('http://httpbin.org/')
|
7
|
+
# response[:curb] #=> Get the response from Curb
|
8
|
+
#
|
9
|
+
# @example Performing multiple requests
|
10
|
+
# lineup = HTTPalooza::Lineup.new.with_curb.and_unirest
|
11
|
+
# lineup.get('http://httpbin.org/')
|
12
|
+
# response[:curb] #=> Get the response from Curb
|
13
|
+
# response[:unirest] #=> Get the response from Unirest
|
2
14
|
class Lineup
|
3
15
|
include API
|
4
16
|
|
@@ -17,6 +29,7 @@ module HTTPalooza
|
|
17
29
|
end
|
18
30
|
end
|
19
31
|
|
32
|
+
# Return a Lineup with all available Players
|
20
33
|
def everyone
|
21
34
|
players.merge(Players.available)
|
22
35
|
self
|
data/lib/httpalooza/players.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
module HTTPalooza
|
2
2
|
module Players
|
3
|
+
# Superclass for Player implementations
|
4
|
+
# @abstract
|
3
5
|
class Base
|
4
6
|
class << self
|
5
7
|
attr_reader :name, :dependencies
|
6
8
|
|
9
|
+
# Create a new player and require any depenencies.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# introducing! :selenium, %w[ selenium-webdriver ]
|
13
|
+
#
|
14
|
+
# @param [Symbol] name the name of the player
|
15
|
+
# @param [Array] dependencies a list of dependencies require in order to use this player
|
7
16
|
def introducing!(name, dependencies = [])
|
8
17
|
@name = name.to_sym
|
9
18
|
@dependencies = dependencies
|
data/lib/httpalooza/request.rb
CHANGED
@@ -1,9 +1,28 @@
|
|
1
1
|
module HTTPalooza
|
2
|
+
# Request presents a standard interface for describing an HTTP request that Players can translate into the underlying library's representation.
|
2
3
|
class Request
|
3
4
|
STANDARD_METHODS = [:get, :post, :put, :patch, :delete, :options, :head]
|
4
5
|
|
5
6
|
attr_reader :url, :method, :params, :payload, :headers
|
7
|
+
# @!attribute [r] url
|
8
|
+
# @return [String] the URL to request
|
9
|
+
# @!attribute [r] method
|
10
|
+
# @return [Symbol] the HTTP method
|
11
|
+
# @!attribute [r] params
|
12
|
+
# @return [Hash] the URL parameters
|
13
|
+
# @!attribute [r] payload
|
14
|
+
# @return [String] the request body
|
15
|
+
# @!attribute [r] headers
|
16
|
+
# @return [Hash] the request headers
|
6
17
|
|
18
|
+
# Instantiate a Request.
|
19
|
+
#
|
20
|
+
# @param [String] url the URL to request
|
21
|
+
# @param [Symbol] method the HTTP method
|
22
|
+
# @param [Hash] options additional options
|
23
|
+
# @option options [Hash] :params the URL parameters
|
24
|
+
# @option options [Hash] :headers the request headers
|
25
|
+
# @option options [String] :payload the request payload
|
7
26
|
def initialize(url, method, options = {})
|
8
27
|
@url = url
|
9
28
|
@method = method
|
@@ -14,6 +33,7 @@ module HTTPalooza
|
|
14
33
|
normalize_url!
|
15
34
|
end
|
16
35
|
|
36
|
+
# @return [Boolean] whether or not the URL is SSL
|
17
37
|
def ssl?
|
18
38
|
!!(url.to_s =~ /^https/)
|
19
39
|
end
|
data/lib/httpalooza/response.rb
CHANGED
@@ -1,18 +1,29 @@
|
|
1
1
|
module HTTPalooza
|
2
|
+
# Response represents a unified interface for the various Player's responses.
|
2
3
|
class Response
|
3
4
|
AwesomeResponseCodes = 200..299
|
4
5
|
|
6
|
+
# @!attribute code
|
7
|
+
# @return [Fixnum] the HTTP status code
|
8
|
+
# @!attribute body
|
9
|
+
# @return [String] the HTTP response body
|
5
10
|
attr_accessor :code, :body
|
6
11
|
|
12
|
+
# Create a new Response.
|
13
|
+
#
|
14
|
+
# @param [Fixnum] code the HTTP status code. Should be between 100 and 599.
|
15
|
+
# @param [String] body the HTTP response body.
|
7
16
|
def initialize(code, body)
|
8
17
|
@code = code.to_i
|
9
18
|
@body = body
|
10
19
|
end
|
11
20
|
|
21
|
+
# @return [Boolean] whether or not the response code was awesome.
|
12
22
|
def awesome?
|
13
23
|
AwesomeResponseCodes.include?(code)
|
14
24
|
end
|
15
25
|
|
26
|
+
# @return [Boolean] whether or not the response code was not awesome.
|
16
27
|
def not_awesome?
|
17
28
|
!awesome?
|
18
29
|
end
|
data/lib/httpalooza/version.rb
CHANGED