nestful 0.0.8 → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.markdown +11 -37
- data/Rakefile +1 -14
- data/examples/resource.rb +6 -0
- data/lib/nestful/.DS_Store +0 -0
- data/lib/nestful/connection.rb +107 -245
- data/lib/nestful/endpoint.rb +42 -0
- data/lib/nestful/exceptions.rb +1 -1
- data/lib/nestful/formats/form_format.rb +3 -3
- data/lib/nestful/formats/json_format.rb +10 -9
- data/lib/nestful/formats/multipart_format.rb +9 -8
- data/lib/nestful/formats.rb +19 -16
- data/lib/nestful/helpers.rb +41 -0
- data/lib/nestful/request.rb +73 -96
- data/lib/nestful/resource.rb +144 -27
- data/lib/nestful/response/headers.rb +31 -0
- data/lib/nestful/response.rb +47 -0
- data/lib/nestful/version.rb +3 -0
- data/lib/nestful.rb +17 -30
- data/nestful.gemspec +14 -54
- metadata +21 -28
- data/lib/nestful/formats/blank_format.rb +0 -13
- data/lib/nestful/formats/text_format.rb +0 -17
- data/lib/nestful/formats/xml_format.rb +0 -34
- data/lib/nestful/oauth.rb +0 -24
- data/lib/nestful/request/callbacks.rb +0 -28
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/conversions'
|
2
|
-
|
3
|
-
module Nestful
|
4
|
-
module Formats
|
5
|
-
class XmlFormat < Format
|
6
|
-
def extension
|
7
|
-
'xml'
|
8
|
-
end
|
9
|
-
|
10
|
-
def mime_type
|
11
|
-
'application/xml'
|
12
|
-
end
|
13
|
-
|
14
|
-
def encode(hash, options={})
|
15
|
-
hash.to_xml(options)
|
16
|
-
end
|
17
|
-
|
18
|
-
def decode(xml)
|
19
|
-
from_xml_data(Hash.from_xml(xml))
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
# Manipulate from_xml Hash, because xml_simple is not exactly what we
|
24
|
-
# want for Active Resource.
|
25
|
-
def from_xml_data(data)
|
26
|
-
if data.is_a?(Hash) && data.keys.size == 1
|
27
|
-
data.values.first
|
28
|
-
else
|
29
|
-
data
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/lib/nestful/oauth.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'roauth'
|
2
|
-
|
3
|
-
module Nestful
|
4
|
-
class Request
|
5
|
-
attr_accessor :oauth
|
6
|
-
|
7
|
-
def oauth_sign
|
8
|
-
return unless oauth
|
9
|
-
params = method == :get ? self.params : {}
|
10
|
-
|
11
|
-
signature = ROAuth.header(
|
12
|
-
oauth,
|
13
|
-
uri.to_s,
|
14
|
-
params,
|
15
|
-
method
|
16
|
-
)
|
17
|
-
|
18
|
-
self.headers ||= {}
|
19
|
-
self.headers['Authorization'] = signature
|
20
|
-
end
|
21
|
-
|
22
|
-
before_request(&:oauth_sign)
|
23
|
-
end
|
24
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Nestful
|
2
|
-
class Request
|
3
|
-
module Callbacks
|
4
|
-
CALLBACKS = [
|
5
|
-
:before_request,
|
6
|
-
:after_request,
|
7
|
-
:progress
|
8
|
-
]
|
9
|
-
|
10
|
-
def self.included(base)
|
11
|
-
CALLBACKS.each do |callback|
|
12
|
-
base.instance_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
13
|
-
def #{callback}(method = nil, &block)
|
14
|
-
callbacks(:#{callback}) << (method||block)
|
15
|
-
end
|
16
|
-
EOS
|
17
|
-
|
18
|
-
base.class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
19
|
-
def #{callback}(method = nil, &block)
|
20
|
-
callbacks(:#{callback}) << (method||block)
|
21
|
-
end
|
22
|
-
alias_method :#{callback}=, :#{callback}
|
23
|
-
EOS
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|