fastly 0.5 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
data/Changes ADDED
@@ -0,0 +1,13 @@
1
+ 2011-12-15 v0.9
2
+
3
+ Add mapping from backends to directors and directors to origins
4
+
5
+ 2011-11-03 v0.8
6
+
7
+ Add list_* to all objects
8
+
9
+ Add Healthchecks and Syslog endpoint streaming
10
+
11
+ 2011-11-02 v0.5
12
+
13
+ Initial releasee
data/README.md CHANGED
@@ -2,7 +2,7 @@ Fastly - client library for interacting with the Fastly web acceleration service
2
2
 
3
3
  # Example
4
4
 
5
- fastly = Net::Fastly.new(%login_opts);
5
+ fastly = Fastly.new(login_opts);
6
6
 
7
7
  current_user = fastly.current_user;
8
8
  current_customer = fastly.current_customer;
@@ -5,7 +5,7 @@
5
5
  # A client library for interacting with the Fastly web acceleration service
6
6
  class Fastly
7
7
  # The current version of the library
8
- VERSION = "0.5"
8
+ VERSION = "0.9"
9
9
 
10
10
  require 'fastly/fetcher'
11
11
  require 'fastly/client'
@@ -16,11 +16,13 @@ class Fastly
16
16
  require 'fastly/customer'
17
17
  require 'fastly/director'
18
18
  require 'fastly/domain'
19
+ require 'fastly/healthcheck'
19
20
  require 'fastly/invoice'
20
21
  require 'fastly/match'
21
22
  require 'fastly/origin'
22
23
  require 'fastly/service'
23
24
  require 'fastly/settings'
25
+ require 'fastly/syslog'
24
26
  require 'fastly/user'
25
27
  require 'fastly/vcl'
26
28
  require 'fastly/version'
@@ -79,12 +81,15 @@ class Fastly
79
81
  end
80
82
 
81
83
 
82
- [User, Customer, Backend, Director, Domain, Match, Origin, Service, VCL, Version].each do |klass|
84
+ [User, Customer, Backend, Director, Domain, Healthcheck, Match, Origin, Service, Syslog, VCL, Version].each do |klass|
83
85
  type = klass.to_s.downcase.split("::")[-1]
84
- # self.send :define_method, "list_#{type}s".to_sym do
85
- # list(klass)
86
- # end
87
-
86
+ # unless the class doesn't have a list path or it already exists
87
+ unless klass.list_path.nil? || klass.respond_to?("list_#{type}s".to_sym)
88
+ self.send :define_method, "list_#{type}s".to_sym do |*args|
89
+ list(klass, *args)
90
+ end
91
+ end
92
+
88
93
  self.send :define_method, "get_#{type}".to_sym do |*args|
89
94
  get(klass, *args)
90
95
  end
@@ -125,6 +130,14 @@ class Fastly
125
130
  ##
126
131
  # :method: create_origin(opts)
127
132
  # opts must contain service_id, version and name params
133
+
134
+ ##
135
+ # :method: create_healthcheck(opts)
136
+ # opts must contain service_id, version and name params
137
+
138
+ ##
139
+ # :method: create_syslog(opts)
140
+ # opts must contain service_id, version and name params
128
141
 
129
142
  ##
130
143
  # :method: create_vcl(opts)
@@ -157,6 +170,10 @@ class Fastly
157
170
  ##
158
171
  # :method: get_domain(service_id, number, name)
159
172
  # Get a Domain
173
+
174
+ ##
175
+ # :method: get_healthcheck(service_id, number, name)
176
+ # Get a Healthcheck
160
177
 
161
178
  ##
162
179
  # :method: get_match(service_id, number, name)
@@ -165,6 +182,10 @@ class Fastly
165
182
  ##
166
183
  # :method: get_origin(service_id, number, name)
167
184
  # Get an Origin
185
+
186
+ ##
187
+ # :method: get_syslog(service_id, number, name)
188
+ # Get a Syslog
168
189
 
169
190
  ##
170
191
  # :method: get_vcl(service_id, number, name)
@@ -212,6 +233,11 @@ class Fastly
212
233
  # :method: update_domain(domain)
213
234
  # You can also call
214
235
  # domain.save!
