Class: Aranha::Parsers::SourceAddress::HashHttpBase
- Inherits:
-
Object
- Object
- Aranha::Parsers::SourceAddress::HashHttpBase
show all
- Defined in:
- lib/aranha/parsers/source_address/hash_http_base.rb,
lib/aranha/parsers/source_address/hash_http_base/headers.rb
Defined Under Namespace
Classes: Headers
Constant Summary
collapse
- DEFAULT_BODY =
''
- DEFAULT_FOLLOW_REDIRECT =
true
{}.freeze
- DEFAULT_PARAMS =
{}.freeze
- USER_AGENT_KEY =
'user-agent'
- USER_AGENT_VALUE =
'aranha-parsers'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.http_method ⇒ Object
15
16
17
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 15
def http_method
const_get 'HTTP_METHOD'
end
|
.valid_source?(source) ⇒ Boolean
19
20
21
22
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 19
def valid_source?(source)
source.is_a?(::Hash) &&
source.with_indifferent_access[:method].to_s.downcase.strip == http_method.to_s
end
|
Instance Method Details
#body ⇒ Object
39
40
41
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 39
def body
param(:body, DEFAULT_BODY)
end
|
#content ⇒ Object
59
60
61
62
63
64
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 59
def content
request = http_request
request.response.body_str
rescue ::EacEnvs::Http::Error => e
raise ::Aranha::Parsers::SourceAddress::FetchContentError, e.message, request
end
|
#follow_redirect? ⇒ Boolean
43
44
45
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 43
def follow_redirect?
param(:follow_redirect, DEFAULT_FOLLOW_REDIRECT)
end
|
47
48
49
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 47
def
param(:headers, DEFAULT_HEADERS)
end
|
#param(key, default_value) ⇒ Object
66
67
68
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 66
def param(key, default_value)
source[key] || params[key] || default_value
end
|
#params ⇒ Object
70
71
72
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 70
def params
source[:params].if_present(DEFAULT_PARAMS)
end
|
#serialize ⇒ Object
55
56
57
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 55
def serialize
source.to_yaml
end
|
#url ⇒ Object
51
52
53
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 51
def url
source.fetch(:url)
end
|