httparty_with_cookies 0.1.0
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/httparty-with-cookies.gemspec +16 -0
- data/lib/httparty_with_cookies.rb +53 -0
- metadata +95 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
SPEC = Gem::Specification.new do |s|
|
2
|
+
s.name = 'httparty_with_cookies'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
5
|
+
s.author = 'Arthur Silva'
|
6
|
+
s.summary = 'Basic automatic cookie handling for HTTParty'
|
7
|
+
s.email = 'awls99@gmail.com'
|
8
|
+
s.homepage = 'https://github.com/awls99/httparty-with-cookies'
|
9
|
+
s.description = 'This gem works mostly as HTTParty, but has automatic saving and sending of cookies to the server.'
|
10
|
+
s.add_dependency 'httparty'
|
11
|
+
s.add_development_dependency 'rspec'
|
12
|
+
s.add_development_dependency 'sinatra'
|
13
|
+
s.files = Dir.glob("{lib}/*").push __FILE__
|
14
|
+
s.require_path = 'lib'
|
15
|
+
s.has_rdoc = false
|
16
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module HTTParty_with_cookies
|
4
|
+
# include HTTParty
|
5
|
+
attr :cookies
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend HTTParty
|
9
|
+
base.send :include, HTTParty
|
10
|
+
end
|
11
|
+
|
12
|
+
#####this way we can support the same http verbs as httparty
|
13
|
+
HTTParty::Request::SupportedHTTPMethods.each do | netclass |
|
14
|
+
method_sym = netclass.to_s.split('::').last.downcase.to_sym
|
15
|
+
define_method method_sym do |uri, options={}, &block|
|
16
|
+
|
17
|
+
base_headers = {'Cookie' => request_cookies}
|
18
|
+
if options[:headers]
|
19
|
+
options[:headers] = base_headers.merge options[:headers]
|
20
|
+
else
|
21
|
+
options[:headers] = base_headers
|
22
|
+
end
|
23
|
+
options[:headers] = options[:headers].delete_if{|k,v| v == {}}
|
24
|
+
@last_response = self.class.method( method_sym ).call uri, options, &block
|
25
|
+
set_cookies
|
26
|
+
return @last_response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def request_cookies
|
32
|
+
URI.unescape( @cookies.to_a.map do |cookie|
|
33
|
+
cookie.join('=')
|
34
|
+
end.join(';') )
|
35
|
+
end
|
36
|
+
def set_cookies #ugly hack to get the correct cookie array from the headers
|
37
|
+
response_cookies = @last_response.headers.instance_variable_get(:@header)['set-cookie']
|
38
|
+
return unless response_cookies and !response_cookies.empty?
|
39
|
+
response_cookies = [ response_cookies ] if response_cookies.is_a? String
|
40
|
+
response_cookies.each do |cookie|
|
41
|
+
add_cookies( cookie.split(';')[0] )
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def add_cookies *cookies
|
47
|
+
@cookies||= {}
|
48
|
+
cookies.each do |cookie|
|
49
|
+
key, value = cookie.split '='
|
50
|
+
@cookies[ key ] = value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: httparty_with_cookies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Arthur Silva
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: sinatra
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: This gem works mostly as HTTParty, but has automatic saving and sending
|
63
|
+
of cookies to the server.
|
64
|
+
email: awls99@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/httparty_with_cookies.rb
|
70
|
+
- httparty-with-cookies.gemspec
|
71
|
+
homepage: https://github.com/awls99/httparty-with-cookies
|
72
|
+
licenses: []
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.24
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Basic automatic cookie handling for HTTParty
|
95
|
+
test_files: []
|