netlify 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 500cb94ed39ac0ca44ca44deb7a447dfd566b15a
4
- data.tar.gz: 48194a2bc54a43d712c9cceb2b26b3835ed590a3
3
+ metadata.gz: 437996fb50a44a765375a8b7f176fc5b4e2e8b14
4
+ data.tar.gz: 902fce5832eba704da8714fc7d24a5d77e0d4d71
5
5
  SHA512:
6
- metadata.gz: 8614bd0635a023f9f63bcb7663c7f6930b3d8867b948324ec3784c986f90799740ebbbd849d1285aaa73fc61fbf3a294e36be3199649c8ecd691e85a569db1e3
7
- data.tar.gz: 42f05bd119c82170e2c6e121cedeb6b28c85527ef0d88ea5e11bc1b8e2296f03fde5c09cd393ab30e797595dc16172b6a80853ccfc9bfb717f2ab78106de047a
6
+ metadata.gz: fc9e999d347c6c0e23a5381f5a35235a6da6c5509befa1fc52fbc14b4c4f32b439da8215c7e9ff9df57049a71441be93b67a512575dca27380d462c8f3872df5
7
+ data.tar.gz: 96c84262f78082f8d127131ad2ebb9effbcd8a66eda35fbf2aae37784198a8055e9290ee5480a9d54fcdf45df789c411bf565a350555d331154afb7fb8274740
data/README.md CHANGED
@@ -197,50 +197,33 @@ deploy = site.deploys.create(:dir => "/tmp/my-site", :draft => true)
197
197
 
198
198
  This will upload and process a deploy. You can view the deploy at `deploy.deploy_url` and make it the live version of the site with `deploy.publish`.
199
199
 
200
+ Continuous Deployment
201
+ =====================
200
202
 
201
- Users
202
- =====
203
-
204
- Access all users you have access to
205
-
206
- ```ruby
207
- Netlify.users.all
208
- ```
209
-
210
- Access a specific user
203
+ You can also configure continuous deployment for a new or existing site from the Ruby client.
211
204
 
212
- ```ruby
213
- Netlify.users.get(id)
214
- ```
205
+ You'll need a Github access token (this will never get sent to Netlify) in addition to your Netlify token. Make sure this access token have the permission to add a deploy key and a web hook to your repository.
215
206
 
216
- Create a user. **Reseller only**. A unique email is required. You can optionally include a unique uid, typically the database ID you use for the user on your end.
207
+ Create a new site with continuous deployment:
217
208
 
218
209
  ```ruby
219
- Netlify.users.create(:email => "some@email.com", :uid => "12345")
210
+ client.sites.create(:github => {
211
+ :repo => "netlify/example",
212
+ :dir => "build",
213
+ :cmd => "middleman build",
214
+ :access_token => GITHUB_ACCESS_TOKEN
215
+ })
220
216
  ```
221
217
 
222
- Update a user. **Reseller only**.
218
+ Configure continuous deployment for an existing site:
223
219
 
224
220
  ```ruby
225
- Netlify.users.get(id).update(:email => "new@email.com", :uid => "12345")
226
- ```
227
-
228
- Delete a user. **Reseller only**
229
-
230
- ```ruby
231
- Netlify.users.get(id).destroy
232
- ```
233
-
234
- Get all sites for a user
235
-
236
- ```ruby
237
- Netlify.users.get(id).sites
238
- ```
239
-
240
- Get all form submissions for a user
241
-
242
- ```ruby
243
- Netlify.users.get(id).submissions
221
+ site.configure_github!(
222
+ :repo => "netlify/example",
223
+ :dir => "build",
224
+ :cmd => "middleman build",
225
+ :access_token => GITHUB_ACCESS_TOKEN
226
+ )
244
227
  ```
245
228
 
246
229
  Forms
@@ -361,63 +344,3 @@ Remove a snippet
361
344
  site.snippet.get(id).destroy
