fastly 1.1.4 → 1.1.5

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.
@@ -1,3 +1,4 @@
1
+ # Settings Object
1
2
  class Fastly
2
3
  # Represent arbitary key value settings for a given Version
3
4
  class Settings < Base
@@ -31,23 +32,23 @@ class Fastly
31
32
  end
32
33
 
33
34
  # :nodoc:
34
- def self.list_path(opts={})
35
+ def self.list_path(_opts = {})
35
36
  nil
36
37
  end
37
38
 
38
39
  # :nodoc:
39
40
  def self.post_path
40
- raise "You can't POST to an setting"
41
+ fail "You can't POST to an setting"
41
42
  end
42
43
 
43
44
  # :nodoc:
44
45
  def self.delete_path
45
- raise "You can't DELETE to an setting"
46
+ fail "You can't DELETE to an setting"
46
47
  end
47
48
 
48
49
  # :nodoc:
49
50
  def delete!
50
- raise "You can't delete an invoice"
51
+ fail "You can't delete an invoice"
51
52
  end
52
53
 
53
54
  # :nodoc:
@@ -58,17 +59,15 @@ class Fastly
58
59
 
59
60
  # Get the Settings object for the specified Version
60
61
  def get_settings(service, number)
61
- klass = Fastly::Settings
62
- hash = client.get(Fastly::Settings.get_path(service, number))
63
-
62
+ hash = client.get(Settings.get_path(service, number))
64
63
  return nil if hash.nil?
65
- hash["settings"] = Hash[["general.default_host", "general.default_ttl"].collect { |var| [var, hash.delete(var)] }]
66
64
 
67
- return klass.new(hash, self)
65
+ hash['settings'] = Hash[['general.default_host', 'general.default_ttl'].collect { |var| [var, hash.delete(var)] }]
66
+ Settings.new(hash, self)
68
67
  end
69
68
 
70
69
  # Update the Settings object for the specified Version
71
- def update_settings(opts={})
72
- update(Fastly::Settings, opts)
70
+ def update_settings(opts = {})
71
+ update(Settings, opts)
73
72
  end
74
73
  end
data/lib/fastly/syslog.rb CHANGED
@@ -1,70 +1,66 @@
1
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, :response_conditions
2
+ # An endpoint to stream syslogs to
3
+ class Syslog < BelongsToServiceAndVersion
4
+ attr_accessor :service_id, :name, :comment, :ipv4, :ipv6, :hostname, :port, :format, :response_conditions
5
5
 
6
- ##
7
- # :attr: service_id
8
- #
9
- # The id of the service this belongs to.
10
- #
6
+ ##
7
+ # :attr: service_id
8
+ #
9
+ # The id of the service this belongs to.
10
+ #
11
11
 
12
- ##
13
- # :attr: version
14
- #
15
- # The number of the version this belongs to.
16
- #
12
+ ##
13
+ # :attr: version
14
+ #
15
+ # The number of the version this belongs to.
16
+ #
17
17
 
18
- ##
19
- # :attr: name
20
- #
21
- # The domain name of this domain
22
- #
18
+ ##
19
+ # :attr: name
20
+ #
21
+ # The domain name of this domain
22
+ #
23
23
 
24
- ##
25
- # :attr: comment
26
- #
27
- # a free form comment field
24
+ ##
25
+ # :attr: comment
26
+ #
27
+ # a free form comment field
28
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.
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
35
 
36
- ##
37
- # :attr: ipv4
38
- #
39
- # the ipv4 address of the host to stream logs to (this, hostname or ipv6 must be set)
36
+ ##
37
+ # :attr: ipv4
38
+ #
39
+ # the ipv4 address of the host to stream logs to (this, hostname or ipv6 must be set)
40
40
 
41
+ ##
42
+ # :attr: ipv6
43
+ #
44
+ # the ipv6 address of the host to stream logs to (this, hostname or ipv4 must be set)
41
45
 
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
+ # :attr: hostname
48
+ #
49
+ # the hostname to to stream logs to (this, ipv4 or ipv6 must be set)
46
50
 
51
+ ##
52
+ # :attr: port
53
+ #
54
+ # the port to stream logs to (defaults to 514)
47
55
 
