Class: CloudscrapeClient::DTO

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudscrape_client/dto.rb

Direct Known Subclasses

ExecutionDTO, RunDTO

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options:) ⇒ DTO

Returns a new instance of DTO.



8
9
10
# File 'lib/cloudscrape_client/dto.rb', line 8

def initialize(options:)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/cloudscrape_client/dto.rb', line 6

def options
  @options
end

Class Method Details

.delete(options = {}) ⇒ Object



24
25
26
# File 'lib/cloudscrape_client/dto.rb', line 24

def self.delete(options = {})
  new(options: options).response(:delete)
end

.for(options) ⇒ Object



12
13
14
# File 'lib/cloudscrape_client/dto.rb', line 12

def self.for(options)
  new(options: options).response(options.fetch(:method))
end

.get(options = {}) ⇒ Object



16
17
18
# File 'lib/cloudscrape_client/dto.rb', line 16

def self.get(options = {})
  new(options: options).response(:get)
end

.post(options = {}) ⇒ Object



20
21
22
# File 'lib/cloudscrape_client/dto.rb', line 20

def self.post(options = {})
  new(options: options).response(:post)
end

Instance Method Details

#endpointObject



44
45
46
# File 'lib/cloudscrape_client/dto.rb', line 44

def endpoint
  fail NotImplementedError, "Inheriting class must implement"
end

#paramsObject



40
41
42
# File 'lib/cloudscrape_client/dto.rb', line 40

def params
  {}
end

#response(method) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cloudscrape_client/dto.rb', line 28

def response(method)
  API.public_send(
    method,
    domain: domain,
    url: endpoint,
    options: {
      api_key: api_key,
      format: "json"
    }.merge(params)
  ).tap(&CloudscrapeClient::Validate).body
end