class CloudscrapeClient::API
Constants
- InvalidAccountId
- InvalidApiKey
Public Class Methods
delete(*args)
click to toggle source
# File lib/cloudscrape_client/api.rb, line 22 def self.delete(*args) new.delete(*args) end
get(*args)
click to toggle source
# File lib/cloudscrape_client/api.rb, line 14 def self.get(*args) new.get(*args) end
post(*args)
click to toggle source
# File lib/cloudscrape_client/api.rb, line 18 def self.post(*args) new.post(*args) end
Public Instance Methods
delete(domain:, url:, content_type:, options: {})
click to toggle source
# File lib/cloudscrape_client/api.rb, line 39 def delete(domain:, url:, content_type:, options: {}) connection(domain: domain, content_type: content_type) .delete(URI.escape(url), options) end
get(domain:, url:, content_type:, options: {})
click to toggle source
# File lib/cloudscrape_client/api.rb, line 26 def get(domain:, url:, content_type:, options: {}) connection(domain: domain, content_type: content_type) .get(URI.escape(url), options) end
post(domain:, url:, content_type:, options: {})
click to toggle source
# File lib/cloudscrape_client/api.rb, line 31 def post(domain:, url:, content_type:, options: {}) connection(domain: domain, content_type: content_type).post do |req| req.url URI.escape(url) req.headers["Content-Type"] = content_type.to_s req.body = options.to_json end end
Private Instance Methods
access_key()
click to toggle source
# File lib/cloudscrape_client/api.rb, line 46 def access_key raise InvalidAccountId, account_id unless account_id raise InvalidApiKey, api_key unless api_key Digest::MD5.hexdigest(account_id + api_key) end
account_id()
click to toggle source
# File lib/cloudscrape_client/api.rb, line 53 def account_id CloudscrapeClient.configuration.account_id end
api_key()
click to toggle source
# File lib/cloudscrape_client/api.rb, line 57 def api_key CloudscrapeClient.configuration.api_key end
connection(domain:, content_type:)
click to toggle source
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
# File lib/cloudscrape_client/api.rb, line 67 def connection(domain:, content_type:) Faraday.new(url: domain) do |faraday| faraday.request :url_encoded faraday.request :user_agent, app: CloudscrapeClient.configuration.user_agent_app, version: user_agent_version faraday.request :request_headers, accept: "application/json", "X-CloudScrape-Access" => access_key, "X-CloudScrape-Account" => account_id, content_type: content_type.to_s if CloudscrapeClient.configuration.verbose faraday.use :extended_logging, logger: CloudscrapeClient.configuration.logger end faraday.response :multi_json, content_type: /\bjson$/, symbolize_keys: true faraday.adapter Faraday.default_adapter end end
user_agent_version()
click to toggle source
# File lib/cloudscrape_client/api.rb, line 61 def user_agent_version CloudscrapeClient.configuration.user_agent_version end