236
+
237
+ ##
238
+ # :method: update_healthcheck(healthcheck)
239
+ # You can also call
240
+ # healthcheck.save!
215
241
 
216
242
  ##
217
243
  # :method: update_match(match)
@@ -222,6 +248,16 @@ class Fastly
222
248
  # :method: update_origin(origin)
223
249
  # You can also call
224
250
  # origin.save!
251
+
252
+ ##
253
+ # :method: update_settings(settings)
254
+ # You can also call
255
+ # settings.save!
256
+
257
+ ##
258
+ # :method: update_syslog(syslog)
259
+ # You can also call
260
+ # syslog.save!
225
261
 
226
262
  ##
227
263
  # :method: update_vcl(vcl)
@@ -233,11 +269,6 @@ class Fastly
233
269
  # You can also call
234
270
  # version.save!
235
271
 
236
- ##
237
- # :method: update_settings(settings)
238
- # You can also call
239
- # settings.save!
240
-
241
272
 
242
273
  ##
243
274
  # :method: delete_user(user)
@@ -278,6 +309,10 @@ class Fastly
278
309
  # You can also call
279
310
  # domain.delete!
280
311
 
312
+ ##
313
+ # :method: delete_healthcheck(healthcheck)
314
+ # You can also call
315
+ # healthcheck.delete!
281
316
 
282
317
  ##
283
318
  # :method: delete_match(match)
@@ -290,18 +325,74 @@ class Fastly
290
325
  # You can also call
291
326
  # origin.delete!
292
327
 
328
+ ##
329
+ # :method: delete_syslog(syslog)
330
+ # You can also call
331
+ # syslog.delete!
332
+
293
333
 
294
334
  ##
295
335
  # :method: delete_vcl(vcl)
296
336
  # You can also call
297
337
  # vcl.delete!
298
338
 
299
-
300
339
  ##
301
340
  # :method: delete_version(version)
302
341
  # You can also call
303
342
  # version.delete!
304
343
 
344
+ # :method: list_users
345
+ #
346
+ # Get a list of all users
347
+
348
+ # :method: list_customers
349
+ #
350
+ # Get a list of all customers
351
+
352
+ # :method: list_versions
353
+ #
354
+ # Get a list of all versions
355
+
356
+ # :method: list_services
357
+ #
358
+ # Get a list of all services
359
+
360
+ # :method: list_backends
361
+ #
362
+ # Get a list of all backends
363
+
364
+ # :method: list_directors
365
+ #
366
+ # Get a list of all directors
367
+
368
+ # :method: list_domains
369
+ #
370
+ # Get a list of all domains
371
+
372
+ # :method: list_healthchecks
373
+ #
374
+ # Get a list of all healthchecks
375
+
376
+ # :method: list_matchs
377
+ #
378
+ # Get a list of all matches
379
+
380
+ # :method: list_origins
381
+ #
382
+ # Get a list of all origins
383
+
384
+ # :method: list_syslogs
385
+ #
386
+ # Get a list of all syslogs
387
+
388
+ # :method: list_vcls
389
+ #
390
+ # Get a list of all vcls
391
+
392
+ # :method: list_versions
393
+ #
394
+ # Get a list of all versions
395
+
305
396
 
306
397
 
307
398
  ##
@@ -2,7 +2,7 @@ class Fastly
2
2
  # An individual host you want to serve assets off
3
3
  class Backend < BelongsToServiceAndVersion
4
4
  attr_accessor :service_id, :name, :address, :ipv4, :ipv6, :hostname, :use_ssl, :client_cert, :port,
5
- :connect_timeout, :first_byte_timeout, :between_bytes_timeout, :error_threshold, :max_conn, :weight, :comment
5
+ :connect_timeout, :first_byte_timeout, :between_bytes_timeout, :error_threshold, :max_conn, :weight, :comment, :healthcheck
6
6
 
7
7
  ##
8
8
  # :attr: service_id
@@ -94,6 +94,11 @@ class Fastly
94
94
  # :attr: weight
95
95
  #
96
96
  # the weight assigned to this backend (default 100)
97
+
98
+ ##
99
+ # :attr: healthcheck
100
+ #
101
+ # the name of a healthcheck to associate with this backend. See the Healthcheck object
97
102
 
98
103
  end
99
104
  end
@@ -43,5 +43,21 @@ class Fastly
43
43
  # :attr: comment
44
44
  #
45
45
  # a free form comment field
46
+
47
+ # Add a Backend object to a Director
48
+ #
49
+ # Return true on success and false on failure
50
+ def add_backend(backend)
51
+ hash = fetcher.client.post(Fastly::Director.put_path(self)+"/backend/#{backend.name}")
52
+ return !hash.nil?
53
+ end
54
+
55
+ # Delete a Backend object from a Director
56
+ #
57
+ # Return true on success and false on failure
58
+ def delete_backend(backend)
59
+ hash = fetcher.client.delete(Fastly::Director.put_path(self)+"/backend/#{backend.name}")
60
+ return !hash.nil?
61
+ end
46
62
  end
47
63
  end
@@ -0,0 +1,64 @@
1
+ class Fastly
2
+ # A way of keeping track of any of your hosts which are down
3
+ class Healthcheck < BelongsToServiceAndVersion
4
+ attr_accessor :service_id, :name, :comment, :path, :host, :http_version, :timeout, :window, :threshold
5
+
6
+ ##
7
+ # :attr: service_id
8
+ #
9
+ # The id of the service this belongs to.
10
+ #
11
+
12
+ ##
13
+ # :attr: version
14
+ #
15
+ # The number of the version this belongs to.
16
+ #
17
+
18
+ ##
19
+ # :attr: name
20
+ #
21
+ # The name of this Healthcheck
22
+ #
23
+
24
+ ##
25
+ # :attr: comment
26
+ #
27
+ # A free form comment field
28
+
29
+ ##
30
+ # :attr: method
31
+ #
32
+ # Which HTTP method to use
33
+
34
+ ##
35
+ # :attr: host
36
+ #
37
+ # Which host to check
38
+
39
+ ##
40
+ # :attr: path
41
+ #
42
+ # Path to check
43
+
44
+ ##
45
+ # :attr: http_version
46
+ #
47
+ # 1.0 or 1.1 (defaults to 1.1)
48
+
49
+ ##
50
+ # :attr: timeout
51
+ #
52
+ # Timeout in seconds
53
+
54
+ ##
55
+ # :attr: window
56
+ #
57
+ # How large window to keep track for healthchecks
58
+
59
+ ##
60
+ # :attr: threshold
61
+ #
62
+ # How many have to be ok for it work
63
+ end
64
+ end
@@ -19,5 +19,22 @@ class Fastly
19
19
  # :attr: name
20
20
  #
21
21
  # The domain name of this domain
22
+
23
+
24
+ # Add a Director object to an Origin
25
+ #
26
+ # Return true on success and false on failure
27
+ def add_director(director)
28
+ hash = fetcher.client.post(Fastly::Origin.put_path(self)+"/director/#{director.name}")
29
+ return !hash.nil?
30
+ end
31
+
32
+ # Delete a Director object from an Origin
33
+ #
34
+ # Return true on success and false on failure
35
+ def delete_director(director)
36
+ hash = fetcher.client.delete(Fastly::Origin.put_path(self)+"/director/#{director.name}")
37
+ return !hash.nil?
38
+ end
22
39
  end
23
40
  end
@@ -1,7 +1,7 @@
1
1
  class Fastly
2
2
  # Represents something you want to serve - this can be, for example, a whole web site, a Wordpress site, or just your image servers
3
3
  class Service < Base
4
- attr_accessor :id, :customer, :name, :comment
4
+ attr_accessor :id, :customer_id, :name, :comment
5
5
  @versions = []
6
6
 
7
7
  ##
@@ -11,7 +11,7 @@ class Fastly
11
11
  #
12
12
 
13
13
  ##
14
- # :attr: customer
14
+ # :attr: customer_id
15
15
  #
16
16
  # The id of the customer this belongs to
17
17
  #
@@ -73,11 +73,7 @@ class Fastly
73
73
  # Get a sorted array of all the versions that this service has had.
74
74
  def versions
75
75
  raise Fastly::FullAuthRequired unless fetcher.fully_authed?
