resource_accessor 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGES +5 -1
- data/Gemfile +1 -3
- data/Gemfile.lock +14 -15
- data/README.md +58 -22
- data/Rakefile +11 -10
- data/lib/resource_accessor/resource_accessor.rb +17 -16
- data/lib/resource_accessor/version.rb +1 -1
- data/resource_accessor.gemspec +3 -1
- data/resource_accessor.gemspec.erb +2 -1
- metadata +12 -10
- data/.rvmrc +0 -4
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NTMwYmNlMGNkYzg1NWU5ZTFiZTk0ZGViZGYwY2U3ZjU5OTAzNTk0MDYxOWMx
|
10
|
-
MWFlYjgyZTA3MmM4OWRiZTcyYmIwZTI1OWUwYjliZDZhNTc3YzE2NTZmNTQ4
|
11
|
-
Y2IzNWFlNjUzNGMzZDdkMmM5YzM4NmI2MDc2MDU4N2NkZTZmOTk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Y2ExNDE5NGI3YWQ4NDkxMGJmZDBiZTVlMTFmY2M1ODk1NDk3Y2VhMDMzMjZi
|
14
|
-
MGUwOGJkMzBjMzAxNzNjOTA2ZTQ0YzliZjM4MjNiMGMyMzBkOGRiODEyZGUx
|
15
|
-
MTFiNjEwMzU5ZTliZjBjZjcyZmViYTQyMWQ0NzI0NmQyOWI2Yjk=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 32baacfc4e7a916204597ea8d1f6241e56c38807
|
4
|
+
data.tar.gz: a1994c6edd8045267b9ab688cf658edcd70bec12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afb238c1736db16a20a52b995b789bff9a3fbdc0989ecd174607972584ee87903d3071f0e5fcf69bbd22b7f49be2f8c456be6593f64aa075ac0c61c5e634acbe
|
7
|
+
data.tar.gz: b9e1d3c2f7069b857d86e9d4d4dbe42000055c79dc7344f3871df29ce5f5ddfc05709ca8d449b7362e80e727800bbccf631e08eb7ec431e6ae1f1c7da5678026
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
resource_accessor
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/CHANGES
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
GEM
|
2
|
-
remote:
|
2
|
+
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
diff-lcs (1.
|
5
|
-
file_utils (1.0.
|
4
|
+
diff-lcs (1.2.4)
|
5
|
+
file_utils (1.0.7)
|
6
6
|
gemcutter (0.7.1)
|
7
|
-
gemspec_deps_gen (1.
|
7
|
+
gemspec_deps_gen (1.1.2)
|
8
|
+
bundler
|
8
9
|
file_utils
|
9
10
|
metaclass (0.0.1)
|
10
|
-
mocha (0.
|
11
|
+
mocha (0.14.0)
|
11
12
|
metaclass (~> 0.0.1)
|
12
|
-
rspec (2.
|
13
|
-
rspec-core (~> 2.
|
14
|
-
rspec-expectations (~> 2.
|
15
|
-
rspec-mocks (~> 2.
|
16
|
-
rspec-core (2.
|
17
|
-
rspec-expectations (2.
|
18
|
-
diff-lcs (
|
19
|
-
rspec-mocks (2.
|
13
|
+
rspec (2.14.1)
|
14
|
+
rspec-core (~> 2.14.0)
|
15
|
+
rspec-expectations (~> 2.14.0)
|
16
|
+
rspec-mocks (~> 2.14.0)
|
17
|
+
rspec-core (2.14.5)
|
18
|
+
rspec-expectations (2.14.2)
|
19
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
20
|
+
rspec-mocks (2.14.3)
|
20
21
|
|
21
22
|
PLATFORMS
|
22
23
|
ruby
|
@@ -26,5 +27,3 @@ DEPENDENCIES
|
|
26
27
|
gemspec_deps_gen
|
27
28
|
mocha
|
28
29
|
rspec
|
29
|
-
rspec-core
|
30
|
-
rspec-expectations
|
data/README.md
CHANGED
@@ -12,41 +12,77 @@ And then execute:
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
+
Create accessor object:
|
16
|
+
|
15
17
|
```ruby
|
16
|
-
|
18
|
+
require 'resource_accessor'
|
19
|
+
|
20
|
+
accessor = ResourceAccessor.new
|
21
|
+
```
|
22
|
+
|
23
|
+
If you want to access unprotected resource located at **some_url**:
|
17
24
|
|
18
|
-
|
25
|
+
```ruby
|
26
|
+
response = accessor.get_response :url => some_url
|
27
|
+
```
|
19
28
|
|
20
|
-
|
21
|
-
response = accessor.get_response :url => some_url
|
29
|
+
If you want to get protected resource, first get a cookie and then access protected resource:
|
22
30
|
|
23
|
-
|
24
|
-
|
31
|
+
```ruby
|
32
|
+
# 1. Get cookie
|
25
33
|
|
26
|
-
|
27
|
-
response = accessor.get_response :url => some_url, :method => :post, :cookie => cookie,
|
28
|
-
:body => some_hash
|
34
|
+
cookie = accessor.get_cookie login_url, user_name, password
|
29
35
|
|
30
|
-
|
31
|
-
response = accessor.get_response :url => some_url, :method => :post, :cookie => cookie,
|
32
|
-
:body => some_string
|
36
|
+
# 2.a. Get protected resource through POST and post body as hash
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
# or
|
37
|
-
response = accessor.get_response {:url => some_url}, {'X-Requested-With' => 'XMLHttpRequest'}
|
38
|
+
response = accessor.get_response :url => some_url, :method => :post, :cookie => cookie,
|
39
|
+
:body => some_hash
|
38
40
|
|
39
|
-
|
40
|
-
response = accessor.get_soap_response :url => some_url
|
41
|
-
# or
|
42
|
-
response = accessor.get_response {:url => some_url}, {'SOAPAction' => 'someSoapOperation', 'Content-Type' => 'text/xml;charset=UTF-8'}
|
41
|
+
# 2.b. Get protected resource through POST and post body as string
|
43
42
|
|
44
|
-
|
45
|
-
|
43
|
+
response = accessor.get_response :url => some_url, :method => :post, :cookie => cookie,
|
44
|
+
:body => some_string
|
45
|
+
```
|
46
|
+
You have to specify HTTP method explicitly here (post).
|
46
47
|
|
48
|
+
If you want to get AJAX resource, add special header to the request or use special method:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
response1 = accessor.get_response {:url => some_url}, {'X-Requested-With' => 'XMLHttpRequest'}
|
52
|
+
|
53
|
+
response2 = accessor.get_ajax_response :url => some_url
|
54
|
+
```
|
55
|
+
|
56
|
+
If you want to get SOAP resource, same as before, add special header to the request or use special method:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
response1 = accessor.get_response {:url => some_url}, {'SOAPAction' => 'someSoapOperation', 'Content-Type' => 'text/xml;charset=UTF-8'}
|
47
60
|
|
61
|
+
response2 = accessor.get_soap_response :url => some_url
|
48
62
|
```
|
49
63
|
|
64
|
+
If you want to get JSON resource, same as before, add special header to the request or use special method:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
response = accessor.get_response {:url => some_url}, {'Content-Type" => "application/json;charset=UTF-8'}
|
68
|
+
|
69
|
+
response2 = accessor.get_json_response :url => some_url
|
70
|
+
```
|
71
|
+
|
72
|
+
You can setup timeout for your accessor object in milliseconds:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
accessor.timeout = 10000
|
76
|
+
```
|
77
|
+
|
78
|
+
If you need to work over ssl enable certificate validation before the call:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
accessor.validate_ssl_cert = true
|
82
|
+
accessor.ca_file = 'your cert file location'
|
83
|
+
```
|
84
|
+
|
85
|
+
|
50
86
|
## Contributing
|
51
87
|
|
52
88
|
1. Fork it
|
data/Rakefile
CHANGED
@@ -6,20 +6,16 @@ require "rspec/core/rake_task"
|
|
6
6
|
require "resource_accessor/version"
|
7
7
|
require "gemspec_deps_gen/gemspec_deps_gen"
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def project_name
|
14
|
-
File.basename(Dir.pwd)
|
15
|
-
end
|
9
|
+
version = ResourceAccessor::VERSION
|
10
|
+
project_name = File.basename(Dir.pwd)
|
16
11
|
|
17
|
-
task :
|
18
|
-
system "rm #{project_name}.gemspec"
|
12
|
+
task :gen do
|
19
13
|
generator = GemspecDepsGen.new
|
20
14
|
|
21
|
-
generator.generate_dependencies "#{project_name}.gemspec.erb", "#{project_name}.gemspec"
|
15
|
+
generator.generate_dependencies "spec", "#{project_name}.gemspec.erb", "#{project_name}.gemspec"
|
16
|
+
end
|
22
17
|
|
18
|
+
task :build => :gen do
|
23
19
|
system "gem build #{project_name}.gemspec"
|
24
20
|
end
|
25
21
|
|
@@ -27,6 +23,10 @@ task :install do
|
|
27
23
|
system "gem install #{project_name}-#{version}.gem"
|
28
24
|
end
|
29
25
|
|
26
|
+
task :uninstall do
|
27
|
+
system "gem uninstall #{project_name}"
|
28
|
+
end
|
29
|
+
|
30
30
|
task :release => :build do
|
31
31
|
system "gem push #{project_name}-#{version}.gem"
|
32
32
|
end
|
@@ -35,3 +35,4 @@ RSpec::Core::RakeTask.new do |task|
|
|
35
35
|
task.pattern = 'spec/**/*_spec.rb'
|
36
36
|
task.verbose = false
|
37
37
|
end
|
38
|
+
|
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'net/https'
|
2
2
|
|
3
|
-
require 'system_timer' if RUBY_VERSION.to_f < 1.9 and RUBY_PLATFORM != 'java'
|
4
|
-
|
5
3
|
class ResourceAccessor
|
6
|
-
|
4
|
+
attr_accessor :timeout, :ca_file, :validate_ssl_cert
|
5
|
+
|
6
|
+
def initialize timeout = 10000, ca_file = nil, validate_ssl_cert = false
|
7
|
+
@timeout = timeout
|
8
|
+
@ca_file = ca_file
|
9
|
+
@validate_ssl_cert = validate_ssl_cert
|
10
|
+
end
|
7
11
|
|
8
12
|
def get_response params, headers = {}
|
9
13
|
locate_response(params[:url], params[:method], headers, params[:body], params[:cookie])
|
@@ -23,6 +27,12 @@ class ResourceAccessor
|
|
23
27
|
locate_response(params[:url], params[:method], headers, params[:body], params[:cookie])
|
24
28
|
end
|
25
29
|
|
30
|
+
def get_json_response params, headers = {}
|
31
|
+
headers["Content-Type"] = "application/json;charset=UTF-8"
|
32
|
+
|
33
|
+
locate_response(params[:url], params[:method], headers, params[:body], params[:cookie])
|
34
|
+
end
|
35
|
+
|
26
36
|
def get_cookie url, user_name, password
|
27
37
|
headers = {"Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8"}
|
28
38
|
|
@@ -85,25 +95,16 @@ class ResourceAccessor
|
|
85
95
|
request = Net::HTTP::Get.new(uri.request_uri, headers)
|
86
96
|
end
|
87
97
|
|
88
|
-
connection.read_timeout = timeout
|
89
|
-
connection.open_timeout = timeout
|
90
|
-
|
91
|
-
timeout_class = defined?(SystemTimer) ? SystemTimer : Timeout
|
98
|
+
connection.read_timeout = timeout
|
99
|
+
connection.open_timeout = timeout
|
92
100
|
|
93
|
-
|
101
|
+
Timeout.timeout(timeout) do
|
94
102
|
return connection.request(request)
|
95
103
|
end
|
96
104
|
end
|
97
105
|
|
98
106
|
def validate_ssl_cert?
|
99
|
-
|
107
|
+
validate_ssl_cert
|
100
108
|
end
|
101
109
|
|
102
|
-
def ca_file
|
103
|
-
nil
|
104
|
-
end
|
105
|
-
|
106
|
-
def timeout
|
107
|
-
10000
|
108
|
-
end
|
109
110
|
end
|
data/resource_accessor.gemspec
CHANGED
@@ -14,9 +14,11 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
spec.version = ResourceAccessor::VERSION
|
17
|
+
spec.license = "MIT"
|
17
18
|
|
19
|
+
|
18
20
|
spec.add_development_dependency "gemspec_deps_gen", [">= 0"]
|
19
21
|
spec.add_development_dependency "gemcutter", [">= 0"]
|
20
|
-
|
22
|
+
|
21
23
|
end
|
22
24
|
|
@@ -14,7 +14,8 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
spec.version = ResourceAccessor::VERSION
|
17
|
+
spec.license = "MIT"
|
17
18
|
|
18
|
-
<%=
|
19
|
+
<%= project_dependencies %>
|
19
20
|
end
|
20
21
|
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resource_accessor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Shvets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gemspec_deps_gen
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: gemcutter
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: This library is used to simplify access to protected or unprotected http
|
@@ -48,7 +48,8 @@ files:
|
|
48
48
|
- .gitignore
|
49
49
|
- .idea/dictionaries/alex.xml
|
50
50
|
- .idea/scopes/scope_settings.xml
|
51
|
-
- .
|
51
|
+
- .ruby-gemset
|
52
|
+
- .ruby-version
|
52
53
|
- CHANGES
|
53
54
|
- Gemfile
|
54
55
|
- Gemfile.lock
|
@@ -63,7 +64,8 @@ files:
|
|
63
64
|
- spec/resource_accessor_spec.rb
|
64
65
|
- spec/spec_helper.rb
|
65
66
|
homepage: http://github.com/shvets/resource_accessor
|
66
|
-
licenses:
|
67
|
+
licenses:
|
68
|
+
- MIT
|
67
69
|
metadata: {}
|
68
70
|
post_install_message:
|
69
71
|
rdoc_options: []
|
@@ -71,12 +73,12 @@ require_paths:
|
|
71
73
|
- lib
|
72
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
75
|
requirements:
|
74
|
-
- -
|
76
|
+
- - '>='
|
75
77
|
- !ruby/object:Gem::Version
|
76
78
|
version: '0'
|
77
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
80
|
requirements:
|
79
|
-
- -
|
81
|
+
- - '>='
|
80
82
|
- !ruby/object:Gem::Version
|
81
83
|
version: '0'
|
82
84
|
requirements: []
|
data/.rvmrc
DELETED