fastly 0.97 → 0.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changes CHANGED
@@ -1,3 +1,18 @@
1
+ 2012-02-02 v0.98
2
+
3
+ Make deactivate! work
4
+ Add active?
5
+ Add Service.purge_by_key
6
+
7
+ 2012-01-27 v0.97
8
+
9
+ Fix invoice tests with new billing API
10
+
11
+ 2012-01-16 v0.96
12
+
13
+ Fix version.locked?
14
+ Make fastly_upload_vcl work
15
+
1
16
  2011-12-19 v0.95
2
17
 
3
18
  Fix the way invoices and stats are fetched
data/lib/fastly.rb CHANGED
@@ -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.97"
8
+ VERSION = "0.98"
9
9
 
10
10
  require 'fastly/fetcher'
11
11
  require 'fastly/client'
@@ -51,17 +51,17 @@ class Fastly
51
51
  # Whether or not we're fully (username and password) authed
52
52
  # Some methods require full username and password rather than just auth token
53
53
  def fully_authed?
54
- client.authed? # for now
55
- #client.fully_authed?
54
+ client.fully_authed?
56
55
  end
57
56
 
58
57
  # Return a Customer object representing the customer of the current logged in user.
59
58
  def current_customer
60
- raise Fastly::FullAuthRequired unless self.fully_authed?
59
+ raise Fastly::AuthRequired unless self.authed?
61
60
  @current_customer ||= get(Customer)
62
61
  end
63
62
 
64
63
  # Return a User object representing the current logged in user.
64
+ # NOTE: requires you to be fully authed - will not work with only an API key
65
65
  def current_user
66
66
  raise Fastly::FullAuthRequired unless self.fully_authed?
67
67
  @current_user ||= get(User)
@@ -18,14 +18,12 @@ class Fastly
18
18
  end
19
19
 
20
20
  def list(klass, opts={})
21
- raise Fastly::FullAuthRequired unless self.fully_authed?
22
21
  list = client.get(klass.list_path, opts)
23
22
  return [] if list.nil?
24
23
  list.map { |hash| klass.new(hash, self) }
25
24
  end
26
25
 
27
26
  def get(klass, *args)
28
- raise Fastly::FullAuthRequired unless self.fully_authed?
29
27
  if [User, Customer].include?(klass) && args.empty?
30
28
  hash = client.get("/current_#{klass.path}")
31
29
  else
@@ -36,19 +34,16 @@ class Fastly
36
34
  end
37
35
 
38
36
  def create(klass, opts)
39
- raise Fastly::FullAuthRequired unless self.fully_authed?
40
37
  hash = client.post(klass.post_path(opts),opts)
41
38
  return klass.new(hash, self)
42
39
  end
43
40
 
44
41
  def update(klass, obj)
45
- raise Fastly::FullAuthRequired unless self.fully_authed?
46
42
  hash = client.put(klass.put_path(obj), obj.as_hash)
47
43
  return klass.new(hash, self)
48
44
  end
49
45
 
50
46
  def delete(klass, obj)
51
- raise Fastly::FullAuthRequired unless self.fully_authed?
52
47
  return client.delete(klass.delete_path(obj))
53
48
  end
54
49
 
@@ -38,7 +38,6 @@ class Fastly
38
38
  # * daily
39
39
  # * all
40
40
  def stats(type=:all, opts={})
41
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
42
41
  raise Fastly::Error "Unknown stats type #{type}" unless [:minutely,:hourly,:daily,:all].include?(type.to_sym)
43
42
  hash = fetcher.client.get(Fastly::Service.get_path(self.id)+"/stats/#{type}", opts)
44
43
  return hash
@@ -50,7 +49,6 @@ class Fastly
50
49
  #
51
50
  # Otherwise it returns the invoice for the current month so far.
52
51
  def invoice(year=nil, month=nil)
53
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
54
52
  opts = { :service_id => self.id }
55
53
  unless year.nil? || month.nil?
56
54
  opts[:year] = year
@@ -61,10 +59,15 @@ class Fastly
61
59
 
62
60
  # Purge all assets from this service.
63
61
  def purge_all
64
- raise Fastly::AuthRequired unless self.authed?
65
62
  res = client.put(get_path(self.id)+"/purge_all")
66
63
  end
67
64
 
65
+
66
+ # Purge anything with the specific key from the given service.
67
+ def purge_by_key(key)
68
+ res = client.put(get_path(self.id)+"/purge/#{key}")
69
+ end
70
+
68
71
  # Set all the versions that this service has had.
69
72
  def versions=(versions)
70
73
  @versions = versions
@@ -72,16 +75,19 @@ class Fastly
72
75
 
73
76
  # Get a sorted array of all the versions that this service has had.
74
77
  def versions
75
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
76
78
  @versions.map { |v| Fastly::Version.new(v, fetcher) }.sort { |a,b| a.number.to_i <=> b.number.to_i }
77
79
  end
78
80
 
79
81
  # Get an individual Version object. By default returns the latest version
80
82
  def version(number=-1)
81
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
82
83
  versions[number]
83
84
  end
84
85
 
