maedana-httpclient 2.1.5.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+ # HTTPClient - HTTP client library.
2
+ # Copyright (C) 2000-2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
+ #
4
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5
+ # redistribute it and/or modify it under the same terms of Ruby's license;
6
+ # either the dual license version in 2003, or any later version.
7
+
8
+
9
+ require 'uri'
10
+
11
+
12
+ unless ''.respond_to?(:bytesize)
13
+ class String
14
+ alias bytesize size
15
+ end
16
+ end
17
+
18
+
19
+ class HTTPClient
20
+
21
+
22
+ # A module for common function.
23
+ module Util
24
+ # Keyword argument helper.
25
+ # args:: given arguments.
26
+ # *field:: a list of arguments to be extracted.
27
+ #
28
+ # You can extract 3 arguments (a, b, c) with:
29
+ #
30
+ # include Util
31
+ # def my_method(*args)
32
+ # a, b, c = keyword_argument(args, :a, :b, :c)
33
+ # ...
34
+ # end
35
+ # my_method(1, 2, 3)
36
+ # my_method(:b => 2, :a = 1)
37
+ #
38
+ # instead of;
39
+ #
40
+ # def my_method(a, b, c)
41
+ # ...
42
+ # end
43
+ #
44
+ def keyword_argument(args, *field)
45
+ if args.size == 1 and args[0].is_a?(Hash)
46
+ args[0].values_at(*field)
47
+ else
48
+ args
49
+ end
50
+ end
51
+
52
+ # Gets an URI instance.
53
+ def urify(uri)
54
+ if uri.nil?
55
+ nil
56
+ elsif uri.is_a?(URI)
57
+ uri
58
+ else
59
+ URI.parse(uri.to_s)
60
+ end
61
+ end
62
+
63
+ # Returns true if the given 2 URIs have a part_of relationship.
64
+ # * the same scheme
65
+ # * the same host String (no host resolution or IP-addr conversion)
66
+ # * the same port number
67
+ # * target URI's path starts with base URI's path.
68
+ def uri_part_of(uri, part)
69
+ ((uri.scheme == part.scheme) and
70
+ (uri.host == part.host) and
71
+ (uri.port == part.port) and
72
+ uri.path.upcase.index(part.path.upcase) == 0)
73
+ end
74
+ module_function :uri_part_of
75
+
76
+ # Returns parent directory URI of the given URI.
77
+ def uri_dirname(uri)
78
+ uri = uri.clone
79
+ uri.path = uri.path.sub(/\/[^\/]*\z/, '/')
80
+ uri
81
+ end
82
+ module_function :uri_dirname
83
+
84
+ # Finds a value of a Hash.
85
+ def hash_find_value(hash, &block)
86
+ v = hash.find(&block)
87
+ v ? v[1] : nil
88
+ end
89
+ module_function :hash_find_value
90
+ end
91
+
92
+
93
+ end
@@ -0,0 +1,80 @@
1
+ # HTTPClient - HTTP client library.
2
+ # Copyright (C) 2000-2009 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
+ #
4
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5
+ # redistribute it and/or modify it under the same terms of Ruby's license;
6
+ # either the dual license version in 2003, or any later version.
7
+
8
+
9
+ require 'httpclient'
10
+
11
+ module HTTP
12
+ class Message
13
+ attr_accessor :oauth_params
14
+ end
15
+ end
16
+
17
+
18
+ # OAuthClient provides OAuth related methods in addition to HTTPClient.
19
+ #
20
+ # TODO
21
+ class OAuthClient < HTTPClient
22
+ attr_accessor :oauth_config
23
+
24
+ def initialize(*arg)
25
+ super
26
+ @oauth_config = HTTPClient::OAuth::Config.new
27
+ self.www_auth.oauth.set_config(nil, @oauth_config)
28
+ self.www_auth.oauth.challenge(nil)
29
+ end
30
+
31
+ def get_request_token(uri, callback = nil, param = nil)
32
+ oauth_config.token = nil
33
+ oauth_config.secret = nil
34
+ oauth_config.callback = callback
35
+ oauth_config.verifier = nil
36
+ res = request(oauth_config.http_method, uri, param)
37
+ filter_response(res)
38
+ res
39
+ end
40
+
41
+ def get_access_token(uri, request_token, request_token_secret, verifier = nil)
42
+ oauth_config.token = request_token
43
+ oauth_config.secret = request_token_secret
44
+ oauth_config.callback = nil
45
+ oauth_config.verifier = verifier
46
+ res = request(oauth_config.http_method, uri)
47
+ filter_response(res)
48
+ res
49
+ end
50
+
51
+ private
52
+
53
+ def unescape(escaped)
54
+ ::HTTPClient::HTTP::Message.unescape(escaped)
55
+ end
56
+
57
+ def filter_response(res)
58
+ if res.status == 200
59
+ if res.oauth_params = get_oauth_response(res)
60
+ oauth_config.token = res.oauth_params['oauth_token']
61
+ oauth_config.secret = res.oauth_params['oauth_token_secret']
62
+ end
63
+ end
64
+ end
65
+
66
+ def get_oauth_response(res)
67
+ enc = res.header['content-encoding']
68
+ body = nil
69
+ if enc and enc[0] and enc[0].downcase == 'gzip'
70
+ body = Zlib::GzipReader.wrap(StringIO.new(res.content)) { |gz| gz.read }
71
+ else
72
+ body = res.content
73
+ end
74
+ body.split('&').inject({}) { |r, e|
75
+ key, value = e.split('=', 2)
76
+ r[unescape(key)] = unescape(value)
77
+ r
78
+ }
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maedana-httpclient
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.5.2.1
5
+ platform: ruby
6
+ authors:
7
+ - NAKAMURA, Hiroshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-18 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: nahi@ruby-lang.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/httpclient/http.rb
26
+ - lib/httpclient/ssl_config.rb
27
+ - lib/httpclient/auth.rb
28
+ - lib/httpclient/cacert.p7s
29
+ - lib/httpclient/cacert_sha1.p7s
30
+ - lib/httpclient/timeout.rb
31
+ - lib/httpclient/connection.rb
32
+ - lib/httpclient/cookie.rb
33
+ - lib/httpclient/util.rb
34
+ - lib/httpclient/session.rb
35
+ - lib/oauthclient.rb
36
+ - lib/http-access2.rb
37
+ - lib/http-access2/http.rb
38
+ - lib/http-access2/cookie.rb
39
+ - lib/httpclient.rb
40
+ has_rdoc: true
41
+ homepage: http://dev.ctor.org/httpclient
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.5
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: gives something like the functionality of libwww-perl (LWP) in Ruby
68
+ test_files: []
69
+