Class: CloudscrapeClient::DTO

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

Direct Known Subclasses

ExecutionDTO, RunDTO

Constant Summary collapse

DEFAULT_CONTENT_TYPE =
MIME::Types["application/json"].first

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/cloudscrape_client/dto.rb', line 10

def options
  @options
end

Class Method Details

.delete(options = {}) ⇒ Object



28
29
30
# File 'lib/cloudscrape_client/dto.rb', line 28

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

.for(options) ⇒ Object



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

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

.get(options = {}) ⇒ Object



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

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

.post(options = {}) ⇒ Object



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

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

Instance Method Details

#content_typeObject



49
50
51
# File 'lib/cloudscrape_client/dto.rb', line 49

def content_type
  DEFAULT_CONTENT_TYPE
end

#endpointObject

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/cloudscrape_client/dto.rb', line 53

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

#paramsObject



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