leaseweb-cdn-rest-api 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45042f6731d41436b95b9ab8f2fd3036ec2a6646
4
+ data.tar.gz: 86c2493fdb730aabb12bda5c19c14ecf08edb7f9
5
+ SHA512:
6
+ metadata.gz: 1bc09863a8b10593852b865adc4076061dc827a44c6f56cf2c2b10d3a7323182fd9e894c7f8430809dc64201d16aaeb936744ca9b791f054d37f20958251b958
7
+ data.tar.gz: 7fc222d0e615a00ac0ab471d05a68936ec130a2bae2bd24d419d43b1621069556d9132555fc37415b4fec8abea21b1727030a36a60166b95e662f3191573e313
@@ -0,0 +1,35 @@
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
+ test.rb
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
@@ -0,0 +1,13 @@
1
+ Copyright [2014] [Arnoud Vermeer]
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,64 @@
1
+ leaseweb-cdn-rest-api
2
+ =====================
3
+
4
+ Rubygem to talk to Leaseweb's CDN API
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'leaseweb-cdn-rest-api'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ ```
17
+ $ bundle
18
+ ```
19
+
20
+ Or install it yourself:
21
+
22
+ ```
23
+ $ gem install leaseweb-cdn-rest-api
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Start by creating a new instance of the `LeasewebCDN` class, and passing your api token and customer number.
29
+
30
+ ```ruby
31
+ api = LeasewebCDN.new(api_key, customer_number)
32
+ ```
33
+
34
+ All return values are the direct JSON responses from Leaseweb converted into a Hash.
35
+
36
+ See: [documentation](https://my.leasewebcdn.com/manuals/api/html/introduction.html)
37
+
38
+ Get all `pull|push|pushpull` zones:
39
+
40
+ ```ruby
41
+ zones = api.zone('all', 'pull')['success']
42
+ ```
43
+
44
+ Update a zone:
45
+
46
+ ```ruby
47
+ body = zones.first
48
+ body['alias'] = (1..10).collect { |n| "#{n}.cdn.example.com" }.join(',')
49
+ zone = api.update_zone(body['id'], body, 'pull')
50
+ ```
51
+
52
+ Create a zone:
53
+
54
+ ```ruby
55
+ body = { 'cname' => 'cdn.example.com', 'origin' => "http://origin.example.com", 'active' => 1 }
56
+ zone = api.update_zone('new', body, 'push')
57
+ ```
58
+
59
+ Delete a zone:
60
+
61
+ ```ruby
62
+ body = zones.first
63
+ zone = api.delete_zone(body['id'], 'pushpull')
64
+ ```
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'leaseweb-cdn-rest-api'
3
+ s.version = '1.0.1'
4
+ s.authors = 'Arnoud Vermeer'
5
+ s.email = 'arnoud@tumblr.com'
6
+ s.license = 'Apache'
7
+ s.summary = 'Leaseweb CDN API client for Ruby'
8
+ s.description = 'Leaseweb CDN REST API client for Ruby.'
9
+ s.homepage = 'https://github.com/funzoneq/leaseweb-cdn-rest-api'
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_dependency 'httparty'
14
+ end
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'digest/sha1'
4
+ require 'httparty'
5
+
6
+ class LeasewebCDN
7
+ include HTTParty
8
+ debug_output $stderr
9
+
10
+ base_uri 'https://api.leasewebcdn.com'
11
+
12
+ def initialize (key, customerNumber)
13
+ @key = key
14
+ @customerNumber = customerNumber.to_s
15
+ end
16
+
17
+ def create_url (path)
18
+ path = path.gsub("#customerNumber", @customerNumber)
19
+ timestamp = Time.now.utc.to_i
20
+ signature = Digest::SHA1.hexdigest("#{@key}#{timestamp}#{path}")
21
+
22
+ return "#{path}/#{timestamp}/#{signature}"
23
+ end
24
+
25
+ def zone (zoneID = 'all', type = 'pull')
26
+ self.class.get create_url("/zones/#{type}/#customerNumber/#{zoneID}")
27
+ end
28
+
29
+ def update_zone (zoneID, zone, type = 'pull')
30
+ self.class.post(create_url("/zones/#{type}/#customerNumber/#{zoneID}"), :body => zone )
31
+ end
32
+
33
+ def delete_zone (zoneID, type = 'pull')
34
+ self.class.delete create_url("/zones/#{type}/#customerNumber/#{zoneID}")
35
+ end
36
+
37
+ def stats_cname (type, granularity, timestamp_start, timestamp_end, cname = 'all')
38
+ self.class.get create_url("/stats/#{type}/#customerNumber/#{granularity}/#{timestamp_start}/#{timestamp_end}/#{cname}")
39
+ end
40
+
41
+ def stats_country_pop (type, granularity, timestamp_start, timestamp_end, cname, country, pop)
42
+ self.class.get create_url("/stats/#{type}/#customerNumber/#{granularity}/#{timestamp_start}/#{timestamp_end}/#{cname}/#{country}/#{pop}")
43
+ end
44
+
45
+ def stats_billing_region (type, granularity, timestamp_start, timestamp_end, cname, country, pop)
46
+ self.class.get create_url("/stats/#{type}/#customerNumber/#{granularity}/#{timestamp_start}/#{timestamp_end}/#{cname}/#{country}/#{pop}")
47
+ end
48
+
49
+ def stats_apicalls (year, month)
50
+ self.class.get create_url("/stats/api/#customerNumber/#{year}/#{month}")
51
+ end
52
+
53
+ def avg_traffic
54
+ self.class.get create_url("/stats/traffic/#customerNumber")
55
+ end
56
+
57
+ def nine_five_percentile (billing_region, timestamp_start, timestamp_end)
58
+ self.class.get create_url("/stats/95thpercentile/#customerNumber/#{billing_region}/#{timestamp_start}/#{timestamp_end}")
59
+ end
60
+
61
+ def nine_five_percentile_points (billing_region, timestamp_start, timestamp_end)
62
+ self.class.get create_url("/stats/95thpercentilepoints/#customerNumber/#{billing_region}/#{timestamp_start}/#{timestamp_end}")
63
+ end
64
+
65
+ def purge_status (zoneID, jobID)
66
+ self.class.get create_url("/content/purge/#customerNumber/#{zoneID}/#{jobID}")
67
+ end
68
+
69
+ def purge (zoneID, expression)
70
+ self.class.delete create_url("/content/purge/#customerNumber/#{zoneID}/#{expression}")
71
+ end
72
+
73
+ def search (query, zone_type = 'pull')
74
+ self.class.get create_url("/search/#{zone_type}/#customerNumber/#{query}")
75
+ end
76
+
77
+ def version
78
+ self.class.get create_url("/version")
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leaseweb-cdn-rest-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Arnoud Vermeer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Leaseweb CDN REST API client for Ruby.
28
+ email: arnoud@tumblr.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - LICENSE.txt
35
+ - README.md
36
+ - leaseweb-cdn-rest-api.gemspec
37
+ - lib/leaseweb-cdn-rest-api.rb
38
+ homepage: https://github.com/funzoneq/leaseweb-cdn-rest-api
39
+ licenses:
40
+ - Apache
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.2.2
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Leaseweb CDN API client for Ruby
62
+ test_files: []