httpclient-xaop 2.1.6

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.
@@ -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,81 @@
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
+ oauth_config.verifier = nil
49
+ res
50
+ end
51
+
52
+ def get_oauth_response(res)
53
+ enc = res.header['content-encoding']
54
+ body = nil
55
+ if enc and enc[0] and enc[0].downcase == 'gzip'
56
+ body = Zlib::GzipReader.wrap(StringIO.new(res.content)) { |gz| gz.read }
57
+ else
58
+ body = res.content
59
+ end
60
+ body.split('&').inject({}) { |r, e|
61
+ key, value = e.split('=', 2)
62
+ r[unescape(key)] = unescape(value)
63
+ r
64
+ }
65
+ end
66
+
67
+ private
68
+
69
+ def unescape(escaped)
70
+ escaped ? ::HTTP::Message.unescape(escaped) : nil
71
+ end
72
+
73
+ def filter_response(res)
74
+ if res.status == 200
75
+ if res.oauth_params = get_oauth_response(res)
76
+ oauth_config.token = res.oauth_params['oauth_token']
77
+ oauth_config.secret = res.oauth_params['oauth_token_secret']
78
+ end
79
+ end
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httpclient-xaop
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease: false
6
+ segments:
7
+ - 2
8
+ - 1
9
+ - 6
10
+ version: 2.1.6
11
+ platform: ruby
12
+ authors:
13
+ - NAKAMURA, Hiroshi
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-03-25 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: nahi@ruby-lang.org
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/http-access2/cookie.rb
32
+ - lib/http-access2/http.rb
33
+ - lib/http-access2.rb
34
+ - lib/httpclient/auth.rb
35
+ - lib/httpclient/cacert.p7s
36
+ - lib/httpclient/cacert_sha1.p7s
37
+ - lib/httpclient/connection.rb
38
+ - lib/httpclient/cookie.rb
39
+ - lib/httpclient/http.rb
40
+ - lib/httpclient/session.rb
41
+ - lib/httpclient/ssl_config.rb
42
+ - lib/httpclient/timeout.rb
43
+ - lib/httpclient/util.rb
44
+ - lib/httpclient.rb
45
+ - lib/oauthclient.rb
46
+ has_rdoc: true
47
+ homepage: http://dev.ctor.org/httpclient
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.7
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: gives something like the functionality of libwww-perl (LWP) in Ruby
80
+ test_files: []
81
+