48
- ##
49
- # :attr: hostname
50
- #
51
- # the hostname to to stream logs to (this, ipv4 or ipv6 must be set)
56
+ ##
57
+ # :attr: format
58
+ #
59
+ # Format to log like in apache format
52
60
 
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
-
65
- ##
66
- # :attr: response_condition
67
- #
68
- # name of a response_condition to filter the log on, if empty it always logs
69
- end
61
+ ##
62
+ # :attr: response_condition
63
+ #
64
+ # name of a response_condition to filter the log on, if empty it always logs
65
+ end
70
66
  end
data/lib/fastly/user.rb CHANGED
@@ -25,10 +25,9 @@ class Fastly
25
25
  #
26
26
  # The role this user has (one of admin, owner, superuser, user, engineer, billing)
27
27
 
28
-
29
28
  # Get the Customer object this user belongs to
30
29
  def customer
31
- @customer ||= fetcher.get(Customer, self.customer_id)
30
+ @customer ||= fetcher.get(Customer, customer_id)
32
31
  end
33
32
 
34
33
  # Whether or not this User is the owner of the Customer they belong to
@@ -43,20 +42,19 @@ class Fastly
43
42
  :superuser => 10,
44
43
  :user => 20,
45
44
  :engineer => 30,
46
- :billing => 30,
45
+ :billing => 30
47
46
  }
48
47
 
49
48
  # Does this User have sufficient permissions to perform the given role
50
49
  def can_do?(test_role)
51
50
  test_priority = PRIORITIES[test_role.to_sym] || 1000
52
- my_priority = PRIORITIES[self.role.to_sym] || 1000
51
+ my_priority = PRIORITIES[role.to_sym] || 1000
53
52
 
54
53
  if test_priority == my_priority
55
- test_role.to_s == :owner ? owner? : test_role.to_sym == self.role.to_sym
54
+ test_role.to_s == :owner ? owner? : test_role.to_sym == role.to_sym
56
55
  else
57
56
  my_priority < test_priority
58
57
  end
59
58
  end
60
-
61
59
  end
62
60
  end
data/lib/fastly/util.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  class Fastly
2
+ # Collection of frequently used utility methods
2
3
  module Util
3
4
  def self.class_to_path(klass, append_s = false)
4
5
  klass_string = klass.to_s.split('::')[-1]
@@ -16,25 +16,21 @@ class Fastly
16
16
  #
17
17
  # The name of this version.
18
18
 
19
-
20
19
  ##
21
20
  # :attr: active
22
21
  #
23
22
  # Whether this version is active or not.
24
23
 
25
-
26
24
  ##
27
25
  # :attr: locked
28
26
  #
29
27
  # Whether this version is locked or not.
30
28
 
31
-
32
29
  ##
33
30
  # :attr: staging
34
31
  #
35
32
  # Whether this version is in staging or not.
36
33
 
37
-
38
34
  ##
39
35
  # :attr: testing
40
36
  #
@@ -54,17 +50,17 @@ class Fastly
54
50
 
55
51
  # Is this Version locked
56
52
  def locked?
57
- return @locked.to_i > 0
53
+ @locked.to_i > 0
58
54
  end
59
55
 
60
56
  # Set whether this Version is locked
61
57
  def locked=(is_locked)
62
- @locked = is_locked ? "1" : "0"
58
+ @locked = is_locked ? '1' : '0'
63
59
  end
64
60
 
65
61
  # Get the Service object this Version belongs to
66
62
  def service
67
- fetcher.get(Fastly::Service, service_id)
63
+ fetcher.get(Service, service_id)
68
64
  end
69
65
 
70
66
  # Get the Settings object for this Version
@@ -74,33 +70,34 @@ class Fastly
74
70
 
75
71
  # Is version active?
76
72
  def active?
77
- return @active.to_i > 0
73
+ @active.to_i > 0
78
74
  end
79
75
 
80
76
  # Activate this version
81
77
  def activate!
82
- hash = fetcher.client.put(Fastly::Version.put_path(self)+"/activate")
83
- return !hash.nil?
78
+ hash = fetcher.client.put("#{Version.put_path(self)}/activate")
79
+ !hash.nil?
84
80
  end
85
81
 
86
82
  # Deactivate this version
87
83
  def deactivate!
