akamairb 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e10ba567e1374f6435f3db072e46dfa9a9f5c25d
4
+ data.tar.gz: 3de24ff9e0947772ffd6a883f703eb66ccaa938c
5
+ SHA512:
6
+ metadata.gz: 4de1861229eb773109711b294c2eedd8bd73c1530e1f094fecc06ef754f794123e564108e5364556cf58eaa28f7bfe30117d26753b5be602a6081d7e2b769bc1
7
+ data.tar.gz: 7990fae04f391f0579ba3214190d4c3d693be6f1e786f8eaa9937390111fa2eca267cb71ec422d3a115c792f3255fef6de27c69468b7a501e23d7278394bf557
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'thor'
data/Gemfile.lock ADDED
@@ -0,0 +1,10 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ thor (0.19.1)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ thor
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 the-cocktail
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Manuel Albarrán
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Akamairb
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'akamairb'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install akamairb
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/akamairb/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/akamairb.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'akamairb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "akamairb"
8
+ spec.version = Akamai::VERSION
9
+ spec.authors = ["Manuel Albarrán"]
10
+ spec.email = ["weap88@gmail.com"]
11
+ spec.summary = %q{Akamai purge tool}
12
+ spec.description = %q{Akamai purge tool}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.executables = ["akamai"]
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+
25
+ spec.add_runtime_dependency "thor"
26
+ end
data/bin/akamai ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'akamairb'
4
+
5
+ Akamai::Command.start
data/lib/akamairb.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "akamairb/version"
2
+ require 'akamairb/connection'
3
+ require 'akamairb/command'
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+ require 'thor'
3
+ require 'pp'
4
+
5
+ module Akamai
6
+ class Command < Thor
7
+
8
+ include Thor::Actions
9
+
10
+ desc "purge URLS", "purge urls from Akamai"
11
+ option :debug, :type => :boolean
12
+ def purge(*urls)
13
+ client = Akamai::Connection.new(config)
14
+ client.purge_and_progress(*urls, &printter)
15
+ puts
16
+ end
17
+
18
+ desc "show ID", "show progress of a purge"
19
+ option :debug, :type => :boolean
20
+ def show(id)
21
+ client = Akamai::Connection.new(config)
22
+ client.progress_until_done("/ccu/v2/purges/#{id}", &printter)
23
+ puts
24
+ end
25
+
26
+ private
27
+
28
+ def config
29
+ begin
30
+ config_path = "#{Dir.home}/.akamai.yml"
31
+ config_file = open(config_path)
32
+ config = YAML.load(config_file)
33
+ rescue
34
+ config = nil
35
+ end
36
+
37
+ unless config
38
+ say "Configuration is empty. Please check your '~/.akamai.yml'", :red
39
+ exit -1
40
+ end
41
+
42
+ config
43
+ end
44
+
45
+ def printter
46
+ Proc.new do |response|
47
+ if options[:debug]
48
+ puts
49
+ pp response
50
+ else
51
+ print " \r#{response["purgeId"]} => #{response["purgeStatus"]}"
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,48 @@
1
+ require "json"
2
+ require "faraday"
3
+
4
+ module Akamai
5
+ class Connection
6
+ attr_accessor :conn
7
+
8
+ def initialize(config)
9
+ self.conn = Faraday.new(:url => 'https://api.ccu.akamai.com') do |faraday|
10
+ faraday.headers['Content-Type'] = 'application/json'
11
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
12
+ faraday.basic_auth(config["user"],config["pass"])
13
+ end
14
+ end
15
+
16
+ def purge(*urls)
17
+ response = conn.post do |req|
18
+ req.url '/ccu/v2/queues/default'
19
+ req.body = JSON.dump({"objects" => urls.flatten})
20
+ end
21
+
22
+ parse response
23
+ end
24
+
25
+ def progress url
26
+ parse conn.get(url)
27
+ end
28
+
29
+ def progress_until_done url
30
+ loop do
31
+ response = progress url
32
+ yield response if block_given?
33
+ break if response["purgeStatus"] == "Done"
34
+ sleep response["pingAfterSeconds"]
35
+ end
36
+ end
37
+
38
+ def purge_and_progress *urls, &block
39
+ response = purge *urls
40
+ progress_until_done response["progressUri"], &block
41
+ end
42
+
43
+ private
44
+ def parse response
45
+ JSON.parse(response.body)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module Akamai
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: akamairb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Manuel Albarrán
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Akamai purge tool
56
+ email:
57
+ - weap88@gmail.com
58
+ executables:
59
+ - akamai
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - akamairb.gemspec
71
+ - bin/akamai
72
+ - lib/akamairb.rb
73
+ - lib/akamairb/command.rb
74
+ - lib/akamairb/connection.rb
75
+ - lib/akamairb/version.rb
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Akamai purge tool
100
+ test_files: []
101
+ has_rdoc: