class CloudscrapeClient::DTO

Constants

DEFAULT_CONTENT_TYPE

Attributes

options[R]

Public Class Methods

delete(options = {}) click to toggle source
# File lib/cloudscrape_client/dto.rb, line 28
def self.delete(options = {})
  new(options: options).response(:delete)
end
for(options) click to toggle source
# File lib/cloudscrape_client/dto.rb, line 16
def self.for(options)
  new(options: options).response(options.fetch(:method))
end
get(options = {}) click to toggle source
# File lib/cloudscrape_client/dto.rb, line 20
def self.get(options = {})
  new(options: options).response(:get)
end
new(options:) click to toggle source
# File lib/cloudscrape_client/dto.rb, line 12
def initialize(options:)
  @options = options
end
post(options = {}) click to toggle source
# File lib/cloudscrape_client/dto.rb, line 24
def self.post(options = {})
  new(options: options).response(:post)
end

Public Instance Methods

content_type() click to toggle source
# File lib/cloudscrape_client/dto.rb, line 49
def content_type
  DEFAULT_CONTENT_TYPE
end
endpoint() click to toggle source
# File lib/cloudscrape_client/dto.rb, line 53
def endpoint
  raise NotImplementedError, "Inheriting class must implement"
end
params() click to toggle source
# File lib/cloudscrape_client/dto.rb, line 45
def params
  {}
end
response(method) click to toggle source
# 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

Private Instance Methods

api_key() click to toggle source
# File lib/cloudscrape_client/dto.rb, line 63
def api_key
  CloudscrapeClient.configuration.api_key
end
domain() click to toggle source
# File lib/cloudscrape_client/dto.rb, line 59
def domain
  CloudscrapeClient.configuration.base_url
end