Class: Netlify::Site

Inherits:
Model
  • Object
show all
Defined in:
lib/netlify/site.rb

Instance Attribute Summary

Attributes inherited from Model

#attributes, #client, #prefix

Instance Method Summary collapse

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!(options)
  raise Client::NetlifyError, "You must specify a Github access_token" unless options[:access_token]
  raise Client::NetlifyError, "You must specify a Github repo" unless options[:repo]
  require "github_api"

  _, user, repo = *options[:repo].match(/^([^\/]+)\/([^\/]+)$/)
  unless user && repo
    raise Client::NetlifyError, "Invalid github repo #{options[:repo]}"
  end

  github = Github.new(:oauth_token => options[: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 => options[:repo],
      :deploy_key_id => deploy_key.id,
      :dir => options[:dir],
      :cmd => options[:cmd],
      :branch => options[:branch],
      :env => options[: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

#deploysObject



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

Returns:

  • (Boolean)


14
15
16
# File 'lib/netlify/site.rb', line 14

def error?
  state == "error"
end

#filesObject



79
80
81
# File 'lib/netlify/site.rb', line 79

def files
  Files.new(client, path)
end

#formsObject



71
72
73
# File 'lib/netlify/site.rb', line 71

def forms
  Forms.new(client, path)
end

#ready?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/netlify/site.rb', line 10

def ready?
  state == "current"
end

#snippetsObject



83
84
85
# File 'lib/netlify/site.rb', line 83

def snippets
  Snippets.new(client, path)
end

#submissionsObject



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