nestful 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/nestful.rb +11 -11
- data/lib/nestful/connection.rb +4 -4
- data/lib/nestful/formats.rb +5 -5
- data/lib/nestful/formats/blank_format.rb +1 -1
- data/lib/nestful/formats/form_format.rb +1 -1
- data/lib/nestful/formats/json_format.rb +2 -2
- data/lib/nestful/formats/multipart_format.rb +4 -4
- data/lib/nestful/formats/text_format.rb +1 -1
- data/lib/nestful/formats/xml_format.rb +2 -2
- data/lib/nestful/oauth.rb +2 -2
- data/lib/nestful/request.rb +46 -38
- data/lib/nestful/resource.rb +4 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/lib/nestful.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'tempfile'
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
require 'active_support/inflector'
|
7
7
|
|
8
8
|
$:.unshift(File.dirname(__FILE__))
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
10
|
+
require 'nestful/exceptions'
|
11
|
+
require 'nestful/formats'
|
12
|
+
require 'nestful/connection'
|
13
|
+
require 'nestful/request/callbacks'
|
14
|
+
require 'nestful/request'
|
15
|
+
require 'nestful/resource'
|
16
16
|
|
17
17
|
module Nestful
|
18
18
|
extend self
|
data/lib/nestful/connection.rb
CHANGED
@@ -7,11 +7,11 @@ module Nestful
|
|
7
7
|
class Connection
|
8
8
|
|
9
9
|
HTTP_FORMAT_HEADER_NAMES = {
|
10
|
-
:get
|
11
|
-
:put
|
12
|
-
:post
|
10
|
+
:get => 'Accept',
|
11
|
+
:put => 'Content-Type',
|
12
|
+
:post => 'Content-Type',
|
13
13
|
:delete => 'Accept',
|
14
|
-
:head
|
14
|
+
:head => 'Accept'
|
15
15
|
}
|
16
16
|
|
17
17
|
attr_reader :site, :user, :password, :auth_type, :timeout, :proxy, :ssl_options
|
data/lib/nestful/formats.rb
CHANGED
@@ -14,12 +14,12 @@ module Nestful
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
autoload :BlankFormat,
|
18
|
-
autoload :TextFormat,
|
17
|
+
autoload :BlankFormat, 'nestful/formats/blank_format'
|
18
|
+
autoload :TextFormat, 'nestful/formats/text_format'
|
19
19
|
autoload :MultipartFormat, 'nestful/formats/multipart_format'
|
20
|
-
autoload :FormFormat,
|
21
|
-
autoload :XmlFormat,
|
22
|
-
autoload :JsonFormat,
|
20
|
+
autoload :FormFormat, 'nestful/formats/form_format'
|
21
|
+
autoload :XmlFormat, 'nestful/formats/xml_format'
|
22
|
+
autoload :JsonFormat, 'nestful/formats/json_format'
|
23
23
|
|
24
24
|
# Lookup the format class from a mime type reference symbol. Example:
|
25
25
|
#
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'securerandom'
|
2
2
|
|
3
3
|
module Nestful
|
4
4
|
module Formats
|
@@ -9,7 +9,7 @@ module Nestful
|
|
9
9
|
|
10
10
|
def initialize(*args)
|
11
11
|
super
|
12
|
-
@boundary =
|
12
|
+
@boundary = SecureRandom.hex(10)
|
13
13
|
@stream = Tempfile.new("nf.#{rand(1000)}")
|
14
14
|
@stream.binmode
|
15
15
|
end
|
@@ -72,8 +72,8 @@ module Nestful
|
|
72
72
|
def filename(body)
|
73
73
|
return body.original_filename if body.respond_to?(:original_filename)
|
74
74
|
return File.basename(body.path) if body.respond_to?(:path)
|
75
|
-
|
75
|
+
'Unknown'
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
-
end
|
79
|
+
end
|
data/lib/nestful/oauth.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'roauth'
|
2
2
|
|
3
3
|
module Nestful
|
4
4
|
class Request
|
@@ -16,7 +16,7 @@ module Nestful
|
|
16
16
|
)
|
17
17
|
|
18
18
|
self.headers ||= {}
|
19
|
-
self.headers[
|
19
|
+
self.headers['Authorization'] = signature
|
20
20
|
end
|
21
21
|
|
22
22
|
before_request(&:oauth_sign)
|
data/lib/nestful/request.rb
CHANGED
@@ -6,7 +6,7 @@ module Nestful
|
|
6
6
|
@callbacks[type] ||= []
|
7
7
|
end
|
8
8
|
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :options, :format, :url
|
10
10
|
attr_accessor :params, :body, :buffer, :method, :headers, :callbacks, :raw, :extension
|
11
11
|
|
12
12
|
# Connection options
|
@@ -14,20 +14,18 @@ module Nestful
|
|
14
14
|
|
15
15
|
def initialize(url, options = {})
|
16
16
|
@url = url.to_s
|
17
|
+
|
17
18
|
@options = options
|
18
|
-
@options.each
|
19
|
+
@options.each do |key, val|
|
19
20
|
method = "#{key}="
|
20
21
|
send(method, val) if respond_to?(method)
|
21
|
-
|
22
|
+
end
|
23
|
+
|
22
24
|
self.method ||= :get
|
23
|
-
self.format ||= :blank
|
24
|
-
self.headers ||= {}
|
25
25
|
self.params ||= {}
|
26
|
+
self.headers ||= {}
|
26
27
|
self.body ||= ''
|
27
|
-
|
28
|
-
if self.uri.query
|
29
|
-
populate_query_params
|
30
|
-
end
|
28
|
+
self.format ||= :blank
|
31
29
|
end
|
32
30
|
|
33
31
|
def format=(mime_or_format)
|
@@ -46,17 +44,33 @@ module Nestful
|
|
46
44
|
conn
|
47
45
|
end
|
48
46
|
|
47
|
+
def url=(value)
|
48
|
+
@url = value
|
49
|
+
@uri = nil
|
50
|
+
@url
|
51
|
+
end
|
52
|
+
|
49
53
|
def uri
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
return @uri if @uri
|
55
|
+
|
56
|
+
url = @url.match(/^http/) ? @url : "http://#{@url}"
|
57
|
+
|
58
|
+
@uri = URI.parse(url)
|
59
|
+
@uri.path = "/" if @uri.path.empty?
|
60
|
+
|
53
61
|
if extension
|
54
62
|
extension = format.extension if extension.is_a?(Boolean)
|
55
|
-
uri.path += ".#{extension}"
|
56
|
-
end
|
57
|
-
|
63
|
+
@uri.path += ".#{extension}"
|
64
|
+
end
|
65
|
+
|
66
|
+
@uri.query.split("&").each do |res|
|
67
|
+
key, value = res.split("=")
|
68
|
+
@params[key] = value
|
69
|
+
end if @uri.query
|
70
|
+
|
71
|
+
@uri
|
58
72
|
end
|
59
|
-
|
73
|
+
|
60
74
|
def path
|
61
75
|
uri.path
|
62
76
|
end
|
@@ -74,23 +88,26 @@ module Nestful
|
|
74
88
|
callback(:before_request, self)
|
75
89
|
result = nil
|
76
90
|
if [:post, :put].include?(method)
|
77
|
-
connection.send(method, path, encoded, headers)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
91
|
+
connection.send(method, path, encoded, headers) do |res|
|
92
|
+
result = decoded(res)
|
93
|
+
result.class_eval { attr_accessor :response }
|
94
|
+
result.response = res
|
95
|
+
end
|
82
96
|
else
|
83
|
-
connection.send(method, query_path, headers)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
97
|
+
connection.send(method, query_path, headers) do |res|
|
98
|
+
result = decoded(res)
|
99
|
+
result.class_eval { attr_accessor :response }
|
100
|
+
result.response = res
|
101
|
+
end
|
88
102
|
end
|
89
103
|
callback(:after_request, self, result)
|
90
104
|
result
|
105
|
+
rescue Redirection => error
|
106
|
+
self.url = error.response['Location']
|
107
|
+
execute
|
91
108
|
end
|
92
109
|
|
93
|
-
protected
|
110
|
+
protected
|
94
111
|
def encoded
|
95
112
|
params.any? ? format.encode(params) : body
|
96
113
|
end
|
@@ -101,10 +118,10 @@ module Nestful
|
|
101
118
|
size = 0
|
102
119
|
total = result.content_length
|
103
120
|
|
104
|
-
result.read_body
|
121
|
+
result.read_body do |chunk|
|
105
122
|
callback(:progress, self, total, size += chunk.size)
|
106
123
|
data.write(chunk)
|
107
|
-
|
124
|
+
end
|
108
125
|
|
109
126
|
data.rewind
|
110
127
|
data
|
@@ -115,15 +132,6 @@ module Nestful
|
|
115
132
|
end
|
116
133
|
end
|
117
134
|
|
118
|
-
def populate_query_params
|
119
|
-
uri_query = self.uri.query.split("&").inject({}) {|hash, res|
|
120
|
-
key, value = res.split("=")
|
121
|
-
hash[key] = value
|
122
|
-
hash
|
123
|
-
}
|
124
|
-
self.params.merge!(uri_query)
|
125
|
-
end
|
126
|
-
|
127
135
|
def callbacks(type = nil)
|
128
136
|
@callbacks ||= {}
|
129
137
|
return @callbacks unless type
|
data/lib/nestful/resource.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nestful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70352776847120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 3.0.0.beta
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70352776847120
|
25
25
|
description: Simple Ruby HTTP/REST client with a sane API
|
26
26
|
email: info@eribium.org
|
27
27
|
executables: []
|