88
- hash = fetcher.client.put(Fastly::Version.put_path(self)+"/deactivate")
89
- return !hash.nil?
84
+ hash = fetcher.client.put("#{Version.put_path(self)}/deactivate")
85
+ !hash.nil?
90
86
  end
91
87
 
92
88
  # Clone this Version
93
89
  def clone
94
- hash = fetcher.client.put(Fastly::Version.put_path(self)+"/clone")
90
+ hash = fetcher.client.put("#{Version.put_path(self)}/clone")
95
91
  return nil if hash.nil?
96
- return Fastly::Version.new(hash, fetcher)
92
+ Version.new(hash, fetcher)
97
93
  end
98
94
 
99
95
  # Create an entirely new version, not cloned from the previous one.
100
96
  def self.create_new(fetcher, opts)
101
- hash = fetcher.client.post(Fastly::Version.post_path(opts))
97
+ hash = fetcher.client.post(Version.post_path(opts))
102
98
  return nil if hash.nil?
103
- return Fastly::Version.new(hash, fetcher)
99
+
100
+ Version.new(hash, fetcher)
104
101
  end
105
102
 
106
103
  # Get the generated VCL object for this Version (which must have been activated first)
@@ -108,22 +105,23 @@ class Fastly
108
105
  # Won't return the content of the VCL unless you pass in
109
106
  # :include_content => true
110
107
  # in the opts
111
- def generated_vcl(opts={})
112
- hash = fetcher.client.get(Fastly::Version.put_path(self)+"/generated_vcl", opts)
108
+ def generated_vcl(opts = {})
109
+ hash = fetcher.client.get("#{Version.put_path(self)}/generated_vcl", opts)
113
110
  opts = {
114
111
  'content' => hash['vcl'] || hash['content'],
115
112
  'name' => hash['md5'],
116
113
  'version' => hash['version'],
117
114
  'service_id' => hash['service']
118
115
  }
119
- return Fastly::VCL.new(opts, fetcher)
116
+
117
+ VCL.new(opts, fetcher)
120
118
  end
121
119
 
122
120
  # Upload a VCL file for this Version
123
121
  def upload_vcl(name, content)
124
- hash = fetcher.client.post(Fastly::Version.put_path(self)+"/vcl", :name => name, :content => content)
122
+ hash = fetcher.client.post("#{Version.put_path(self)}/vcl", name: name, content: content)
125
123
  return nil if hash.nil?
126
- return Fastly::VCL.new(hash, fetcher)
124
+ VCL.new(hash, fetcher)
127
125
  end
128
126
 
129
127
  # Upload a VCL file for this Version and set as the main VCL
@@ -136,30 +134,27 @@ class Fastly
136
134
  # Won't return the content of the VCL unless you pass in
137
135
  # :include_content => true
138
136
  # in the opts
139
- def vcl(name, opts={})
137
+ def vcl(name, opts = {})
140
138
  fetcher.get_vcl(service_id, number, name, opts)
141
139
  end
142
140
 
143
141
  # Delete a VCL file for this Version
144
142
  def delete_vcl(name)
145
- hash = fetcher.client.delete(Fastly::Version.put_path(self)+"/vcl/" + name )
146
- return nil if hash.nil?
147
- return hash
143
+ hash = fetcher.client.delete("#{Version.put_path(self)}/vcl/#{name}")
144
+ hash.nil? ? nil : hash
148
145
  end
149
146
 
150
147
  # Validate this Version
151
148
  def validate
152
- hash = fetcher.client.get(Fastly::Version.put_path(self)+"/validate")
153
- return !hash.nil?
149
+ hash = fetcher.client.get("#{Version.put_path(self)}/validate")
150
+ !hash.nil?
154
151
  end
155
152
 
156
- private
157
-
158
153
  def self.get_path(service, number)
159
154
  "/service/#{service}/version/#{number}"
160
155
  end
161
156
 
162
- def self.post_path(opts)
157
+ def self.post_path(opts = {})
163
158
  "/service/#{opts[:service_id]}/version"
164
159
  end
165
160
 
data/test/admin_test.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  require 'helper'
2
2
 
3
+ # Admin-related tests
3
4
  class AdminTest < Fastly::TestCase
4
5
  def setup
