netlify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 500cb94ed39ac0ca44ca44deb7a447dfd566b15a
4
+ data.tar.gz: 48194a2bc54a43d712c9cceb2b26b3835ed590a3
5
+ SHA512:
6
+ metadata.gz: 8614bd0635a023f9f63bcb7663c7f6930b3d8867b948324ec3784c986f90799740ebbbd849d1285aaa73fc61fbf3a294e36be3199649c8ecd691e85a569db1e3
7
+ data.tar.gz: 42f05bd119c82170e2c6e121cedeb6b28c85527ef0d88ea5e11bc1b8e2296f03fde5c09cd393ab30e797595dc16172b6a80853ccfc9bfb717f2ab78106de047a
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in Netlify.gemspec
4
+ gemspec
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ netlify (0.2.1)
5
+ highline
6
+ oauth2 (>= 0.9.2)
7
+ slop
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.3.3)
13
+ crack (0.3.2)
14
+ faraday (0.9.0)
15
+ multipart-post (>= 1.2, < 3)
16
+ highline (1.6.21)
17
+ jwt (1.0.0)
18
+ minitest (5.0.8)
19
+ multi_json (1.10.1)
20
+ multi_xml (0.5.5)
21
+ multipart-post (2.0.0)
22
+ oauth2 (1.0.0)
23
+ faraday (>= 0.8, < 0.10)
24
+ jwt (~> 1.0)
25
+ multi_json (~> 1.3)
26
+ multi_xml (~> 0.5)
27
+ rack (~> 1.2)
28
+ rack (1.5.2)
29
+ slop (3.6.0)
30
+ webmock (1.11.0)
31
+ addressable (>= 2.2.7)
32
+ crack (>= 0.3.2)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ minitest
39
+ netlify!
40
+ webmock
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mathias Biilmann Christensen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,423 @@
1
+ Netlify Ruby Client
2
+ ======================
3
+
4
+ Netlify is a hosting service for the programmable web. It understands your documents, processes forms and lets you do deploys, manage forms submissions, inject javascript snippets into sites and do intelligent updates of HTML documents through it's API.
5
+
6
+ The basic flow to using the ruby client is:
7
+
8
+ 1. Authenticate (via credentials or a previously aquired access token)
9
+ 2. Get site (via id)
10
+ 3. Deploy
11
+ * If site has not been deployed to yet, then the above step will throw a `not found` exception, and you'll need to use `Netlify.sites.create` to create the site and do the initial deploy.
12
+ * If the site has already been deployed and the above step was successful, you can simply use `site.update` to re-deploy.
13
+
14
+ If you'd rather, there's also a command line utility to handle most of these steps: `Netlify deploy`.
15
+
16
+ Installation
17
+ ============
18
+
19
+ Install the gem by running
20
+
21
+ gem install netlify
22
+
23
+ or put it in a Gemfile and run `bundle install`
24
+
25
+ gem netlify
26
+
27
+
28
+ Authenticating
29
+ ==============
30
+
31
+ Register a new application at https://app.netlify.com/applications to get your Oauth2 secret and key.
32
+
33
+ Once you have your credentials you can instantiate a Netlify client.
34
+
35
+ ```ruby
36
+ Netlify = Netlify::Client.new(:client_id => "YOUR_API_KEY", :client_secret => "YOUR_API_SECRET")
37
+ ```
38
+
39
+ Before you can make any requests to the API, you'll need to authenticate with OAuth2. The Netlify client supports two OAuth2 flows.
40
+
41
+ If you're authenticating on behalf of a user, you'll need to get a valid access token for that user. Use the Netlify client to request an authentication URL:
42
+
43
+ ```ruby
44
+ url = Netlify.authorize_url(:redirect_uri => "http://www.example.com/callback")
45
+ ```
46
+
47
+ The user then visits that URL and will be prompted to authorize your application to access his Netlify sites. If she grants permission, she'll be redirected back to the `redirect_uri` provided in the `authorize_url` call. This URL must match the redirect url configured for your Netlify application. Once the user comes back to your app, you'll be able to access a `code` query parameter that gives you an authorization code. Use this to finish the OAuth2 flow:
48
+
49
+ ```ruby
50
+ Netlify.authorize!(token, :redirect_uri => "http://www.example.com/callback")
51
+ ```
52
+
53
+ If you're not authenticating on behalf of a user you can authorize directly with the API credentials. Just call:
54
+
55
+ ```ruby
56
+ Netlify.authorize_from_credentials!
57
+ ```
58
+
59
+ If you already have an OAuth2 `access_token` you can instantiate the client like this:
60
+
61
+ ```ruby
62
+ Netlify = Netlify::Client.new(:access_token => access_token)
63
+ ```
64
+
65
+ And the client will be ready to do requests without having to use `authorize_from_credentials`. This means that once you've gotten a token via `authorize_from_credentials!` you can store it and reuse it for later sessions.
66
+
67
+ If you're authenticating via the `access_token` and you'd like to test if you have a valid `access_token`, you can attempt to make a request with the Netlify client and if the token is invalid, a `Netlify::Client::AuthenticationError` will be raised. See Miles Matthias' [Netlify Rakefile](https://github.com/milesmatthias/Netlify-rakefile) for an example.
68
+
69
+
70
+ Sites
71
+ =====
72
+
73
+ Getting a list of all sites you have access to:
74
+
75
+ ```ruby
76
+ Netlify.sites.each do |site|
77
+ puts site.id
78
+ puts site.url
79
+ end
80
+ ```
81
+
82
+ Each site has a unique, system generated id. Getting a specific site by id:
83
+
84
+ ```ruby
85
+ site = Netlify.sites.get(id)
86
+ ```
87
+
88
+ Creating a site from a directory: _(note the path given is a system path)_
89
+
90
+ ```ruby
91
+ site = Netlify.sites.create(:dir => "my-site")
92
+ puts site.id
93
+ ```
94
+
95
+ You'll want to then save that site id for future reference. Note that a site can also be looked up by its `url`.
96
+
97
+ Creating a site from a zip file:
98
+
99
+ ```ruby
100
+ site = Netlify.sites.create(:zip => "/tmp/my-site.zip")
101
+ ```
102
+
103
+ Both methods will create the site and upload the files to a new deploy.
104
+
105
+ Creating a site with a dir or a zip is actually a shortcut for this:
106
+
107
+ ```ruby
108
+ site = Netlify.sites.create(:name => "unique-site-subdomain", :custom_domain => "www.example.com")
109
+ deploy = site.deploys.create(:dir => "path/to/my-site")
110
+ ```
111
+
112
+ Use `wait_for_ready` to wait until a site has finished processing.
113
+
114
+ ```ruby
115
+ site = Netlify.sites.create(:dir => "/tmp/my-site")
116
+ site.wait_for_ready
117
+ site.state == "ready"
118
+ ```
119
+
120
+ This also works on a specific deploy, and you can pass in a block to execute after each polling action:
121
+
122
+ ```ruby
123
+ deploy = site.deploys.create(:dir => "/tmp/my-site")
124
+ deploy.wait_for_ready do |deploy|
125
+ puts "Current state: #{deploy.state}"
126
+ end
127
+ ```
128
+
129
+ Redeploy a site from a dir:
130
+
131
+ ```ruby
132
+ site = Netlify.sites.get(site_id)
133
+ deploy = site.deploys.create(:dir => "/tmp/my-site")
134
+ deploy.wait_for_ready
135
+ ```
136
+
137
+ Redeploy a site from a zip file:
138
+
139
+ ```ruby
140
+ site = Netlify.sites.get(site_id)
141
+ deploy = site.deploys.create(:zip => "/tmp/my-site.zip")
142
+ deploy.wait_for_ready
143
+ ```
144
+
145
+ Update the name of the site (its subdomain), the custom domain and the notification email for form submissions:
146
+
147
+ ```ruby
148
+ site.update(:name => "my-site", :custom_domain => "www.example.com", :notification_email => "me@example.com", :password => "secret-password")
149
+ ```
150
+
151
+ Deleting a site:
152
+
153
+ ```ruby
154
+ site.destroy!
155
+ ```
156
+
157
+ Deploys
158
+ =======
159
+
160
+ Access all deploys for a site
161
+
162
+ ```ruby
163
+ site = Netlify.sites.get(site_id)
164
+ site.deploys.all
165
+ ```
166
+
167
+ Access a specific deploy
168
+
169
+ ```ruby
170
+ site = Netlify.sites.get(site_id)
171
+ deploy = site.deploys.get(id)
172
+ ```
173
+
174
+ Publish a deploy (makes it the current live version of the site)
175
+
176
+ ```ruby
177
+ site.deploys.get(id).publish
178
+ ```
179
+
180
+ Create a new deploy
181
+
182
+ ```ruby
183
+ deploy = site.deploys.create(:dir => "/tmp/my-site")
184
+ ```
185
+
186
+ Create a draft deploy
187
+
188
+ ```ruby
189
+ deploy = site.deploys.draft(:dir => "/tmp/my-site")
190
+ ```
191
+
192
+ Or
193
+
194
+ ```ruby
195
+ deploy = site.deploys.create(:dir => "/tmp/my-site", :draft => true)
196
+ ```
197
+
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
+
200
+
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
211
+
212
+ ```ruby
213
+ Netlify.users.get(id)
214
+ ```
215
+
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.
217
+
218
+ ```ruby
219
+ Netlify.users.create(:email => "some@email.com", :uid => "12345")
220
+ ```
221
+
222
+ Update a user. **Reseller only**.
223
+
224
+ ```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
244
+ ```
245
+
246
+ Forms
247
+ =====
248
+
249
+ Access all forms you have access to:
250
+
251
+ ```ruby
252
+ Netlify.forms.all
253
+ ```
254
+
255
+ Access forms for a specific site:
256
+
257
+ ```ruby
258
+ site = Netlify.sites.get(id)
259
+ site.forms.all
260
+ ```
261
+
262
+ Access a specific form:
263
+
264
+ ```ruby
265
+ form = Netlify.forms.get(id)
266
+ ```
267
+
268
+ Access a list of all form submissions you have access to:
269
+
270
+ ```ruby
271
+ Netlify.submissions.all
272
+ ```
273
+
274
+ Access submissions from a specific site
275
+
276
+ ```ruby
277
+ site = Netlify.sites.get(id)
278
+ site.submissions.all
279
+ ```
280
+
281
+ Access submissions from a specific form
282
+
283
+ ```ruby
284
+ form = Netlify.forms.get(id)
285
+ form.submissions.all
286
+ ```
287
+
288
+ Get a specific submission
289
+
290
+ ```ruby
291
+ Netlify.submissions.get(id)
292
+ ```
293
+
294
+ Files
295
+ =====
296
+
297
+ Access all files in a site:
298
+
299
+ ```ruby
300
+ site = Netlify.sites.get(id)
301
+ site.files.all
302
+ ```
303
+
304
+ Get a specific file:
305
+
306
+ ```ruby
307
+ file = site.files.get(path) # Example paths: "/css/main.css", "/index.html"
308
+ ```
309
+
310
+ Reading a file:
311
+
312
+ ```ruby
313
+ file.read
314
+ ```
315
+
316
+ Snippets
317
+ ========
318
+
319
+ Snippets are small code snippets injected into all HTML pages of a site right before the closing head or body tag. To get all snippets for a site:
320
+
321
+ ```ruby
322
+ site = Netlify.sites.get(id)
323
+ site.snippets.all
324
+ ```
325
+
326
+ Get a specific snippet
327
+
328
+ ```ruby
329
+ site.snippets.get(0)
330
+ ```
331
+
332
+ Add a snippet to a site.
333
+
334
+ You can specify a `general` snippet that will be inserted into all pages, and a `goal` snippet that will be injected into a page following a successful form submission. Each snippet must have a title. You can optionally set the position of both the general and the goal snippet to `head` or `footer` to determine if it gets injected into the head tag or at the end of the page.
335
+
336
+ ```ruby
337
+ site.snippets.create(
338
+ :general => general_snippet,
339
+ :general_position => "footer",
340
+ :goal => goal_snippet,
341
+ :goal_position => "head",
342
+ :title => "My Snippet"
343
+ )
344
+ ```
345
+
346
+ Update a snippet
347
+
348
+ ```ruby
349
+ site.snippets.get(id).update(
350
+ :general => general_snippet,
351
+ :general_position => "footer",
352
+ :goal => goal_snippet,
353
+ :goal_position => "head",
354
+ :title => "My Snippet"
355
+ )
356
+ ```
357
+
358
+ Remove a snippet
359
+
360
+ ```ruby
361
+ site.snippet.get(id).destroy
362
+ end
363
+ ```
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
+ ```