Class: Aranha::Parsers::SourceAddress::HashHttpBase
- Inherits:
-
Base
- Object
- Base
- 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
Methods inherited from Base
#source_as_hash, #source_as_hash?, #source_as_uri, #source_as_uri?, #url
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
|
Instance Method Details
#body ⇒ Object
29
30
31
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 29
def body
param(:body, DEFAULT_BODY)
end
|
#content ⇒ Object
45
46
47
48
49
50
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 45
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
33
34
35
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 33
def follow_redirect?
param(:follow_redirect, DEFAULT_FOLLOW_REDIRECT)
end
|
37
38
39
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 37
def
param(:headers, DEFAULT_HEADERS)
end
|
#param(key, default_value) ⇒ Object
52
53
54
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 52
def param(key, default_value)
source_as_hash[key] || params[key] || default_value
end
|
#params ⇒ Object
56
57
58
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 56
def params
source_as_hash[:params].if_present(DEFAULT_PARAMS)
end
|
#serialize ⇒ Object
41
42
43
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 41
def serialize
source_as_hash.to_yaml
end
|
#uri ⇒ Addressable::URI
61
62
63
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 61
def uri
::Addressable::URI.parse(source_as_hash.fetch(:url))
end
|
#valid? ⇒ Boolean
66
67
68
69
|
# File 'lib/aranha/parsers/source_address/hash_http_base.rb', line 66
def valid?
source_as_hash? &&
source_as_hash[:method].to_s.downcase.strip == self.class.http_method.to_s
end
|