Class: Netlify::Deploys

Inherits:
CollectionProxy show all
Defined in:
lib/netlify/deploys.rb

Instance Attribute Summary

Attributes inherited from CollectionProxy

#client, #prefix

Instance Method Summary collapse

Methods inherited from CollectionProxy

#all, #each, #get, #initialize, model, #model, path, #path

Constructor Details

This class inherits a constructor from Netlify::CollectionProxy

Instance Method Details

#create(attributes) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/netlify/deploys.rb', line 7

def create(attributes)
  if attributes[:dir]
    response = client.request(:post, path,
      :body => JSON.generate({:files => inventory(attributes[:dir]), :draft => attributes[:draft] || false}),
      :headers => {"Content-Type" => "application/json"}
    )
    Deploy.new(client, response.parsed).tap do |deploy|
      deploy.upload_dir(attributes[:dir])
    end
  elsif attributes[:zip]
    request_path = attributes[:draft] ? "#{path}?draft=true" : path
    response = client.request(:post, request_path,
      :body => ::File.read(attributes[:zip]),
      :headers => {"Content-Type" => "application/zip"}
    )
    Deploy.new(client, response.parsed)
  elsif attributes[:tar]
    request_path = attributes[:draft] ? "#{path}?draft=true" : path
    response = client.request(:post, request_path,
      :body => ::File.read(attributes[:tar]),
      :headers => {"Content-Type" => "application/x-gzip"}
    )
    Deploy.new(client, response.parsed)
  else
    raise "Need dir or zip to create a deploy"
  end
end

#draft(attributes) ⇒ Object



35
36
37
# File 'lib/netlify/deploys.rb', line 35

def draft(attributes)
  create(attributes.merge(:draft => true))
end