Class: CloudscrapeClient::DTO
- Inherits:
-
Object
- Object
- CloudscrapeClient::DTO
- Defined in:
- lib/cloudscrape_client/dto.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_CONTENT_TYPE =
MIME::Types["application/json"].first
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .delete(options = {}) ⇒ Object
- .for(options) ⇒ Object
- .get(options = {}) ⇒ Object
- .post(options = {}) ⇒ Object
Instance Method Summary collapse
- #content_type ⇒ Object
- #endpoint ⇒ Object
-
#initialize(options:) ⇒ DTO
constructor
A new instance of DTO.
- #params ⇒ Object
- #response(method) ⇒ Object
Constructor Details
#initialize(options:) ⇒ DTO
Returns a new instance of DTO.
12 13 14 |
# File 'lib/cloudscrape_client/dto.rb', line 12 def initialize(options:) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/cloudscrape_client/dto.rb', line 10 def @options end |
Class Method Details
.delete(options = {}) ⇒ Object
28 29 30 |
# File 'lib/cloudscrape_client/dto.rb', line 28 def self.delete( = {}) new(options: ).response(:delete) end |
.for(options) ⇒ Object
16 17 18 |
# File 'lib/cloudscrape_client/dto.rb', line 16 def self.for() new(options: ).response(.fetch(:method)) end |
.get(options = {}) ⇒ Object
20 21 22 |
# File 'lib/cloudscrape_client/dto.rb', line 20 def self.get( = {}) new(options: ).response(:get) end |
.post(options = {}) ⇒ Object
24 25 26 |
# File 'lib/cloudscrape_client/dto.rb', line 24 def self.post( = {}) new(options: ).response(:post) end |
Instance Method Details
#content_type ⇒ Object
49 50 51 |
# File 'lib/cloudscrape_client/dto.rb', line 49 def content_type DEFAULT_CONTENT_TYPE end |
#endpoint ⇒ Object
53 54 55 |
# File 'lib/cloudscrape_client/dto.rb', line 53 def endpoint raise NotImplementedError, "Inheriting class must implement" end |
#params ⇒ Object
45 46 47 |
# File 'lib/cloudscrape_client/dto.rb', line 45 def params {} end |
#response(method) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cloudscrape_client/dto.rb', line 32 def response(method) API.public_send( method, domain: domain, url: endpoint, content_type: content_type, options: { api_key: api_key, format: "json" }.merge(params) ).tap(&CloudscrapeClient::Validate).body end |