Class: StackPath::Client

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

Overview

An API client that allows querying StackPath

Constant Summary collapse

HEADERS =

The constant headers that are sent with each request

{
  'User-Agent' => 'Ruby StackPath CDN API Client',
  'Content-Type' => 'application/json'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
23
# File 'lib/stack_path/client.rb', line 15

def initialize(options = {})
  @base_url = "https://api.stackpath.com/v1/#{options[:company_alias]}"
  @oauth_client =
    Signet::OAuth1::Client.new(
      client_credential_key: options[:client_key],
      client_credential_secret: options[:client_secret],
      two_legged: true
    )
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



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

def base_url
  @base_url
end

#oauth_clientObject (readonly)

Returns the value of attribute oauth_client.



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

def oauth_client
  @oauth_client
end

Instance Method Details

#delete(path, params = {}) ⇒ Object

Send a DELETE request to the StackPath API



42
43
44
# File 'lib/stack_path/client.rb', line 42

def delete(path, params = {})
  request(:delete, path, params)
end

#get(path, params = {}) ⇒ Object

Send a GET request to the StackPath API



26
27
28
29
# File 'lib/stack_path/client.rb', line 26

def get(path, params = {})
  path = "#{path}?#{URI.encode_www_form(params)}" if params.any?
  request(:get, path)
end

#post(path, params = {}) ⇒ Object

Send a POST request to the StackPath API



32
33
34
# File 'lib/stack_path/client.rb', line 32

def post(path, params = {})
  request(:post, path, params)
end

#put(path, params = {}) ⇒ Object

Send a PUT request to the StackPath API



37
38
39
# File 'lib/stack_path/client.rb', line 37

def put(path, params = {})
  request(:put, path, params)
end