Class: FbRuby::Utils::Session
- Inherits:
-
Object
- Object
- FbRuby::Utils::Session
- Defined in:
- lib/FbRuby/utils.rb
Overview
requests Session
Constant Summary collapse
- @@default_user_agent =
"Mozilla/5.0 (Linux; Android 9; SM-N976V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.89 Mobile Safari/537.36"
- @@headers =
{'Accept-Encoding'=> 'gzip, deflate', 'Accept'=> '*/*', 'Connection'=> 'keep-alive'}
- @@facebook_exceptions =
true
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #delete(url, headers = {}, options = {}) ⇒ Object
- #get(url, params = {}, headers = {}, options = {}) ⇒ Object
- #get_cookie_dict ⇒ Object
- #get_cookie_hash ⇒ Object
- #get_cookie_str ⇒ Object
- #get_without_sessions(url) ⇒ Object
- #head(url, headers = {}, options = {}) ⇒ Object
-
#initialize(headers = {}, cookies = {}) ⇒ Session
constructor
A new instance of Session.
- #post(url, data = {}, headers = {}, options = {}) ⇒ Object
- #post_without_sessions(url, data = {}) ⇒ Object
- #put(url, data = {}, headers = {}, options = {}) ⇒ Object
Constructor Details
#initialize(headers = {}, cookies = {}) ⇒ Session
Returns a new instance of Session.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/FbRuby/utils.rb', line 107 def initialize(headers = {}, = {}) @headers = headers.empty? ? @@headers : headers if .instance_of?(Hash) @cookies = else @cookies = FbRuby::Utils::() end @options = { verify_ssl: true, max_redirects: 10, timeout: 30, open_timeout: 30, user_agent: @headers.member?('user-agent') ? @headers['user-agent'] : @@default_user_agent, follow_redirect: true} end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
105 106 107 |
# File 'lib/FbRuby/utils.rb', line 105 def @cookies end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
105 106 107 |
# File 'lib/FbRuby/utils.rb', line 105 def headers @headers end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
105 106 107 |
# File 'lib/FbRuby/utils.rb', line 105 def @options end |
Class Method Details
.default_headers ⇒ Object
96 97 98 |
# File 'lib/FbRuby/utils.rb', line 96 def default_headers return @@headers end |
.default_user_agent ⇒ Object
92 93 94 |
# File 'lib/FbRuby/utils.rb', line 92 def default_user_agent return @@default_user_agent end |
.facebook_exceptions ⇒ Object
100 101 102 |
# File 'lib/FbRuby/utils.rb', line 100 def facebook_exceptions return @@facebook_exceptions end |
Instance Method Details
#delete(url, headers = {}, options = {}) ⇒ Object
142 143 144 |
# File 'lib/FbRuby/utils.rb', line 142 def delete(url, headers = {}, = {}) request(:delete, url, {}, headers, nil, ) end |
#get(url, params = {}, headers = {}, options = {}) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/FbRuby/utils.rb', line 125 def get(url, params = {}, headers = {}, = {}) if params.length > 0 url = URI(url.to_s) url.query = URI.encode_www_form(params.to_a) end request(:get, url, {}, headers, nil, ) end |
#get_cookie_dict ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/FbRuby/utils.rb', line 166 def if @cookies.instance_of? (Hash) return @cookies else return FbRuby::Utils::(@cookies) end end |
#get_cookie_hash ⇒ Object
174 175 176 |
# File 'lib/FbRuby/utils.rb', line 174 def return end |
#get_cookie_str ⇒ Object
162 163 164 |
# File 'lib/FbRuby/utils.rb', line 162 def return FbRuby::Utils::(@cookies) end |
#get_without_sessions(url) ⇒ Object
150 151 152 |
# File 'lib/FbRuby/utils.rb', line 150 def get_without_sessions(url) return RestClient.get(url.to_s, cookies: @cookies) end |
#head(url, headers = {}, options = {}) ⇒ Object
146 147 148 |
# File 'lib/FbRuby/utils.rb', line 146 def head(url, headers = {}, = {}) request(:head, url, {}, headers, nil, ) end |
#post(url, data = {}, headers = {}, options = {}) ⇒ Object
134 135 136 |
# File 'lib/FbRuby/utils.rb', line 134 def post(url, data = {}, headers = {}, = {}) request(:post, url, {}, headers, data, ) end |
#post_without_sessions(url, data = {}) ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/FbRuby/utils.rb', line 154 def post_without_sessions(url, data = {}) begin return RestClient.post(url.to_s, data, cookies: @cookies) rescue RestClient::Found => err return get_without_sessions(err.response.headers[:location]) end end |
#put(url, data = {}, headers = {}, options = {}) ⇒ Object
138 139 140 |
# File 'lib/FbRuby/utils.rb', line 138 def put(url, data = {}, headers = {}, = {}) request(:put, url, {}, headers, data, ) end |