5
- opts = login_opts(:full).merge(:use_curb => false)
6
+ opts = login_opts(:full)
6
7
  begin
7
8
  @client = Fastly::Client.new(opts)
8
9
  @fastly = Fastly.new(opts)
9
- rescue Exception => e
10
+ rescue => e
10
11
  warn e.inspect
11
12
  warn e.backtrace.join("\n")
12
13
  exit(-1)
@@ -15,9 +16,9 @@ class AdminTest < Fastly::TestCase
15
16
 
16
17
  def test_creating_and_updating_customer
17
18
  return unless @fastly.current_user.can_do?(:admin)
18
- customer = @fastly.create_customer(:name => "fastly-ruby-test-customer-#{get_rand}")
19
- email = "fastly-ruby-test-#{get_rand}-new@example.com"
20
- user = @fastly.create_user(:login => email, :name => "New User")
19
+ customer = @fastly.create_customer(:name => "fastly-ruby-test-customer-#{random_string}")
20
+ email = "fastly-ruby-test-#{random_string}-new@example.com"
21
+ user = @fastly.create_user(:login => email, :name => 'New User')
21
22
  customer.owner_id = user.id
22
23
 
23
24
  tmp = @fastly.update_customer(customer)
@@ -28,10 +29,9 @@ class AdminTest < Fastly::TestCase
28
29
 
29
30
  def test_creating_and_updating_customer_with_owner
30
31
  return unless @fastly.current_user.can_do?(:admin)
31
- email = "fastly-ruby-test-#{get_rand}-new@example.com"
32
- customer = @fastly.create_customer(:name => "fastly-ruby-test-customer-#{get_rand}", :owner => { :login => email, :name => "Test NewOwner" })
32
+ email = "fastly-ruby-test-#{random_string}-new@example.com"
33
+ customer = @fastly.create_customer(:name => "fastly-ruby-test-customer-#{random_string}", :owner => { :login => email, :name => 'Test NewOwner' })
33
34
  assert customer
34
35
  assert_equal customer.owner.login, email
35
36
  end
36
-
37
37
  end
data/test/api_key_test.rb CHANGED
@@ -1,46 +1,27 @@
1
1
  require 'helper'
2
2
 
3
- class ApiKeyTest < Fastly::TestCase
4
- include CommonTests
3
+ # API Key Tests
4
+ class Fastly
5
+ describe 'ApiKeyTest' do
6
+ let(:opts) { login_opts(:api_key) }
7
+ let(:client) { Client.new(opts) }
8
+ let(:fastly) { Fastly.new(opts) }
5
9
 
6
- def setup
7
- @opts = login_opts(:api_key)
8
- begin
9
- @client = Fastly::Client.new(@opts)
10
- @fastly = Fastly.new(@opts)
11
- rescue Exception => e
12
- pp e
13
- exit(-1)
14
- end
15
- end
16
-
17
- def test_raw_client
18
- user = customer = nil
19
- assert_raise(Fastly::Error) {
20
- user = @client.get('/current_user')
21
- }
22
- assert_equal nil, user
23
-
24
- customer = @client.get('/current_customer')
25
- assert customer
26
- assert_equal @opts[:customer], customer['name']
27
- end
28
-
29
- def test_current_user_and_customer
30
- current_user = current_customer = nil
31
- assert_raise(Fastly::FullAuthRequired) {
32
- current_user = @fastly.current_user
33
- }
34
- assert_equal nil, current_user
10
+ describe '#current_{user,customer}' do
11
+ it 'should not have access to current user 'do
12
+ assert_raises(Error) do
13
+ client.get('/current_user')
14
+ end
35
15
 
36
- customer = @fastly.current_customer
37
- assert customer
38
- assert_equal @opts[:customer], customer.name
39
- end
16
+ assert_raises(FullAuthRequired) do
17
+ fastly.current_user
18
+ end
19
+ end
40
20
 
41
- def test_purging
42
- #assert @fastly.purge('foo')
43
- # TODO Won't work until we get fixtures in Heavenly
44
- #assert @fastly.purge_all('foo')
21
+ it 'should have access to current customer' do
22
+ assert_instance_of Hash, client.get('/current_customer')
23
+ assert_instance_of Customer, fastly.current_customer
24
+ end
25
+ end
45
26
  end
46
27
  end