nestful 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -70,6 +70,13 @@ Connection options:
70
70
  ### Multipart post
71
71
 
72
72
  Nestful.post 'http://example.com', :format => :multipart, :params => {:file => File.open('README')}
73
+
74
+ ### OAuth
75
+
76
+ Nestful uses ROAuth for OAuth support - check out supported options: http://github.com/maccman/roauth
77
+
78
+ require 'nestful/oauth'
79
+ Nestful.get 'http://example.com', :oauth => {}
73
80
 
74
81
  ## Credits
75
82
  Large parts of the connection code were taken from ActiveResource
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -18,7 +18,7 @@ module Nestful
18
18
  %Q{multipart/form-data; boundary=#{boundary}}
19
19
  end
20
20
 
21
- def encode(params, options = nil, namespace = nil)
21
+ def encode(params, options = nil)
22
22
  to_multipart(params)
23
23
  stream.write("--" + boundary + "--" + EOL)
24
24
  stream.flush
@@ -0,0 +1,24 @@
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
@@ -13,7 +13,7 @@ module Nestful
13
13
  attr_accessor :proxy, :user, :password, :auth_type, :timeout, :ssl_options
14
14
 
15
15
  def initialize(url, options = {})
16
- @url = url
16
+ @url = url.to_s
17
17
  @options = options
18
18
  @options.each {|key, val|
19
19
  method = "#{key}="
@@ -50,12 +50,12 @@ module Nestful
50
50
  http_url = url.match(/^http/) ? url : "http://#{url}"
51
51
  uri = URI.parse(http_url)
52
52
  uri.path = "/" if uri.path.empty?
53
- if format && format.extension
53
+ if format && format.extension && !uri.path.match(/\..+/)
54
54
  uri.path += ".#{format.extension}"
55
55
  end
56
56
  uri
57
57
  end
58
-
58
+
59
59
  def path
60
60
  uri.path
61
61
  end
@@ -83,7 +83,7 @@ module Nestful
83
83
 
84
84
  protected
85
85
  def encoded
86
- format.encode(params.any? ? params : body)
86
+ params.any? ? format.encode(params) : body
87
87
  end
88
88
 
89
89
  def decoded(result)
data/nestful.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nestful}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex MacCaw"]
12
- s.date = %q{2010-08-23}
12
+ s.date = %q{2010-10-05}
13
13
  s.description = %q{Simple Ruby HTTP/REST client with a sane API}
14
14
  s.email = %q{info@eribium.org}
15
15
  s.extra_rdoc_files = [
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "lib/nestful/formats/json_format.rb",
31
31
  "lib/nestful/formats/multipart_format.rb",
32
32
  "lib/nestful/formats/xml_format.rb",
33
+ "lib/nestful/oauth.rb",
33
34
  "lib/nestful/request.rb",
34
35
  "lib/nestful/request/callbacks.rb",
35
36
  "lib/nestful/resource.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex MacCaw
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-23 00:00:00 +01:00
17
+ date: 2010-10-05 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -56,6 +56,7 @@ files:
56
56
  - lib/nestful/formats/json_format.rb
57
57
  - lib/nestful/formats/multipart_format.rb
58
58
  - lib/nestful/formats/xml_format.rb
59
+ - lib/nestful/oauth.rb
59
60
  - lib/nestful/request.rb
60
61
  - lib/nestful/request/callbacks.rb
61
62
  - lib/nestful/resource.rb