Class: Netlify::Site
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
- #configure_github!(options) ⇒ Object
- #deploys ⇒ Object
- #destroy! ⇒ Object
- #error? ⇒ Boolean
- #files ⇒ Object
- #forms ⇒ Object
- #ready? ⇒ Boolean
- #snippets ⇒ Object
- #submissions ⇒ Object
- #update(attributes) ⇒ Object
- #wait_for_ready(timeout = 900, &block) ⇒ Object
Methods inherited from Model
#collection, collection, #destroy, fields, #initialize, #path, #process, #refresh
Constructor Details
This class inherits a constructor from Netlify::Model
Instance Method Details
#configure_github!(options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/netlify/site.rb', line 35 def configure_github!() raise Client::NetlifyError, "You must specify a Github access_token" unless [:access_token] raise Client::NetlifyError, "You must specify a Github repo" unless [:repo] require "github_api" _, user, repo = *[:repo].match(/^([^\/]+)\/([^\/]+)$/) unless user && repo raise Client::NetlifyError, "Invalid github repo #{options[:repo]}" end github = Github.new(:oauth_token => [:access_token]) deploy_key = client.deploy_keys.create({}) github.repos.keys.create(user, repo, title: "Netlify", key: deploy_key.public_key) response = client.request(:put, path, :body => { :github => { :repo => [:repo], :deploy_key_id => deploy_key.id, :dir => [:dir], :cmd => [:cmd], :branch => [:branch], :env => [:env] } }) process(response.parsed) github.repos.hooks.create(user, repo, name: "web", active: true, events: ["push"], config: { url: deploy_hook, content_type: 'json' }) self end |
#deploys ⇒ Object
87 88 89 |
# File 'lib/netlify/site.rb', line 87 def deploys Deploys.new(client, path) end |
#destroy! ⇒ Object
66 67 68 69 |
# File 'lib/netlify/site.rb', line 66 def destroy! client.request(:delete, path) true end |
#error? ⇒ Boolean
14 15 16 |
# File 'lib/netlify/site.rb', line 14 def error? state == "error" end |
#files ⇒ Object
79 80 81 |
# File 'lib/netlify/site.rb', line 79 def files Files.new(client, path) end |
#forms ⇒ Object
71 72 73 |
# File 'lib/netlify/site.rb', line 71 def forms Forms.new(client, path) end |
#ready? ⇒ Boolean
10 11 12 |
# File 'lib/netlify/site.rb', line 10 def ready? state == "current" end |
#snippets ⇒ Object
83 84 85 |
# File 'lib/netlify/site.rb', line 83 def snippets Snippets.new(client, path) end |
#submissions ⇒ Object
75 76 77 |
# File 'lib/netlify/site.rb', line 75 def submissions Submissions.new(client, path) end |
#update(attributes) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/netlify/site.rb', line 25 def update(attributes) response = client.request(:put, path, :body => mutable_attributes(attributes)) process(response.parsed) if attributes[:zip] || attributes[:dir] deploy = deploys.create(attributes) self.deploy_id = deploy.id end self end |
#wait_for_ready(timeout = 900, &block) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/netlify/site.rb', line 18 def wait_for_ready(timeout = 900, &block) deploy = deploys.get(deploy_id) raise "Error fetching deploy #{deploy_id}" unless deploy deploy.wait_for_ready(timeout, &block) self end |