76
- versions = []
77
- @versions.each_pair { |number, version|
78
- versions.push Fastly::Version.new({ :number => number, :service_id => self.id, :comment => version['comment'] || "" }, fetcher)
79
- }
80
- versions.sort {|a,b| a.number.to_i <=> b.number.to_i }
76
+ @versions.map { |v| Fastly::Version.new(v, fetcher) }.sort { |a,b| a.number.to_i <=> b.number.to_i }
81
77
  end
82
78
 
83
79
  # Get an individual Version object. By default returns the latest version
@@ -85,12 +81,11 @@ class Fastly
85
81
  raise Fastly::FullAuthRequired unless fetcher.fully_authed?
86
82
  versions[number]
87
83
  end
88
-
89
- end
90
-
91
- # Get a list of all the services that the current customer has.
92
- def list_services(opts={})
93
- list(Fastly::Service, opts)
84
+
85
+ # Get the Customer object for this Service
86
+ def customer
87
+ fetcher.get(Fastly::Customer, customer_id)
88
+ end
94
89
  end
95
90
 
96
91
  # Search all the services that the current customer has.
@@ -33,7 +33,7 @@ class Fastly
33
33
 
34
34
  # :nodoc:
35
35
  def self.list_path(opts={})
36
- raise "You can't list settings"
36
+ nil
37
37
  end
38
38
 
39
39
  # :nodoc:
@@ -0,0 +1,65 @@
1
+ class Fastly
2
+ # An endpoint to stream syslogs to
3
+ class Syslog < BelongsToServiceAndVersion
4
+ attr_accessor :service_id, :name, :comment, :ipv4, :ipv6, :hostname, :port, :format
5
+
6
+ ##
7
+ # :attr: service_id
8
+ #
9
+ # The id of the service this belongs to.
10
+ #
11
+
12
+ ##
13
+ # :attr: version
14
+ #
15
+ # The number of the version this belongs to.
16
+ #
17
+
18
+ ##
19
+ # :attr: name
20
+ #
21
+ # The domain name of this domain
22
+ #
23
+
24
+ ##
25
+ # :attr: comment
26
+ #
27
+ # a free form comment field
28
+
29
+ ##
30
+ # :attr: address
31
+ #
32
+ # A magic field - will automagically be set to whichever of ipv4, ipv6 or hostname is currently set.
33
+ #
34
+ # Conversely if you set the address field then the correct field from ipv4, ipv6 or hostname will be set.
35
+
36
+ ##
37
+ # :attr: ipv4
38
+ #
39
+ # the ipv4 address of the host to stream logs to (this, hostname or ipv6 must be set)
40
+
41
+
42
+ ##
43
+ # :attr: ipv6
44
+ #
45
+ # the ipv6 address of the host to stream logs to (this, hostname or ipv4 must be set)
46
+
47
+
48
+ ##
49
+ # :attr: hostname
50
+ #
51
+ # the hostname to to stream logs to (this, ipv4 or ipv6 must be set)
52
+
53
+
54
+ ##
55
+ # :attr: port
56
+ #
57
+ # the port to stream logs to (defaults to 514)
58
+
59
+
60
+ ##
61
+ # :attr: format
62
+ #
63
+ # Format to log like in apache format
64
+ end
65
+ end
@@ -14,20 +14,20 @@ module CommonTests
14
14
  settings = @fastly.get_settings(service.id, version.number)
15
15
  assert settings
16
16
  assert_equal settings.service_id, service.id
17
- assert_equal settings.version, version.number
17
+ assert_equal settings.version.to_s, version.number.to_s
18
18
 
19
19
  default_ttl = settings.settings['general.default_ttl']
20
20
  settings = version.settings
21
21
  assert settings
22
22
  assert_equal settings.service_id, service.id
23
- assert_equal settings.version, version.number
23
+ assert_equal settings.version.to_s, version.number.to_s
24
24
  assert_equal settings.settings['general.default_ttl'], default_ttl
25
25
 
26
26
  settings.settings['general.default_ttl'] = default_ttl = "888888888"
27
27
  settings.save!;
28
28
 
29
29
  settings = version.settings
