Class: StackPath::Client
- Inherits:
-
Object
- Object
- StackPath::Client
- Defined in:
- lib/stack_path/client.rb
Overview
An API client that allows querying StackPath
Constant Summary
- 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
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#oauth_client ⇒ Object
readonly
Returns the value of attribute oauth_client.
Instance Method Summary collapse
-
#delete(path, params = {}) ⇒ Object
Send a DELETE request to the StackPath API.
-
#get(path, params = {}) ⇒ Object
Send a GET request to the StackPath API.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#post(path, params = {}) ⇒ Object
Send a POST request to the StackPath API.
-
#put(path, params = {}) ⇒ Object
Send a PUT request to the StackPath API.
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( = {}) @base_url = "https://api.stackpath.com/v1/#{[:company_alias]}" @oauth_client = Signet::OAuth1::Client.new( client_credential_key: [:client_key], client_credential_secret: [:client_secret], two_legged: true ) end |
Instance Attribute Details
#base_url ⇒ Object (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_client ⇒ Object (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 |