api_smith 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/api_smith/client.rb +20 -0
- data/lib/api_smith/httparty_extensions.rb +23 -0
- data/lib/api_smith/version.rb +1 -1
- metadata +25 -10
data/lib/api_smith/client.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'httparty'
|
2
|
+
require 'net/http/persistent'
|
2
3
|
|
3
4
|
module APISmith
|
5
|
+
|
4
6
|
# A mixin providing the base set of functionality for building API clients.
|
5
7
|
#
|
6
8
|
# @see InstanceMethods
|
@@ -325,6 +327,24 @@ module APISmith
|
|
325
327
|
define_method(:endpoint) { value }
|
326
328
|
end
|
327
329
|
|
330
|
+
# Allows you to set a given endpoint as persistnet, using Net::HTTP::Persistent.
|
331
|
+
# @param [true,false] value when true, will be persisted. Otherwise, non-persistent.
|
332
|
+
# @param [String] name the name for the client in Net::HTTP::Persistent
|
333
|
+
# @example Making it persistent:
|
334
|
+
# persistent
|
335
|
+
# @example Persistent with a custom client name
|
336
|
+
# persistent true, 'my-client'
|
337
|
+
# @example Making it non-persistent
|
338
|
+
# persistent false
|
339
|
+
def persistent(value = true, name = 'api_smith')
|
340
|
+
if value
|
341
|
+
require 'api_smith/httparty_extensions'
|
342
|
+
default_options[:persistent] ||= Net::HTTP::Persistent.new(name)
|
343
|
+
else
|
344
|
+
default_options[:persistent] = nil
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
328
348
|
end
|
329
349
|
|
330
350
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Monkey patches HTTParty to accept persistent connections.
|
2
|
+
module HTTParty
|
3
|
+
class Request
|
4
|
+
|
5
|
+
alias _original_http http
|
6
|
+
def http
|
7
|
+
options[:persistent] || _original_http
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform
|
11
|
+
validate
|
12
|
+
setup_raw_request
|
13
|
+
self.last_response = perform_inner_request
|
14
|
+
handle_deflation
|
15
|
+
handle_response
|
16
|
+
end
|
17
|
+
|
18
|
+
def perform_inner_request
|
19
|
+
options[:persistent] ? http.request(uri, @raw_request) : http.request(@raw_request)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/api_smith/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_smith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Darcy Laycock
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2012-02-16 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: httparty
|
@@ -48,7 +48,7 @@ dependencies:
|
|
48
48
|
type: :runtime
|
49
49
|
version_requirements: *id002
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
|
-
name:
|
51
|
+
name: net-http-persistent
|
52
52
|
prerelease: false
|
53
53
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
@@ -59,12 +59,26 @@ dependencies:
|
|
59
59
|
segments:
|
60
60
|
- 0
|
61
61
|
version: "0"
|
62
|
-
type: :
|
62
|
+
type: :runtime
|
63
63
|
version_requirements: *id003
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
|
-
name:
|
65
|
+
name: rr
|
66
66
|
prerelease: false
|
67
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
type: :development
|
77
|
+
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
prerelease: false
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
68
82
|
none: false
|
69
83
|
requirements:
|
70
84
|
- - ~>
|
@@ -75,11 +89,11 @@ dependencies:
|
|
75
89
|
- 0
|
76
90
|
version: "2.0"
|
77
91
|
type: :development
|
78
|
-
version_requirements: *
|
92
|
+
version_requirements: *id005
|
79
93
|
- !ruby/object:Gem::Dependency
|
80
94
|
name: fuubar
|
81
95
|
prerelease: false
|
82
|
-
requirement: &
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
83
97
|
none: false
|
84
98
|
requirements:
|
85
99
|
- - ">="
|
@@ -89,7 +103,7 @@ dependencies:
|
|
89
103
|
- 0
|
90
104
|
version: "0"
|
91
105
|
type: :development
|
92
|
-
version_requirements: *
|
106
|
+
version_requirements: *id006
|
93
107
|
description: APISmith provides tools to make working with structured HTTP-based apis even easier.
|
94
108
|
email:
|
95
109
|
- sutto@thefrontiergroup.com.au
|
@@ -102,6 +116,7 @@ extra_rdoc_files: []
|
|
102
116
|
files:
|
103
117
|
- lib/api_smith/base.rb
|
104
118
|
- lib/api_smith/client.rb
|
119
|
+
- lib/api_smith/httparty_extensions.rb
|
105
120
|
- lib/api_smith/smash.rb
|
106
121
|
- lib/api_smith/version.rb
|
107
122
|
- lib/api_smith/web_mock_extensions.rb
|