86
+ # A deep hash of nested details
87
+ def details(opts={})
88
+ client.get(get_path(self.id)+"/details", opts);
89
+ end
90
+
85
91
  # Get the Customer object for this Service
86
92
  def customer
87
93
  fetcher.get(Fastly::Customer, customer_id)
@@ -98,7 +104,6 @@ class Fastly
98
104
  #
99
105
  # service = fastly.search_services(:name => name, :version => number)
100
106
  def search_services(opts)
101
- raise Fastly::FullAuthRequired unless self.fully_authed?
102
107
  klass = Fastly::Service
103
108
  hash = client.get(klass.post_path+"/search", opts)
104
109
  return nil if hash.nil?
@@ -54,7 +54,7 @@ class Fastly
54
54
 
55
55
  # Is this Version locked
56
56
  def locked?
57
- return @locked.to_i > 1
57
+ return @locked.to_i > 0
58
58
  end
59
59
 
60
60
  # Set whether this Version is locked
@@ -72,23 +72,25 @@ class Fastly
72
72
  fetcher.get_settings(service_id, number)
73
73
  end
74
74
 
75
+ # Is version active?
76
+ def active?
77
+ return @active.to_i > 0
78
+ end
79
+
75
80
  # Activate this version
76
81
  def activate!
77
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
78
82
  hash = fetcher.client.put(Fastly::Version.put_path(self)+"/activate")
79
83
  return !hash.nil?
80
84
  end
81
85
 
82
- # XXX Not currently
83
- # def deactivate!
84
- # raise Fastly::FullAuthRequired unless fetcher.fully_authed?
85
- # hash = fetcher.client.put(Fastly::Version.put_path(self)+"/deactivate")
86
- # return !hash.nil?
87
- # end
86
+ # Deactivate this version
87
+ def deactivate!
88
+ hash = fetcher.client.put(Fastly::Version.put_path(self)+"/deactivate")
89
+ return !hash.nil?
90
+ end
88
91
 
89
92
  # Clone this Version
90
93
  def clone
91
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
92
94
  hash = fetcher.client.put(Fastly::Version.put_path(self)+"/clone")
93
95
  return nil if hash.nil?
94
96
  return Fastly::Version.new(hash, fetcher)
@@ -100,7 +102,6 @@ class Fastly
100
102
  # :include_content => true
101
103
  # in the opts
102
104
  def generated_vcl(opts={})
103
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
104
105
  hash = fetcher.client.get(Fastly::Version.put_path(self)+"/generated_vcl", opts)
105
106
  opts = {
106
107
  'content' => hash['vcl'] || hash['content'],
@@ -113,7 +114,6 @@ class Fastly
113
114
 
114
115
  # Upload a VCL file for this Version
115
116
  def upload_vcl(name, content)
116
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
117
117
  hash = fetcher.client.post(Fastly::Version.put_path(self)+"/vcl", :name => name, :content => content)
118
118
  return nil if hash.nil?
119
119
  return Fastly::VCL.new(hash, fetcher)
@@ -125,13 +125,11 @@ class Fastly
125
125
  # :include_content => true
126
126
  # in the opts
127
127
  def vcl(name, opts={})
128
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
129
128
  fetcher.get_vcl(service_id, number, name, opts)
130
129
  end
131
130
 
132
131
  # Validate this Version
133
132
  def validate
134
- raise Fastly::FullAuthRequired unless fetcher.fully_authed?
135
133
  hash = fetcher.client.get(Fastly::Version.put_path(self)+"/validate")
136
134
  return !hash.nil?
137
135
  end
data/test/api_key_test.rb CHANGED
@@ -32,7 +32,7 @@ class ApiKeyTest < Test::Unit::TestCase
32
32
 
33
33
  def test_current_user_and_customer
34
34
  current_user = current_customer = nil
35
- assert_raise(Fastly::Error) {
35
+ assert_raise(Fastly::FullAuthRequired) {
36
36
  current_user = @fastly.current_user
37
37
  }
38
38
  assert_equal nil, current_user
data/test/common.rb CHANGED
@@ -111,11 +111,17 @@ module CommonTests
111
111
  # assert_equal origin.version.number.to_s, number.to_s
112
112
 
113
113
  assert version3.activate!
114
+ assert version3.deactivate!
115
+ assert !@fastly.get_service(version3.service_id).version.active
116
+ assert !@fastly.get_service(version3.service_id).version.active?
117
+ assert version3.activate!
118
+ assert @fastly.get_service(version3.service_id).version.active
119
+ assert @fastly.get_service(version3.service_id).version.active?
114
120
 
115
- generated = version3.generated_vcl
121
+ generated = version3.generated_vcl(:no_content => true)
116
122
  assert generated
117
123
  assert generated.content.nil?
118
- generated = version3.generated_vcl(:include_content => true)
124
+ generated = version3.generated_vcl
119
125
  assert !generated.content.nil?
120
126
  assert generated.content.match(/\.port = "9092"/ms)
121
127
 
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: 201
4
+ hash: 207
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 97
9
- version: "0.97"
8
+ - 98
9
+ version: "0.98"
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: 2012-01-27 00:00:00 Z
17
+ date: 2012-02-16 00:00:00 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: json