Class: Spidra::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/spidra/client.rb

Constant Summary collapse

DEFAULT_BASE_URL =
"https://api.spidra.io/api"
DEFAULT_TIMEOUT =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT) ⇒ Client

Create a new Spidra client.

Parameters:

  • api_key (String)

    your Spidra API key

  • base_url (String) (defaults to: DEFAULT_BASE_URL)

    override the API base URL (optional)

  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    HTTP timeout in seconds (default: 30)

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/spidra/client.rb', line 20

def initialize(api_key, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT)
  raise ArgumentError, "api_key is required" if api_key.nil? || api_key.empty?

  http = HTTP.new(api_key: api_key, base_url: base_url, timeout: timeout)

  @scrape = Resources::Scrape.new(http)
  @batch  = Resources::Batch.new(http)
  @crawl  = Resources::Crawl.new(http)
  @logs   = Resources::Logs.new(http)
  @usage  = Resources::Usage.new(http)
end

Instance Attribute Details

#batchObject (readonly)

Returns the value of attribute batch.



13
14
15
# File 'lib/spidra/client.rb', line 13

def batch
  @batch
end

#crawlObject (readonly)

Returns the value of attribute crawl.



13
14
15
# File 'lib/spidra/client.rb', line 13

def crawl
  @crawl
end

#logsObject (readonly)

Returns the value of attribute logs.



13
14
15
# File 'lib/spidra/client.rb', line 13

def logs
  @logs
end

#scrapeObject (readonly)

Returns the value of attribute scrape.



13
14
15
# File 'lib/spidra/client.rb', line 13

def scrape
  @scrape
end

#usageObject (readonly)

Returns the value of attribute usage.



13
14
15
# File 'lib/spidra/client.rb', line 13

def usage
  @usage
end