cdnsun 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27cc907c768cc6253d8c3669fae28a8dd36542db
4
+ data.tar.gz: a36cbc5afb1c58d74d522346af8026d684861ac8
5
+ SHA512:
6
+ metadata.gz: 89d79d4eab735b59701a408c07eb8f759772a453333da5a44741743b80e67904c11b6b941db20f7532dc4bdd4e57018d93a3694cbd83132e4614222b3aecab2c
7
+ data.tar.gz: c09ad722318b2659dc4324806d442c539dd5d0b16717cee5e2c71b05b79fc3c7759d230ff75f934af6d55c820c21ec902e0ec9668a080ae137fbef9ae892d85f
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cdn_api_client.gemspec
6
+ gemspec
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cdn_api_client (0.6.0)
5
+ httparty (~> 0.16)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ httparty (0.16.2)
12
+ multi_xml (>= 0.5.2)
13
+ multi_xml (0.6.0)
14
+ rake (10.5.0)
15
+ rspec (3.7.0)
16
+ rspec-core (~> 3.7.0)
17
+ rspec-expectations (~> 3.7.0)
18
+ rspec-mocks (~> 3.7.0)
19
+ rspec-core (3.7.1)
20
+ rspec-support (~> 3.7.0)
21
+ rspec-expectations (3.7.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.7.0)
24
+ rspec-mocks (3.7.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.7.0)
27
+ rspec-support (3.7.1)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.16)
34
+ cdn_api_client!
35
+ rake (~> 10.0)
36
+ rspec (~> 3.0)
37
+
38
+ BUNDLED WITH
39
+ 1.16.3
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 CDNsun s.r.o., https://cdnsun.com, info@cdnsun.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Client for CDNsun CDN API
2
+
3
+ SYSTEM REQUIREMENTS
4
+
5
+ * Ruby >= 2.1
6
+ * httparty
7
+
8
+ GEM
9
+
10
+ https://rubygems.org/gems/cdn_api_client
11
+
12
+ CDN API DOCUMENTATION
13
+
14
+ https://cdnsun.com/knowledgebase/api
15
+
16
+ CLIENT USAGE
17
+
18
+ * Initialize the client
19
+ ```
20
+ require 'cdn_api_client'
21
+
22
+ client = CDNsunCdnApiClient.new(
23
+ username: 'YOUR_API_USERNAME',
24
+ password: 'YOUR_API_PASSWORD'
25
+ )
26
+ ```
27
+
28
+ * Get CDN service reports (https://cdnsun.com/knowledgebase/api/documentation/res/cdn/act/reports)
29
+ ```
30
+ client.get(url: 'cdns/ID/reports', data: { type: 'GB', period: '4h'})
31
+ ```
32
+ * Purge CDN service content (https://cdnsun.com/knowledgebase/api/documentation/res/cdn/act/purge)
33
+
34
+ ```
35
+ client.post(url: 'cdns/ID/purge', data: { purge_paths: [ '/path1.img', '/path2.img'] })
36
+ ```
37
+
38
+ NOTES
39
+
40
+ * The ID stands for a CDN service ID, it is an integer number, eg. 123, to find your CDN service ID please visit the Services/How-To (https://cdnsun.com/cdn/how-to) page in the CDNsun CDN dashboard.
41
+
42
+ CONTACT
43
+
44
+ * W: https://cdnsun.com
45
+ * E: info@cdnsun.com
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org/gems/cdn_api_client).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cdn_api_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cdn_api_client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cdnsun"
8
+ spec.version = CDNsunCdnApiClient::VERSION
9
+ spec.authors = ["CDNsun"]
10
+ spec.email = ["info@cdnsun.com"]
11
+
12
+ spec.summary = %q{Client for CDNsun CDN API}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "httparty", "~> 0.16"
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
@@ -0,0 +1,72 @@
1
+ require "httparty"
2
+ require "cdn_api_client/version"
3
+
4
+ class CDNsunCdnApiClient
5
+ class InvalidParameters < StandardError; end
6
+
7
+ include HTTParty
8
+
9
+ base_uri "https://cdnsun.com/api/"
10
+ format :json
11
+
12
+ REQUEST_TIMEOUT = 60
13
+
14
+ def initialize(username: , password: )
15
+ raise InvalidParameters unless [username, password].all? do |arg|
16
+ !arg.to_s.empty?
17
+ end
18
+
19
+ @username = username
20
+ @password = password
21
+ end
22
+
23
+ def get(options = {})
24
+ request(:get, options)
25
+ end
26
+
27
+ def put(options = {})
28
+ request(:put, options)
29
+ end
30
+
31
+ def post(options = {})
32
+ request(:post, options)
33
+ end
34
+
35
+ def delete(options = {})
36
+ request(:delete, options)
37
+ end
38
+
39
+ def request(verb, options)
40
+ options = Hash(options)
41
+
42
+ if ![:get, :post, :put, :delete].include?(verb) ||
43
+ options.empty? || "#{options[:url]}".empty?
44
+ raise InvalidParameters
45
+ end
46
+
47
+ query_key, query = if body_needed?(verb)
48
+ [:body, options[:data].to_json]
49
+ else
50
+ [:query, options[:data]]
51
+ end
52
+
53
+ resp = self.class.send(
54
+ verb,
55
+ format_url(options[:url]),
56
+ basic_auth: { username: @username, password: @password },
57
+ timeout: REQUEST_TIMEOUT,
58
+ query_key => query,
59
+ headers: { 'Content-Type' => 'application/json' }
60
+ )
61
+
62
+ resp.parsed_response
63
+ end
64
+
65
+ def body_needed?(verb)
66
+ verb == :post || verb == :put
67
+ end
68
+
69
+ def format_url(url)
70
+ "/#{url.sub(self.class.base_uri, '')}"
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ class CDNsunCdnApiClient
2
+ VERSION = "0.1.0"
3
+ end
data/test.rb ADDED
@@ -0,0 +1,19 @@
1
+ require_relative "lib/cdn_api_client"
2
+
3
+ username = 'YOUR_API_USERNAME';
4
+ password = 'YOUR_API_PASSWORD';
5
+ id = 'YOUR_CDN_SERVICE_ID';
6
+
7
+ client = CDNsunCdnApiClient.new(username: username, password: password)
8
+
9
+ response = client.get(url: "cdns")
10
+
11
+ p response
12
+
13
+ response = client.get(url: "cdns/#{id}/reports", data: { type: 'GB', period: '4h'})
14
+
15
+ p response
16
+
17
+ response = client.post(url: "cdns/#{id}/purge", data: { purge_paths: ['/path1.img', '/path2.img'] })
18
+
19
+ p response
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cdnsun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - CDNsun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-12 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.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - info@cdnsun.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - LICENSE.md
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - cdn_api_client.gemspec
84
+ - lib/cdn_api_client.rb
85
+ - lib/cdn_api_client/version.rb
86
+ - test.rb
87
+ homepage:
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.2.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Client for CDNsun CDN API
111
+ test_files: []