akamai_api 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -0
  3. data/.yardopts +4 -0
  4. data/Gemfile +16 -0
  5. data/README.md +53 -52
  6. data/Thorfile +7 -1
  7. data/akamai_api.gemspec +1 -7
  8. data/bin/akamai_api +2 -1
  9. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_credentials.yml +1 -1
  10. data/cassettes/akamai_api_ccu_arl_invalidate/invalid_item.yml +1 -1
  11. data/cassettes/akamai_api_ccu_arl_invalidate/multiple_items.yml +1 -1
  12. data/cassettes/akamai_api_ccu_arl_invalidate/single_item.yml +1 -1
  13. data/cassettes/akamai_api_ccu_arl_remove/invalid_credentials.yml +1 -1
  14. data/cassettes/akamai_api_ccu_arl_remove/invalid_item.yml +2 -2
  15. data/cassettes/akamai_api_ccu_arl_remove/multiple_items.yml +1 -1
  16. data/cassettes/akamai_api_ccu_arl_remove/single_item.yml +1 -1
  17. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_credentials.yml +1 -1
  18. data/cassettes/akamai_api_ccu_cpcode_invalidate/invalid_item.yml +1 -1
  19. data/cassettes/akamai_api_ccu_cpcode_invalidate/multiple_items.yml +1 -1
  20. data/cassettes/akamai_api_ccu_cpcode_invalidate/single_item.yml +1 -1
  21. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_credentials.yml +1 -1
  22. data/cassettes/akamai_api_ccu_cpcode_remove/invalid_item.yml +1 -1
  23. data/cassettes/akamai_api_ccu_cpcode_remove/multiple_items.yml +1 -1
  24. data/cassettes/akamai_api_ccu_cpcode_remove/single_item.yml +1 -1
  25. data/cassettes/akamai_api_eccu_all_ids/invalid_credentials.yml +68 -0
  26. data/cassettes/akamai_api_eccu_all_ids/successful.yml +72 -0
  27. data/cassettes/akamai_api_eccu_destroy/invalid_credentials.yml +69 -0
  28. data/cassettes/akamai_api_eccu_destroy/not_found_request.yml +55 -0
  29. data/cassettes/akamai_api_eccu_destroy/successful.yml +57 -0
  30. data/cassettes/akamai_api_eccu_find/invalid_credentials.yml +69 -0
  31. data/cassettes/akamai_api_eccu_find/not_found_request.yml +55 -0
  32. data/cassettes/akamai_api_eccu_find/successful.yml +70 -0
  33. data/cassettes/akamai_api_eccu_find/successful_without_content.yml +70 -0
  34. data/cassettes/akamai_api_eccu_publish/invalid_credentials.yml +5 -5
  35. data/cassettes/akamai_api_eccu_publish/invalid_domain.yml +7 -7
  36. data/cassettes/akamai_api_eccu_publish/successful.yml +8 -8
  37. data/cassettes/akamai_api_eccu_update_email/invalid_credentials.yml +69 -0
  38. data/cassettes/akamai_api_eccu_update_email/not_found_request.yml +55 -0
  39. data/cassettes/akamai_api_eccu_update_email/successful.yml +57 -0
  40. data/cassettes/akamai_api_eccu_update_notes/invalid_credentials.yml +70 -0
  41. data/cassettes/akamai_api_eccu_update_notes/not_found_request.yml +56 -0
  42. data/cassettes/akamai_api_eccu_update_notes/successful.yml +58 -0
  43. data/features/ccu_arl_invalidate.feature +5 -9
  44. data/features/ccu_arl_remove.feature +5 -9
  45. data/features/ccu_cpcode_invalidate.feature +2 -6
  46. data/features/ccu_cpcode_remove.feature +2 -6
  47. data/features/ccu_purge_status.feature +2 -2
  48. data/features/eccu_publish.feature +6 -42
  49. data/features/step_definitions/file_named_with_content_steps.rb +3 -0
  50. data/features/support/env.rb +12 -3
  51. data/lib/akamai_api/ccu/base_response.rb +27 -0
  52. data/lib/akamai_api/ccu/error.rb +38 -0
  53. data/lib/akamai_api/ccu/purge/request.rb +58 -11
  54. data/lib/akamai_api/ccu/purge/response.rb +15 -9
  55. data/lib/akamai_api/ccu/purge.rb +14 -3
  56. data/lib/akamai_api/ccu/purge_status/not_found.rb +18 -0
  57. data/lib/akamai_api/ccu/purge_status/request.rb +41 -7
  58. data/lib/akamai_api/ccu/purge_status/response.rb +49 -3
  59. data/lib/akamai_api/ccu/purge_status.rb +17 -9
  60. data/lib/akamai_api/ccu/status/request.rb +20 -7
  61. data/lib/akamai_api/ccu/status/response.rb +8 -2
  62. data/lib/akamai_api/ccu/status.rb +13 -2
  63. data/lib/akamai_api/ccu/unrecognized_option.rb +6 -0
  64. data/lib/akamai_api/ccu.rb +132 -23
  65. data/lib/akamai_api/cli/app.rb +15 -13
  66. data/lib/akamai_api/cli/ccu/arl.rb +10 -4
  67. data/lib/akamai_api/cli/ccu/base.rb +11 -3
  68. data/lib/akamai_api/cli/ccu/cp_code.rb +10 -4
  69. data/lib/akamai_api/cli/ccu/purge_renderer.rb +1 -1
  70. data/lib/akamai_api/cli/ccu/status_renderer.rb +46 -26
  71. data/lib/akamai_api/cli/ccu.rb +2 -4
  72. data/lib/akamai_api/cli/command.rb +60 -25
  73. data/lib/akamai_api/cli/eccu/base.rb +59 -0
  74. data/lib/akamai_api/cli/eccu/entry_renderer.rb +5 -3
  75. data/lib/akamai_api/cli/eccu.rb +2 -56
  76. data/lib/akamai_api/cli.rb +2 -6
  77. data/lib/akamai_api/eccu/base_edit_request.rb +51 -0
  78. data/lib/akamai_api/eccu/base_request.rb +32 -0
  79. data/lib/akamai_api/eccu/destroy_request.rb +30 -0
  80. data/lib/akamai_api/eccu/find_request.rb +45 -0
  81. data/lib/akamai_api/eccu/find_response.rb +110 -0
  82. data/lib/akamai_api/eccu/invalid_domain.rb +7 -0
  83. data/lib/akamai_api/eccu/list_request.rb +21 -0
  84. data/lib/akamai_api/eccu/not_found.rb +6 -0
  85. data/lib/akamai_api/eccu/publish_request.rb +75 -0
  86. data/lib/akamai_api/eccu/soap_body.rb +99 -0
  87. data/lib/akamai_api/eccu/update_attribute_request.rb +62 -0
  88. data/lib/akamai_api/eccu.rb +19 -0
  89. data/lib/akamai_api/eccu_request.rb +39 -117
  90. data/lib/akamai_api/error.rb +5 -0
  91. data/lib/akamai_api/unauthorized.rb +6 -0
  92. data/lib/akamai_api/version.rb +1 -1
  93. data/lib/akamai_api.rb +18 -4
  94. data/spec/features/ccu/purge_request_spec.rb +10 -12
  95. data/spec/features/ccu/purge_status_request_spec.rb +5 -5
  96. data/spec/features/ccu/status_request_spec.rb +3 -3
  97. data/spec/features/eccu/destroy_spec.rb +28 -0
  98. data/spec/features/eccu/find_request_spec.rb +34 -0
  99. data/spec/features/eccu/list_request_spec.rb +22 -0
  100. data/spec/features/eccu/publish_request_spec.rb +29 -0
  101. data/spec/features/eccu/update_email_spec.rb +28 -0
  102. data/spec/features/eccu/update_notes_spec.rb +28 -0
  103. data/spec/lib/akamai_api/ccu/{response_spec.rb → base_response_spec.rb} +2 -2
  104. data/spec/lib/akamai_api/ccu/purge/request_spec.rb +26 -20
  105. data/spec/lib/akamai_api/ccu/purge/response_spec.rb +16 -26
  106. data/spec/lib/akamai_api/ccu/purge_status/not_found_response_spec.rb +34 -34
  107. data/spec/lib/akamai_api/ccu/purge_status/request_spec.rb +24 -12
  108. data/spec/lib/akamai_api/ccu/purge_status/{successful_response_spec.rb → response_spec.rb} +8 -8
  109. data/spec/lib/akamai_api/ccu/status/request_spec.rb +6 -6
  110. data/spec/lib/akamai_api/ccu/status/response_spec.rb +2 -2
  111. data/spec/lib/akamai_api/ccu_spec.rb +7 -7
  112. data/spec/lib/akamai_api/cli/ccu/status_renderer_spec.rb +5 -17
  113. data/spec/lib/akamai_api/eccu/destroy_request_spec.rb +75 -0
  114. data/spec/lib/akamai_api/eccu/find_request_spec.rb +74 -0
  115. data/spec/lib/akamai_api/eccu/find_response_spec.rb +159 -0
  116. data/spec/lib/akamai_api/eccu/list_request_spec.rb +43 -0
  117. data/spec/lib/akamai_api/eccu/publish_request_spec.rb +133 -0
  118. data/spec/lib/akamai_api/eccu/soap_body_spec.rb +46 -0
  119. data/spec/lib/akamai_api/eccu/update_attribute_request_spec.rb +86 -0
  120. data/spec/lib/akamai_api/eccu_request_spec.rb +149 -158
  121. data/spec/spec_helper.rb +11 -3
  122. metadata +90 -104
  123. data/lib/akamai_api/ccu/purge_status/not_found_response.rb +0 -9
  124. data/lib/akamai_api/ccu/purge_status/successful_response.rb +0 -25
  125. data/lib/akamai_api/ccu/response.rb +0 -18
  126. data/lib/akamai_api/soap_body.rb +0 -40
  127. data/spec/lib/akamai_api/soap_body_spec.rb +0 -48
  128. data/spec/support/savon_backports.rb +0 -10