362
345
  end
363
346
  ```
364
-
365
- DNS Zones
366
- =========
367
-
368
- Resellers can manage DNS Zones through the ruby client. To use this feature your access token must belong to a reseller administrator.
369
-
370
- Create a DNS Zone
371
-
372
- ```ruby
373
- Netlify.dns_zones.create(:name => "www.example.com", :user_id => "1234")
374
- ```
375
-
376
- Get all DNS Zones
377
-
378
- ```ruby
379
- Netlify.dns_zones.all
380
- ```
381
-
382
- Delete a DNS Zone
383
-
384
- ```ruby
385
- dns_zone.destroy
386
- ```
387
-
388
- Get all dns records for a zone
389
-
390
- ```ruby
391
- dns_zone.dns_records.all
392
- ```
393
-
394
- Adding a new record (supported types: A, CNAME, TXT, MX)
395
-
396
- ```ruby
397
- dns_zone.dns_records.create(:hostname => "www", :type => "CNAME", :value => "Netlify.com", :ttl => "500")
398
- ```
399
-
400
- Deleting a record
401
-
402
- ```ruby
403
- dns_record.destroy
404
- ```
405
-
406
- Access Tokens
407
- =============
408
-
409
- Resellers can create and revoke access tokens on behalf of their users. To use this feature your access token must belong to a reseller administrator.
410
-
411
- Create access token:
412
-
413
- ```ruby
414
- Netlify.access_tokens.create(:user => {:email => "test@example.com", :uid => 123})
415
- ```
416
-
417
- The user must have either an email or a uid or both. Both email and uid must be unique within your reseller account. The uid would typically correspond to your internal database id for the user. If the users doesn't exist, a new user will be created on the fly.
418
-
419
- Revoke access token:
420
-
421
- ```ruby
422
- Netlify.access_tokens.get("token-string").destroy
423
- ```
data/lib/netlify.rb CHANGED
@@ -10,6 +10,7 @@ require "netlify/files"
10
10
  require "netlify/snippets"
11
11
  require "netlify/users"
12
12
  require "netlify/deploys"
13
+ require "netlify/deploy_keys"
13
14
  require "netlify/dns_zones"
14
15
  require "netlify/access_tokens"
15
16
  require "netlify/multipass"
@@ -52,6 +52,10 @@ module Netlify
52
52
  Submissions.new(self)
53
53
  end
54
54
 
55
+ def deploy_keys
56
+ DeployKeys.new(self)
57
+ end
58
+
55
59
  def users
56
60
  Users.new(self)
57
61
  end
@@ -32,7 +32,6 @@ module Netlify
32
32
  while !(ready?)
33
33
  sleep 5
34
34
  refresh
35
- puts "Got state: #{state}"
36
35
  raise "Error processing site: #{error_message}" if error?
37
36
  yield(self) if block_given?
38
37
  raise "Timeout while waiting for ready" if Time.now - start > timeout
@@ -0,0 +1,7 @@
1
+ require "Netlify/dns_records"
2
+
3
+ module Netlify
4
+ class DeployKey < Model
5
+ fields :id, :public_key, :created_at
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require "Netlify/deploy_key"
2
+
3
+ module Netlify
4
+ class DeployKeys < CollectionProxy
5
+ path "/deploy_keys"
6
+ end
7
+ end
data/lib/netlify/model.rb CHANGED
@@ -62,4 +62,4 @@ module Netlify
62
62
  ::File.join(*[prefix, collection.path, id.to_s].compact)
63
63
  end
64
64
  end
65
- end
65
+ end
data/lib/netlify/site.rb CHANGED
@@ -4,8 +4,8 @@ require 'uri'
4
4
  module Netlify
5
5
  class Site < Model
6
6
  fields :id, :state, :premium, :claimed, :name, :custom_domain, :url,
7
- :admin_url, :deploy_id, :deploy_url, :screenshot_url, :created_at, :updated_at,
8
- :password, :notification_email, :user_id, :error_message, :required
7
+ :admin_url, :deploy_id, :build_id, :deploy_url, :screenshot_url, :created_at, :updated_at,
8
+ :password, :notification_email, :user_id, :error_message, :required, :deploy_hook
9
9
 
10
10
  def ready?
11
11
  state == "current"
@@ -32,6 +32,37 @@ module Netlify
32
32
  self
33
33
  end
34
34
 
35
+ def configure_github!(options)
36
+ raise Client::NetlifyError, "You must specify a Github access_token" unless options[:access_token]
37
+ raise Client::NetlifyError, "You must specify a Github repo" unless options[:repo]
38
+ require "github_api"
39
+
40
+ _, user, repo = *options[:repo].match(/^([^\/]+)\/([^\/]+)$/)
41
+ unless user && repo
42
+ raise Client::NetlifyError, "Invalid github repo #{options[:repo]}"
43
+ end
44
+
45
+ github = Github.new(:oauth_token => options[:access_token])
46
+ deploy_key = client.deploy_keys.create({})
47
+ github.repos.keys.create(user, repo, title: "Netlify", key: deploy_key.public_key)
48
+ response = client.request(:put, path, :body => {
49
+ :github => {
50
+ :repo => options[:repo],
51
+ :deploy_key_id => deploy_key.id,
52
+ :dir => options[:dir],
53
+ :cmd => options[:cmd],
54
+ :branch => options[:branch],
55
+ :env => options[:env]
56
+ }
57
+ })
58
+ process(response.parsed)
59
+ github.repos.hooks.create(user, repo, name: "web", active: true, events: ["push"], config: {
60
+ url: deploy_hook,
61
+ content_type: 'json'
62
+ })
63
+ self
64
+ end
65
+
35
66
  def destroy!
36
67
  client.request(:delete, path)
37
68
  true
data/lib/netlify/sites.rb CHANGED
@@ -11,6 +11,8 @@ module Netlify
11
11
  if attributes[:zip] || attributes[:dir]
12
12
  deploy = site.deploys.create(attributes)
13
13
  site.deploy_id = deploy.id
14
+ elsif attributes[:github]
15
+ site.configure_github!(attributes[:github])
14
16
  end
15
17
  end
16
18
  end
@@ -1,3 +1,3 @@
1
1
  module Netlify
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/netlify.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'Netlify/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "netlify"
8
+ gem.version = Netlify::VERSION
9
+ gem.authors = ["Mathias Biilmann Christensen"]
10
+ gem.email = ["mathias@Netlify.com"]
11
+ gem.description = %q{API Client for Netlify}
12
+ gem.summary = %q{API Client for Netlify}
13
+ gem.homepage = "https://www.netlify.com"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "oauth2", ">= 0.9.2"
21
+ gem.add_dependency "slop"
22
+ gem.add_dependency "highline"
23
+ gem.add_dependency "github_api"
24
+ gem.add_development_dependency "minitest"
25
+ gem.add_development_dependency "webmock"
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netlify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Biilmann Christensen
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: github_api
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: minitest
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +112,8 @@ files:
98
112
  - lib/netlify/client.rb
99
113
  - lib/netlify/collection_proxy.rb
100
114
  - lib/netlify/deploy.rb
115
+ - lib/netlify/deploy_key.rb
116
+ - lib/netlify/deploy_keys.rb
101
117
  - lib/netlify/deploys.rb
102
118
  - lib/netlify/dns_record.rb
103
119
  - lib/netlify/dns_records.rb
@@ -118,6 +134,7 @@ files:
118
134
  - lib/netlify/user.rb
119
135
  - lib/netlify/users.rb
120
136
  - lib/netlify/version.rb
137
+ - netlify.gemspec
121
138
  - test/client_test.rb
122
139
  - test/files/site-dir.zip
123
140
  - test/files/site-dir/index.html