30
- assert_equal settings.settings['general.default_ttl'], default_ttl;
30
+ assert_equal settings.settings['general.default_ttl'].to_s, default_ttl;
31
31
 
32
32
  services = @fastly.list_services
33
33
  assert !services.empty?
@@ -62,19 +62,19 @@ module CommonTests
62
62
  backend = @fastly.create_backend(:service_id => service.id, :version => number, :address => '74.125.224.146', :name => backend_name)
63
63
  assert backend
64
64
  assert_equal backend.service_id, service.id
65
- assert_equal backend.ipv4, '74.125.224.146'
65
+ #assert_equal backend.ipv4, '74.125.224.146'
66
66
  assert_equal backend.address, '74.125.224.146'
67
- assert_equal backend.port, '80'
67
+ assert_equal backend.port.to_s, '80'
68
68
 
69
- backend.hostname = 'thegestalt.org'
69
+ backend.address = 'thegestalt.org'
70
70
  backend.port = '9092'
71
71
  @fastly.update_backend(backend)
72
72
  backend = @fastly.get_backend(service.id, number, backend_name)
73
73
 
74
74
  assert backend
75
75
  assert_equal backend.address, 'thegestalt.org'
76
- assert_equal backend.hostname, 'thegestalt.org'
77
- assert_equal backend.port, '9092'
76
+ #assert_equal backend.hostname, 'thegestalt.org'
77
+ assert_equal backend.port.to_s, '9092'
78
78
 
79
79
 
80
80
  domain_name = "fastly-test-domain-#{get_rand}-example.com"
@@ -99,6 +99,9 @@ module CommonTests
99
99
  assert_equal director.version_number.to_s, number.to_s
100
100
  assert_equal director.version.number.to_s, number.to_s
101
101
 
102
+ assert director.add_backend(backend)
103
+ generated2 = version3.generated_vcl
104
+
102
105
  origin_name = "fastly-test-origin-#{get_rand}"
103
106
  origin = @fastly.create_origin(:service_id => service.id, :version => number, :name => origin_name)
104
107
  assert origin
@@ -144,9 +147,27 @@ module CommonTests
144
147
  assert invoice
145
148
  assert invoice.regions
146
149
  assert_equal invoice.service_id, service.id
147
-
150
+
148
151
  invoices = @fastly.list_invoices
149
152
  services = @fastly.list_services
153
+ begin
154
+ customer = @fastly.current_customer
155
+ services = services.select { |s| s.customer_id == customer.id }
156
+ rescue
157
+ end
158
+
159
+ assert_equal invoices.size, services.size
160
+ assert_equal Fastly::Invoice, invoices[0].class
161
+ assert invoices[0].service_id
162
+
163
+ invoices = @fastly.list_invoices(Time.now.year, Time.now.month)
164
+ services = @fastly.list_services
165
+ begin
166
+ customer = @fastly.current_customer
167
+ services = services.select { |s| s.customer_id == customer.id }
168
+ rescue
169
+ end
170
+
150
171
  assert_equal invoices.size, services.size
151
172
  assert_equal Fastly::Invoice, invoices[0].class
152
173
  assert invoices[0].service_id
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- version: "0.5"
8
+ - 9
9
+ version: "0.9"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Fastly Inc
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-11-02 00:00:00 Z
17
+ date: 2011-12-15 00:00:00 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: json
@@ -88,6 +88,7 @@ extra_rdoc_files: []
88
88
 
89
89
  files:
90
90
  - .gitignore
91
+ - Changes
91
92
  - Gemfile
92
93
  - README.md
93
94
  - Rakefile
@@ -102,11 +103,13 @@ files:
102
103
  - lib/fastly/director.rb
103
104
  - lib/fastly/domain.rb
104
105
  - lib/fastly/fetcher.rb
106
+ - lib/fastly/healthcheck.rb
105
107
  - lib/fastly/invoice.rb
106
108
  - lib/fastly/match.rb
107
109
  - lib/fastly/origin.rb
108
110
  - lib/fastly/service.rb
109
111
  - lib/fastly/settings.rb
112
+ - lib/fastly/syslog.rb
110
113
  - lib/fastly/user.rb
111
114
  - lib/fastly/vcl.rb
112
115
  - lib/fastly/version.rb