@@ -1,8 +1,4 @@
1
- require 'thor'
1
+ require "akamai_api/cli/app"
2
2
 
3
- %w(command ccu eccu app).each do |file|
4
- require File.expand_path "../cli/#{file}", __FILE__
5
- end
6
-
7
- module AkamaiApi::Cli
3
+ module AkamaiApi::CLI
8
4
  end
@@ -0,0 +1,51 @@
1
+ require "akamai_api/eccu/base_request"
2
+ require "akamai_api/eccu/not_found"
3
+ require "akamai_api/eccu/soap_body"
4
+
5
+ module AkamaiApi::ECCU
6
+ # @abstract
7
+ #
8
+ # This class is intended as a generic superclass for all requests that operate on an existing
9
+ # purge request submitted through the Akamai ECCU interface.
10
+ class BaseEditRequest < BaseRequest
11
+ # ECCU Request code
12
+ # @return [String] request code
13
+ attr_reader :code
14
+
15
+ # @param code ECCU request code
16
+ def initialize code
17
+ @code = code.to_i
18
+ end
19
+
20
+ protected
21
+
22
+ # Creates the request body filling it with all necessary arguments
23
+ #
24
+ # The base implementation fills only the request code. If the request needs additional
25
+ # arguments you'll want to overwrite it like the following:
26
+ # class MyCustomRequest < AkamaiApi::ECCU::BaseEditRequest
27
+ # def request_body code, name, surname
28
+ # super code do |block|
29
+ # block.string(:name, name).string(:surname, surname)
30
+ # end
31
+ # end
32
+ # end
33
+ # @return [SoapBody]
34
+ def request_body *args, &block
35
+ SoapBody.new.tap do |block|
36
+ block.integer :fileId, code
37
+ yield block if block_given?
38
+ end
39
+ end
40
+
41
+ # Wrapper method that you can use inside your custom ECCU request to handle common errors
42
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
43
+ # @raise [AkamaiApi::ECCU::NotFound] when no request can be found with the given code
44
+ def with_soap_error_handling &block
45
+ super
46
+ rescue Savon::SOAPFault => e
47
+ e = ::AkamaiApi::ECCU::NotFound if e.to_hash[:fault][:faultstring] =~ /fileId .* does not exist/
48
+ raise e
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,32 @@
1
+ require "akamai_api/unauthorized"
2
+
3
+ module AkamaiApi::ECCU
4
+ # @abstract
5
+ #
6
+ # This class is intended as a generic superclass for all the specific requests that can be used
7
+ # with the Akamai ECCU interface
8
+ class BaseRequest
9
+ protected
10
+
11
+ # Wrapper method that you can use inside your custom ECCU request to handle common errors
12
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
13
+ def with_soap_error_handling &block
14
+ yield
15
+ rescue Savon::HTTPError => e
16
+ e = ::AkamaiApi::Unauthorized if e.http.code == 401
17
+ raise e
18
+ end
19
+
20
+ # Executes a method via Savon and returns the response
21
+ # @param [String] method method name to call
22
+ # @param args additional arguments to pass to savon when calling the method
23
+ # @return [Object] the object containing the received response
24
+ def client_call method, *args
25
+ client.call(method, *args).body["#{method}_response".to_sym]
26
+ end
27
+
28
+ def client
29
+ AkamaiApi::ECCU.client
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ require "akamai_api/eccu/base_edit_request"
2
+
3
+ module AkamaiApi::ECCU
4
+ # The {DestroyRequest} class is used to delete an ECCU request.
5
+ #
6
+ # @example
7
+ # AkamaiApi::ECCU::DestroyRequest.execute(12345)
8
+ class DestroyRequest < BaseEditRequest
9
+ # Deletes an ECCU request
10
+ # @param [Fixnum] code request code
11
+ # @return [true] when the request has been deleted
12
+ # @return [false] when the request cannot be deleted
13
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
14
+ # @raise [AkamaiApi::ECCU::NotFound] when no request can be found with the given code
15
+ def self.execute code
16
+ new(code).execute
17
+ end
18
+
19
+ # Deletes an ECCU request
20
+ # @return [true] when the request has been deleted
21
+ # @return [false] when the request cannot be deleted
22
+ # @raise [AkamaiApi::Unauthorized] when login credentials are invalid
23
+ # @raise [AkamaiApi::ECCU::NotFound] when no request can be found with the given code
24
+ def execute
25
+ with_soap_error_handling do
26
+ client_call(:delete, message: request_body.to_s)[:success]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,45 @@
1
+ require "akamai_api/eccu/base_edit_request"
2
+ require "akamai_api/eccu/find_response"
3
+
4
+ module AkamaiApi::ECCU
5
+ # The {FindRequest} class is used to get the details of an ECCU request.
6
+ #
7
+ # @example
8
+ # begin
9
+ # res = AkamaiApi::ECCU::FindRequest.execute 12345, false
10
+ # puts "Request found, in status #{res.status[:message]}"
11
+ # rescue AkamaiApi::Unauthorized
12
+ # puts "Invalid credentials"
13
+ # rescue AkamaiApi::NotFound
14
+ # puts "No request found with the given code"
15
+ # end
16
+ class FindRequest < BaseEditRequest
17
+ # Returns the details of an ECCU request
18
+ # @param [Fixnum] code request code
19
+ # @param [true,false] retrieve_content set to true if you want to retrieve request content too
20
+ # @return [FindResponse]
21
+ def self.execute code, retrieve_content = false
22
+ new(code).execute(retrieve_content)
23
+ end
24
+
25
+ # Returns the details of an ECCU request
26
+ # @param [true,false] retrieve_content set to true if you want to retrieve request content too
27
+ # @return [FindResponse]
28
+ def execute retrieve_content = false
29
+ with_soap_error_handling do
30
+ response = client_call :get_info, message: request_body(retrieve_content).to_s
31
+ FindResponse.new response[:eccu_info]
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ # Creates the request body filling it with all necessary arguments
38
+ # @return [SoapBody]
39
+ def request_body retrieve_content
40
+ super do |block|
41
+ block.boolean :retrieveContents, retrieve_content == true
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,110 @@
1
+ require 'base64'
2
+
3
+ module AkamaiApi::ECCU
4
+ # {FindResponse} exposes the response received when requesting the details of an Akamai ECCU request
5
+ class FindResponse
6
+ # Raw response object
7
+ # @return [Hash] raw response object
8
+ attr_reader :raw
9
+
10
+ # @param [Hash] raw raw response object
11
+ def initialize raw
12
+ @raw = raw
13
+ end
14
+
15
+ # Request code
16
+ # @return [Fixnum] request code
17
+ def code
18
+ raw[:file_id]
19
+ end
20
+
21
+ # @!method notes
22
+ # Notes of the request
23
+ # @return [String] notes of the request
24
+ # @!method email
25
+ # Email to be notified when the request becomes completed
26
+ # @return [String] email to be notified when the request becomes completed
27
+ # @!method updated_at
28
+ # Last time the request was updated
29
+ # @return [String] last time the request was updated
30
+ # @!method uploaded_by
31
+ # User that submitted the request
32
+ # @return [String] user name
33
+ # @!method uploaded_at
34
+ # Time the request was uploaded
35
+ # @return [String] time the request was uploaded
36
+ # @!method version
37
+ # version of the request
38
+ # @return [String] version of the request
39
+ {
40
+ :notes => :notes,
41
+ :email => :status_change_email,
42
+ :updated_at => :update_date,
43
+ :uploaded_at => :upload_date,
44
+ :uploaded_by => :uploaded_by,
45
+ :version => :version_string
46
+ }.each do |local_field, soap_field|
47
+ define_method local_field do
48
+ get_if_string(raw[soap_field])
49
+ end
50
+ end
51
+
52
+ alias_method :status_change_email, :email
53
+ alias_method :update_date, :updated_at
54
+ alias_method :upload_date, :uploaded_at
55
+ alias_method :version_string, :version
56
+
57
+ # Uploaded file details
58
+ # @return [Hash] file details
59
+ # - :content [String] file content
60
+ # - :size [Fixnum] file size
61
+ # - :name [String] file name
62
+ # - :md5 [String] MD5 digest of the file content
63
+ def file
64
+ content64 = get_if_string(raw[:contents])
65
+ {
66
+ :content => content64 ? Base64.decode64(content64) : nil,
67
+ :size => raw[:file_size].to_i,
68
+ :name => get_if_string(raw[:filename]),
69
+ :md5 => get_if_string(raw[:md5_digest])
70
+ }.reject { |k, v| v.nil? }
71
+ end
72
+
73
+ # Request status
74
+ # @return [Hash] request status
75
+ # - :extended [String] extended status message
76
+ # - :code [Fixnum] status code
77
+ # - :message [String] status message
78
+ # - :updated_at [String] last time the status has been updated
79
+ def status
80
+ {
81
+ :extended => get_if_string(raw[:extended_status_message]),
82
+ :code => raw[:status_code].to_i,
83
+ :message => get_if_string(raw[:status_message]),
84
+ :updated_at => get_if_string(raw[:status_update_date])
85
+ }.reject { |k, v| v.nil? }
86
+ end
87
+
88
+ # Digital property details
89
+ # @return [Hash] property details
90
+ # - :name [String]
91
+ # - :exact_match [true,false]
92
+ # - :type [String]
93
+ def property
94
+ {
95
+ :name => get_if_string(raw[:property_name]),
96
+ :exact_match => (raw[:property_name_exact_match] == true),
97
+ :type => get_if_string(raw[:property_type])
98
+ }.reject { |k, v| v.nil? }
99
+ end
100
+
101
+ private
102
+
103
+ # This method is used because, for nil values, savon will respond with an hash containing all other attributes.
104
+ # If we check that the expected type is matched, we can
105
+ # prevent to retrieve wrong values
106
+ def get_if_string value
107
+ value.kind_of?(String) && value || nil
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,7 @@
1
+ require "akamai_api/error"
2
+
3
+ module AkamaiApi::ECCU
4
+ # A simple subclass of {AkamaiApi::Error} representing a domain the user is not allowed to operate on
5
+ class InvalidDomain < AkamaiApi::Error
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ require "akamai_api/eccu/soap_body"
2
+ require "akamai_api/eccu/base_request"
3
+
4
+ module AkamaiApi::ECCU
5
+ # Use the {ListRequest} class to get the list of the last submitted ECCU requests
6
+ class ListRequest < BaseRequest
7
+ # Returns the list of the last submitted ECCU requests
8
+ # @return [Array<Fixnum>] list of request codes
9
+ def self.execute
10
+ new.execute
11
+ end
12
+
13
+ # Returns the list of the last submitted ECCU requests
14
+ # @return [Array<Fixnum>] list of request codes
15
+ def execute
16
+ with_soap_error_handling do
17
+ Array.wrap client_call(:get_ids)[:file_ids][:file_ids]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ require "akamai_api/error"
2
+
3
+ module AkamaiApi::ECCU
4
+ # A simple subclass of {AkamaiApi::Error} indicating that the requested ECCU resource cannot be found
5
+ class NotFound < AkamaiApi::Error; end
6
+ end
@@ -0,0 +1,75 @@
1
+ require 'akamai_api/eccu/invalid_domain'
2
+ require 'akamai_api/eccu/soap_body'
3
+ require "akamai_api/eccu/base_request"
4
+
5
+ module AkamaiApi::ECCU
6
+ # {PublishRequest} is responsible of publishing a new ECCU request.
7
+ #
8
+ # @example
9
+ # content = File.read './publish.xml'
10
+ # begin
11
+ # req = AkamaiApi::ECCU::PublishRequest.new 'http://foo.bar/t.txt'
12
+ # code = req.execute content, file_name: 'publish.xml', emails: 'author@mikamai.com'
13
+ # puts "Request enqueued with code #{code}"
14
+ # rescue AkamaiApi::Unauthorized
15
+ # puts "Invalid login credentials"
16
+ # end
17
+ class PublishRequest < BaseRequest
18
+ # @return [String] Digital property name
19
+ attr_reader :property_name
20
+ # @return [String] Digital property type
21
+ attr_reader :property_type
22
+ # @return [true,false] Digital property match type (true if exact)
23
+ attr_reader :property_exact_match
24
+
25
+ # @param [String] property_name Digital property name
26
+ # @param [Hash<Symbol, String>] args Additional arguments
27
+ # @option args [String] :type ('hostheader') Digital property type
28
+ # @option args [true,false] :exact_match (true) Digital property match type
29
+ def initialize property_name, args = {}
30
+ @property_name = property_name
31
+ @property_type = args.fetch(:type, 'hostheader')
32
+ @property_exact_match = args.fetch(:exact_match, true) == true
33
+ end
34
+
35
+ # Publishes a new ECCU request
36
+ # @param [String] content content of the ECCU request
37
+ # @param [Hash<Symbol, String>] args Additional arguments
38
+ # @option args [String] :file_name ('') file name to set in the request
39
+ # @option args [String] :notes ('ECCU Request using AkamaiApi <VERSION>') notes of the ECCU request
40
+ # @option args [String] :version ('') request version number
41
+ # @option args [String,Array<String>] :emails emails to notify when the request has been completed
42
+ def execute content, args = {}
43
+ with_soap_error_handling do
44
+ response = client_call :upload, message_tag: 'upload', message: request_body(content, args).to_s
45
+ response[:file_id].to_i
46
+ end
47
+ end
48
+
49
+ protected
50
+
51
+ # Creates the request body filling it with all necessary arguments
52
+ # @return [SoapBody]
53
+ def request_body content, args
54
+ SoapBody.new.tap do |body|
55
+ body.string :filename, args.fetch(:file_name, '')
56
+ body.text :contents, content
57
+ body.string :notes, args.fetch(:notes, "ECCU Request using AkamaiApi #{AkamaiApi::VERSION}")
58
+ body.string :versionString, args.fetch(:version, '')
59
+ if args[:emails]
60
+ body.string :statusChangeEmail, Array.wrap(args[:emails]).join(',')
61
+ end
62
+ body.string :propertyName, property_name
63
+ body.string :propertyType, property_type
64
+ body.boolean :propertyNameExactMatch, property_exact_match
65
+ end
66
+ end
67
+
68
+ def with_soap_error_handling &block
69
+ super
70
+ rescue Savon::SOAPFault => e
71
+ e = AkamaiApi::ECCU::InvalidDomain if e.to_hash[:fault][:faultstring].include? 'You are not authorized to specify this digital property'
72
+ raise e
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,99 @@
1
+ require "builder"
2
+
3
+ module AkamaiApi::ECCU
4
+ # Utility class used by the ECCU request classes to fill the request payload with the arguments
5
+ # requested by a SOAP method.
6
+ #
7
+ # @note Theoretically this class shouldn't exist because Savon should be able to understand
8
+ # the provided wsdl correctly and the request payload should be filled using its helpers.
9
+ # In practice, at least with Savon v2.2, it wasn't able to do it, and this class tries to
10
+ # simplify the creation of the xml payload that encapsulate method arguments.
11
+ #
12
+ # The payload of each request is an xml describing the arguments of the method. E.g.
13
+ # <filename xsi:type="xsd:string">./publish.xml</filename>
14
+ # <contents xsi:type="xsd:base64Binary">aGVsbG8gd29ybGQ=</contents>
15
+ # <notes xsi:type="xsd:string">ECCU Request using AkamaiApi</notes>
16
+ # <versionString xsi:type="xsd:string"></versionString>
17
+ # <propertyName xsi:type="xsd:string">foo.com</propertyName>
18
+ # <propertyType xsi:type="xsd:string">hostheader</propertyType>
19
+ # <propertyNameExactMatch xsi:type="xsd:boolean">true</propertyNameExactMatch>
20
+ #
21
+ # Using this class you can create the above payload with the following code:
22
+ #
23
+ # block = SoapBody.new
24
+ # block.string :filename, './publish.xml'
25
+ # block.text :contents, 'hello world'
26
+ # block.string :notes, 'ECCU request using AkamaiApi'
27
+ # block.string :versionString, ''
28
+ # block.string :propertyName, 'foo.com'
29
+ # block.string :propertyType, 'hostheader'
30
+ # block.boolean :propertyExactMatch, true
31
+ # block.to_s
32
+ class SoapBody
33
+ TAG_TYPES = {
34
+ :boolean => 'xsd:boolean',
35
+ :integer => 'xsd:int',
36
+ :string => 'xsd:string'
37
+ }
38
+ private_constant :TAG_TYPES
39
+
40
+ attr_reader :builder
41
+ private :builder
42
+
43
+ def initialize
44
+ @builder = Builder::XmlMarkup.new
45
+ end
46
+
47
+ # Appends an argument of type text, encoding the given value in base64
48
+ # @param [String] name argument name
49
+ # @param [String] value
50
+ # @return [SoapBody]
51
+ def text name, value
52
+ builder.tag! name, Base64.encode64(value), 'xsi:type' => 'xsd:base64Binary'
53
+ self
54
+ end
55
+
56
+ # @!method boolean(name, value)
57
+ # Appends an argument of type boolean
58
+ # @param [String] name argument name
59
+ # @param [true,false] value
60
+ # @return [SoapBody]
61
+ # @!method integer(name, value)
62
+ # Appends an argument of type integer
63
+ # @param [String] name argument name
64
+ # @param [Fixnum] value
65
+ # @return [SoapBody]
66
+ # @!method string(name, value)
67
+ # Appends an argument of type string
68
+ # @param [String] name argument name
69
+ # @param [String] value
70
+ # @return [SoapBody]
71
+ TAG_TYPES.each do |type, type_code|
72
+ define_method type do |name, value|
73
+ builder.tag! name, value, 'xsi:type' => type_code
74
+ self
75
+ end
76
+ end
77
+
78
+ # Appends an argument of type array
79
+ # @param [String] name argument name
80
+ # @param [Array] values
81
+ # @return [SoapBody]
82
+ def array name, values
83
+ array_attrs = {
84
+ 'soapenc:arrayType' => "xsd:string[#{values.length}]",
85
+ 'xsi:type' => 'wsdl:ArrayOfString'
86
+ }
87
+ builder.tag! name, array_attrs do |tag|
88
+ values.each { |value| tag.item value }
89
+ end
90
+ self
91
+ end
92
+
93
+ # Returns the XML to use to set SOAP method arguments
94
+ # @return [String] the XML to use to set SOAP method arguments
95
+ def to_s
96
+ builder.target!
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,62 @@
1
+ require "akamai_api/eccu/base_edit_request"
2
+
3
+ module AkamaiApi::ECCU
4
+ # {UpdateAttributeRequest} is a generic request class that can be used to update an attribute of an ECCU request.
5
+ #
6
+ # This class is used to update the {AkamaiApi::ECCURequest#notes} or the {AkamaiApi::ECCURequest#email} attributes
7
+ #
8
+ # @example
9
+ # begin
10
+ # res = AkamaiApi::ECCU::UpdateAttributeRequest.execute 12345, 'notes', 'my new notes'
11
+ # puts "Request completed: #{res}"
12
+ # rescue AkamaiApi::ECCU::NotFound
13
+ # puts "No request can be found with the given code"
14
+ # rescue AkamaiApi::Unauthorized
15
+ # puts "Invalid login credentials"
16
+ # end
17
+ class UpdateAttributeRequest < BaseEditRequest
18
+ # @return [String] attribute to update
19
+ attr_reader :attribute
20
+
21
+ # Updates an attribute of an ECCU request
22
+ # @param [Fixnum] code request code
23
+ # @param [String] attribute name
24
+ # @param [String] value new value to set
25
+ # @return [true,false] whether the request was successful or not
26
+ def self.execute code, attribute, value
27
+ new(code, attribute).execute(value)
28
+ end
29
+
30
+ # @param [Fixnum] code request code
31
+ # @param [String] attribute name
32
+ def initialize code, attribute
33
+ super code
34
+ @attribute = attribute
35
+ end
36
+
37
+ # Updates an attribute of an ECCU request
38
+ # @param [String] value new value to set
39
+ # @return [true,false] whether the request was successful or not
40
+ def execute value
41
+ with_soap_error_handling do
42
+ client_call(:"set_#{attribute}", message: request_body(value).to_s)[:success]
43
+ end
44
+ end
45
+
46
+ protected
47
+
48
+ # Creates the request body filling it with all necessary arguments
49
+ # @return [SoapBody]
50
+ def request_body notes
51
+ super do |block|
52
+ block.string attribute_for_soap, notes
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def attribute_for_soap
59
+ attribute.to_s.camelize(:lower).to_sym
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,19 @@
1
+ module AkamaiApi::ECCU
2
+ def self.client
3
+ build_client
4
+ end
5
+
6
+ private
7
+
8
+ def self.build_client
9
+ Savon.client client_args
10
+ end
11
+
12
+ def self.client_args
13
+ {
14
+ :wsdl => File.expand_path('../../../wsdls/eccu.wsdl', __FILE__),
15
+ :basic_auth => AkamaiApi.config[:auth],
16
+ :log => AkamaiApi.config[:log]
17
+ }
18
+ end
19
+ end