Class: Staticdctl::StaticdClient
- Inherits:
-
Object
- Object
- Staticdctl::StaticdClient
- Defined in:
- lib/staticdctl/staticd_client.rb
Overview
Class to interact with the Staticd API.
Example:
staticd_client = Staticdctl::StaticdClient.new(
url: "http://staticd.domain.tld/api",
access_id: ENV["STATICD_ACCESS_ID"],
secret_key: ENV["STATICD_SECRET_KEY"]
)
Instance Method Summary collapse
- #attach_domain(site_name, domain_params) ⇒ Object
-
#cached_resources(digests) ⇒ Object
Parse a sitemap of resources digest and return of sitemap purged of already know resources.
- #create_release(site_name, archive_file, sitemap_file) ⇒ Object
- #create_site(site_params) ⇒ Object
- #destroy_site(site_name) ⇒ Object
- #detach_domain(site_name, domain_name) ⇒ Object
- #domains(site_name) ⇒ Object
-
#initialize(url, hmac = {}) ⇒ StaticdClient
constructor
A new instance of StaticdClient.
- #releases(site_name) ⇒ Object
- #sites ⇒ Object
Constructor Details
#initialize(url, hmac = {}) ⇒ StaticdClient
Returns a new instance of StaticdClient.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/staticdctl/staticd_client.rb', line 15 def initialize(url, hmac={}) url = url access_id = hmac[:access_id] || "" secret_key = hmac[:secret_key] || "" @staticd_api = Staticdctl::RESTClient.new( url, access_id: access_id, secret_key: secret_key ) end |
Instance Method Details
#attach_domain(site_name, domain_params) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/staticdctl/staticd_client.rb', line 50 def attach_domain(site_name, domain_params) @staticd_api.call( :post, "/sites/#{site_name}/domain_names", domain_params ) do |data| yield build_response(data) end end |
#cached_resources(digests) ⇒ Object
Parse a sitemap of resources digest and return of sitemap purged of already know resources.
Submit a list of resources sha1 digests with HTTP path (in the sitemap format) and get a list purged of already known resources (resources already stored in database).
90 91 92 93 94 |
# File 'lib/staticdctl/staticd_client.rb', line 90 def cached_resources(digests) @staticd_api.call(:post, "/resources/get_cached", digests) do |data| yield build_response(data) end end |
#create_release(site_name, archive_file, sitemap_file) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/staticdctl/staticd_client.rb', line 75 def create_release(site_name, archive_file, sitemap_file) @staticd_api.send_files( "/sites/#{site_name}/releases", {file: archive_file, sitemap: sitemap_file} ) do |data| yield build_response(data) end end |
#create_site(site_params) ⇒ Object
32 33 34 35 36 |
# File 'lib/staticdctl/staticd_client.rb', line 32 def create_site(site_params) @staticd_api.call(:post, "/sites", site_params) do |data| yield build_response(data) end end |
#destroy_site(site_name) ⇒ Object
38 39 40 41 42 |
# File 'lib/staticdctl/staticd_client.rb', line 38 def destroy_site(site_name) @staticd_api.call(:delete, "/sites/#{site_name}") do yield end end |
#detach_domain(site_name, domain_name) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/staticdctl/staticd_client.rb', line 60 def detach_domain(site_name, domain_name) @staticd_api.call( :delete, "/sites/#{site_name}/domain_names/#{domain_name}" ) do yield end end |
#domains(site_name) ⇒ Object
44 45 46 47 48 |
# File 'lib/staticdctl/staticd_client.rb', line 44 def domains(site_name) @staticd_api.call(:get, "/sites/#{site_name}/domain_names") do |data| yield build_response(data) end end |
#releases(site_name) ⇒ Object
69 70 71 72 73 |
# File 'lib/staticdctl/staticd_client.rb', line 69 def releases(site_name) @staticd_api.call :get, "/sites/#{site_name}/releases" do |data| yield build_response(data) end end |
#sites ⇒ Object
26 27 28 29 30 |
# File 'lib/staticdctl/staticd_client.rb', line 26 def sites @staticd_api.call(:get, "/sites") do |data| yield build_response(data) end end |