Skip to content

Instantly share code, notes, and snippets.

@nicolaracco
Created May 22, 2014 09:08
Show Gist options
  • Save nicolaracco/61696fe570d02ffe051b to your computer and use it in GitHub Desktop.
Save nicolaracco/61696fe570d02ffe051b to your computer and use it in GitHub Desktop.
diff --git a/akamai_api.gemspec b/akamai_api.gemspec
index 36d81ee..b5eea39 100644
--- a/akamai_api.gemspec
+++ b/akamai_api.gemspec
@@ -18,7 +18,6 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
gem.add_dependency 'httparty', '~> 0.13.1'
- gem.add_dependency 'activesupport', '>= 2.3.9', '< 5.0'
gem.add_dependency 'thor', '>= 0.14.0', '< 2.0'
gem.add_dependency 'savon', '~> 2.3.0'
gem.add_dependency 'builder', '~> 3.0'
diff --git a/lib/akamai_api/ccu.rb b/lib/akamai_api/ccu.rb
index a92e3ce..ca246e5 100644
--- a/lib/akamai_api/ccu.rb
+++ b/lib/akamai_api/ccu.rb
@@ -1,5 +1,4 @@
require 'httparty'
-require 'active_support/core_ext'
require 'akamai_api/ccu/purge'
require 'akamai_api/ccu/status'
require 'akamai_api/ccu/purge_status'
@@ -30,7 +29,7 @@ module AkamaiApi
end
def status progress_uri = nil
- if progress_uri.present?
+ if progress_uri && !progress_uri.empty?
PurgeStatus::Request.new.execute progress_uri
else
Status::Request.new.execute
diff --git a/lib/akamai_api/ccu/purge/request.rb b/lib/akamai_api/ccu/purge/request.rb
index 0f1159b..0d678fb 100644
--- a/lib/akamai_api/ccu/purge/request.rb
+++ b/lib/akamai_api/ccu/purge/request.rb
@@ -34,7 +34,7 @@ module AkamaiApi::Ccu::Purge
end
def execute *items
- items = Array.wrap(items.first) if items.length == 1
+ items = items.flatten if items.one?
response = self.class.post('/', basic_auth: AkamaiApi.auth, body: request_body(items))
parse_response response
end
diff --git a/lib/akamai_api/cli/command.rb b/lib/akamai_api/cli/command.rb
index bc3a96d..30e3858 100644
--- a/lib/akamai_api/cli/command.rb
+++ b/lib/akamai_api/cli/command.rb
@@ -12,7 +12,8 @@ module AkamaiApi::CLI
config = {}
config_file = File.expand_path '~/.akamai_api.yml'
if File::exists?( config_file )
- config = YAML::load_file(config_file).symbolize_keys
+ loaded_data = YAML::load_file(config_file)
+ config = Hash[loaded_data.map { |k,v| [k.to_sym, v] }]
end
if ENV['AKAMAI_USERNAME'] && ENV['AKAMAI_PASSWORD']
config.merge! :auth => [ENV['AKAMAI_USERNAME'], ENV['AKAMAI_PASSWORD']]
diff --git a/lib/akamai_api/cli/eccu/entry_renderer.rb b/lib/akamai_api/cli/eccu/entry_renderer.rb
index 2047338..02dfae4 100644
--- a/lib/akamai_api/cli/eccu/entry_renderer.rb
+++ b/lib/akamai_api/cli/eccu/entry_renderer.rb
@@ -30,10 +30,10 @@ module AkamaiApi::CLI::Eccu
" #{entry.status[:update_date]}",
entry_property
]
- output << "* Notes : #{entry.notes}" if entry.notes.present?
+ output << "* Notes : #{entry.notes}" if entry.notes && !entry.notes.empty?
output << "* Email : #{entry.email}" if entry.email
output << "* Uploaded by #{entry.uploaded_by} on #{entry.upload_date}"
- output << "* Content:\n#{entry.file[:content]}" if entry.file[:content].present?
+ output << "* Content:\n#{entry.file[:content]}" if entry.file[:content] && !entry.file[:content].empty?
output
end
@@ -52,7 +52,7 @@ module AkamaiApi::CLI::Eccu
end
def entry_status
- if entry.status[:extended].present?
+ if entry.status[:extended] && !entry.status[:extended].empty?
"* Status : #{entry.status[:code]} - #{entry.status[:extended]}"
else
"* Status : #{entry.status[:code]}"
diff --git a/lib/akamai_api/eccu_request.rb b/lib/akamai_api/eccu_request.rb
index 7598e39..2e70353 100644
--- a/lib/akamai_api/eccu_request.rb
+++ b/lib/akamai_api/eccu_request.rb
@@ -53,14 +53,15 @@ module AkamaiApi
class << self
def all_ids
- client.call(:get_ids).body[:get_ids_response][:file_ids][:file_ids]
+ result = client.call(:get_ids).body[:get_ids_response][:file_ids][:file_ids]
+ result.is_a?(Array) && result || [result]
rescue Savon::HTTPError => e
raise ::AkamaiApi::Unauthorized if e.http.code == 401
raise
end
def all args = {}
- Array.wrap(all_ids).map { |v| EccuRequest.find v, args }
+ all_ids.map { |v| EccuRequest.find v, args }
end
def last args = {}
@@ -125,13 +126,14 @@ module AkamaiApi
private
def build_publish_soap_body property, content, args
+ emails = args[:emails].is_a?(Array) && args[:emails].join(' ') || args[:emails]
SoapBody.new do
string :filename, args[:file_name] || ''
text :contents, content
string :notes, args[:notes] || 'ECCU Request using AkamaiApi gem'
string :versionString, args[:version] || ''
if args[:emails]
- string :statusChangeEmail, Array.wrap(args[:emails]).join(' ')
+ string :statusChangeEmail, emails
end
string :propertyName, property
string :propertyType, args[:property_type] || 'hostheader'
diff --git a/spec/lib/akamai_api/eccu_request_spec.rb b/spec/lib/akamai_api/eccu_request_spec.rb
index 20f47b5..42d21d1 100644
--- a/spec/lib/akamai_api/eccu_request_spec.rb
+++ b/spec/lib/akamai_api/eccu_request_spec.rb
@@ -74,7 +74,7 @@ module AkamaiApi
EccuRequest.all.should =~ [:a, :b]
end
it 'returns the detail for each enlisted id even if only one id is returned' do
- EccuRequest.stub :all_ids => "a"
+ EccuRequest.stub :all_ids => ["a"]
EccuRequest.should_receive(:find).with('a', anything()).and_return(:a)
EccuRequest.all.should =~ [:a]
end
diff --git a/spec/support/savon_backports.rb b/spec/support/savon_backports.rb
index 003f554..857e7c5 100644
--- a/spec/support/savon_backports.rb
+++ b/spec/support/savon_backports.rb
@@ -5,6 +5,7 @@ module Savon
verify_message_without_any! unless @expected[:message] == :any
end
- alias_method_chain :verify_message!, :any
+ alias_method :verify_message_without_any!, :verify_message!
+ alias_method :verify_message!, :verify_message_with_any!
end
-end
\ No newline at end of file
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment