oauth-multipart 0.0.1

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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = OauthMultipart
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'OauthMultipart'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module OauthMultipart
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,69 @@
1
+ module OauthMultipart
2
+ end
3
+
4
+ OAuth::Consumer.class_eval do
5
+ def create_http_request_with_multipart(http_method, path, *arguments)
6
+ http_method = http_method.to_sym
7
+
8
+ if [:post, :put].include?(http_method)
9
+ data = arguments.shift
10
+ end
11
+
12
+ # if the base site contains a path, add it now
13
+ uri = URI.parse(site)
14
+ path = uri.path + path if uri.path
15
+
16
+ headers = arguments.first.is_a?(Hash) ? arguments.shift : {}
17
+
18
+ case http_method
19
+ when :post
20
+ request = Net::HTTP::Post.new(path,headers)
21
+ request["Content-Length"] = '0' # Default to 0
22
+ when :put
23
+ request = Net::HTTP::Put.new(path,headers)
24
+ request["Content-Length"] = '0' # Default to 0
25
+ when :get
26
+ request = Net::HTTP::Get.new(path,headers)
27
+ when :delete
28
+ request = Net::HTTP::Delete.new(path,headers)
29
+
30
+ when :head
31
+ request = Net::HTTP::Head.new(path,headers)
32
+ when :multipart_post
33
+ request = Net::HTTP::Post::Multipart.new(path, headers)
34
+ else
35
+ raise ArgumentError, "Don't know how to handle http_method: :#{http_method.to_s}"
36
+ end
37
+
38
+ if data.is_a?(Hash)
39
+ form_data = {}
40
+ data.each {|k,v| form_data[k.to_s] = v if !v.nil?}
41
+ request.set_form_data(form_data)
42
+ elsif data
43
+ if data.respond_to?(:read)
44
+ request.body_stream = data
45
+ if data.respond_to?(:length)
46
+ request["Content-Length"] = data.length.to_s
47
+ elsif data.respond_to?(:stat) && data.stat.respond_to?(:size)
48
+ request["Content-Length"] = data.stat.size.to_s
49
+ else
50
+ raise ArgumentError, "Don't know how to send a body_stream that doesn't respond to .length or .stat.size"
51
+ end
52
+ else
53
+ request.body = data.to_s
54
+ request["Content-Length"] = request.body.length.to_s
55
+ end
56
+ end
57
+
58
+ request
59
+
60
+ end
61
+
62
+ alias_method_chain :create_http_request,:multipart
63
+ end
64
+
65
+ OAuth::AccessToken.class_eval do
66
+ def multipart_post(*args)
67
+ request(:multipart_post,*args)
68
+ end
69
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :oauth-multipart do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class OauthMultipartTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, OauthMultipart
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth-multipart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - aotianlong
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth
16
+ requirement: &70258169901760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70258169901760
25
+ - !ruby/object:Gem::Dependency
26
+ name: multipart-post
27
+ requirement: &70258169901080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70258169901080
36
+ - !ruby/object:Gem::Dependency
37
+ name: sqlite3
38
+ requirement: &70258169900560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70258169900560
47
+ description: Let oauth support file upload
48
+ email:
49
+ - aotianlong@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/oauth-multipart/version.rb
55
+ - lib/oauth-multipart.rb
56
+ - lib/tasks/oauth-multipart_tasks.rake
57
+ - MIT-LICENSE
58
+ - Rakefile
59
+ - README.rdoc
60
+ - test/oauth-multipart_test.rb
61
+ - test/test_helper.rb
62
+ homepage: http://www.powerapple.com
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.15
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Let oauth support file upload
86
+ test_files:
87
+ - test/oauth-multipart_test.rb
88
+ - test/test_helper.rb