verizon_api 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6a12b45d85e1f7cb59d08b8ef2dea1f71892930
4
+ data.tar.gz: 683973f5f8207195c067ebf5130a6a3972f0b0dd
5
+ SHA512:
6
+ metadata.gz: 6b03e4d94f4b79f759fb09d23b537837327487a72ee2ead215f01e0e59b2432c265a8e0692fbca34398ba323386d3ddc3add1d7f339a0ff5ac65032c158ea3dc
7
+ data.tar.gz: e391fec5a35afb037609a0ce6c12f46b059ff4cf646e7b36ff687816cc37bf63021fd9e283806c9bad5fdf48ec6ee4dea66c8a275e0b7401b634fc7f964a55f4
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.idea/*
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in verizon_api.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Justin Ellison
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # VerizonApi
2
+
3
+ This gem provides a ruby interface to Verizon's (Edgecast) API. In it's current state, it only provides methods that
4
+ interact with the WAF (Defend) platform, but will be extended to include more support later.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'verizon_api'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install verizon_api
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'verizon_api'
26
+
27
+ vzw = VerizonApi::Waf.new()
28
+ config = {}
29
+ config['instances'] = vzw.instances
30
+ config['profiles'] = vzw.profiles
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ 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).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/justintime/verizon_api.
42
+
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
47
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "verizon_api"
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
@@ -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,21 @@
1
+ require "verizon_api/version"
2
+ require 'httparty'
3
+ require 'verizon_api/api'
4
+
5
+ module VerizonApi
6
+ require 'verizon_api/config'
7
+
8
+ CONFIG_PATHS = ['./config/verizon.yml', '~/.verizon.yml', ]
9
+ CONFIG_PATHS.each do |file|
10
+ config = File.expand_path(file)
11
+ if File.exist?(config) then
12
+ VerizonApi::Config.load(config)
13
+ end
14
+ end
15
+ %w(api_token account_id).each do |required|
16
+ if !VerizonApi::Config[required] then
17
+ $stderr.puts "No '#{required}' key found in any of #{CONFIG_PATHS}"
18
+ exit(-1)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+
2
+ class VerizonApi::Api
3
+ include HTTParty
4
+ require 'yaml'
5
+ require 'json'
6
+
7
+ # Here, we bring in all our subordinate classes
8
+ require 'verizon_api/waf'
9
+
10
+ headers 'Host' => 'api.edgecast.com', 'Accept' => 'Application/JSON', 'Content-Type' => 'Application/JSON'
11
+ format :json
12
+
13
+ MEDIA_TYPES = {:flash_media_streaming => 2, :http_large_object => 3, :http_small_object => 8, :application_delivery_network => 14}
14
+
15
+
16
+ def initialize(account_id = VerizonApi::Config['account_id'], api_token = VerizonApi::Config['api_token'])
17
+ self.class.base_uri "https://api.edgecast.com/v2/mcc/customers/#{account_id}"
18
+ self.class.default_options[:headers]['Authorization'] = "TOK:#{api_token}"
19
+ end
20
+
21
+ end
@@ -0,0 +1,17 @@
1
+ class VerizonApi::CDN < VerizonApi
2
+
3
+ # def purge(media_type, path)
4
+ # object_url = File.join(@media_base_uri, path)
5
+ # self.class.put('/edge/purge', {:body => {'MediaType' => MEDIA_TYPES[media_type.to_sym], 'MediaPath' => object_url}.to_json})
6
+ # end
7
+ #
8
+ # def load(media_type, path)
9
+ # object_url = File.join(@media_base_uri, path)
10
+ # self.class.put('/edge/load', {:body => {'MediaType' => MEDIA_TYPES[media_type.to_sym], 'MediaPath' => object_url}.to_json})
11
+ # end
12
+ #
13
+ # def purge_status(id)
14
+ # self.class.get("/edge/purge/#{id}")
15
+ # end
16
+
17
+ end
@@ -0,0 +1,32 @@
1
+ class VerizonApi::Config
2
+ def self.load(source)
3
+ @config = {
4
+ :api_host => 'api.edgecast.com',
5
+ :api_token => nil,
6
+ }
7
+
8
+ if source.is_a?(String)
9
+ raise "Config file #{source} not found" unless File.exist?(source)
10
+
11
+ config = YAML.load_file(source)
12
+ @config.merge! config if config
13
+
14
+ elsif source.is_a?(Hash)
15
+ @config.merge! source
16
+ end
17
+ end
18
+
19
+ def self.include?(key)
20
+ @config.include?(key)
21
+ end
22
+
23
+ def self.[](key)
24
+ return nil unless @config
25
+ @config[key]
26
+ end
27
+
28
+ def self.to_yaml
29
+ return nil unless @config
30
+ @config.to_yaml
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module VerizonApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,84 @@
1
+ class VerizonApi::Waf < VerizonApi::Api
2
+
3
+ def _instance_details(id)
4
+ response = self.class.get("/waf/config/instances/#{id}")
5
+ fail("Unable to fetch instance id #{id}: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
6
+ parsed = JSON.parse(response.body)
7
+ end
8
+
9
+ def _profile_details(id)
10
+ response = self.class.get("/waf/config/profiles/#{id}")
11
+ fail("Unable to fetch profile id #{id}: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
12
+ parsed = JSON.parse(response.body)
13
+ end
14
+
15
+ def instances
16
+ unless @instances
17
+ response = self.class.get('/waf/config/instances')
18
+ fail("Unable to fetch instances: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
19
+ parsed = JSON.parse(response.body)
20
+ @instances = {}
21
+ parsed.each do |instance|
22
+ @instances[instance['name']] = _instance_details(instance['id'])
23
+ end
24
+ end
25
+ @instances
26
+ end
27
+
28
+ def profiles
29
+ unless @profiles
30
+ response = self.class.get('/waf/config/profiles')
31
+ fail("Unable to fetch profiles: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
32
+ parsed = JSON.parse(response.body)
33
+ @profiles = {}
34
+ parsed.each do |profile|
35
+ @profiles[profile['name']] = _profile_details(profile['id'])
36
+ end
37
+ end
38
+ @profiles
39
+ end
40
+
41
+ def add_instance(instance)
42
+ # This method creates a new instance. For documentation on what instance should contain, see
43
+ # https://my.edgecast.com/uploads/ubers/1/docs/en-US/webhelp/b/RESTAPIHelpCenter/default.htm#Media_Management/WAF/Add-Instance.htm
44
+ response = self.class.post("/waf/config/instances", body: instance.to_json)
45
+ fail("Unable to create a new instance: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
46
+ end
47
+
48
+ def delete_instance(instance)
49
+ # This method deletes an existing instance. For documentation on what instance should contain, see
50
+ # https://my.edgecast.com/uploads/ubers/1/docs/en-US/webhelp/b/RESTAPIHelpCenter/default.htm#Media_Management/WAF/Delete-Instance.htm
51
+ response = self.class.delete("/waf/config/instances/#{instance['id']}")
52
+ fail("Unable to delete instance id #{instance['id']}: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
53
+ end
54
+
55
+ def update_instance(instance)
56
+ # This method updates an existing instance. For documentation on what instance should contain, see
57
+ # https://my.edgecast.com/uploads/ubers/1/docs/en-US/webhelp/b/RESTAPIHelpCenter/default.htm#Media_Management/WAF/Update-Instance.htm
58
+ id = instance['id']
59
+ response = self.class.put("/waf/config/instances/#{id}", body: instance.to_json)
60
+ fail("Unable to update instance id #{id}: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
61
+ end
62
+
63
+ def add_profile(profile)
64
+ # This method creates a new profile. For documentation on what profile should contain, see
65
+ # https://my.edgecast.com/uploads/ubers/1/docs/en-US/webhelp/b/RESTAPIHelpCenter/default.htm#Media_Management/WAF/Add-Profile.htm
66
+ response = self.class.post("/waf/config/profiles", body: profile.to_json)
67
+ fail("Unable to create a new profile: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
68
+ end
69
+
70
+ def delete_profile(profile)
71
+ # This method deletes an existing profile. For documentation on what profile should contain, see
72
+ # https://my.edgecast.com/uploads/ubers/1/docs/en-US/webhelp/b/RESTAPIHelpCenter/default.htm#Media_Management/WAF/Delete-Profile.htm
73
+ response = self.class.delete("/waf/config/profiles/#{profile['id']}")
74
+ fail("Unable to delete profile id #{profile['id']}: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
75
+ end
76
+
77
+ def update_profile(profile)
78
+ # This method updates an existing profile. For documentation on what profile should contain, see
79
+ # https://my.edgecast.com/uploads/ubers/1/docs/en-US/webhelp/b/RESTAPIHelpCenter/default.htm#Media_Management/WAF/Update-Profile.htm
80
+ id = profile['id']
81
+ response = self.class.put("/waf/config/profiles/#{id}", body: profile.to_json)
82
+ fail("Unable to update profile id #{id}: 'HTTP Code #{response.code}: #{response.body}'") unless response.code == 200
83
+ end
84
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'verizon_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "verizon_api"
8
+ spec.version = VerizonApi::VERSION
9
+ spec.authors = ["Justin Ellison"]
10
+ spec.email = ["justin@techadvise.com"]
11
+
12
+ spec.summary = %q{Interact with Verizon's (EdgeCast) API.}
13
+ spec.description = %q{This gem allows you to view/modify your ADN and WAF configurations.}
14
+ spec.homepage = "http://github.com/justintime/verizon_api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "hashdiff"
25
+
26
+ spec.add_dependency "httparty"
27
+ spec.add_dependency "json"
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: verizon_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Ellison
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-15 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashdiff
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This gem allows you to view/modify your ADN and WAF configurations.
84
+ email:
85
+ - justin@techadvise.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - lib/verizon_api.rb
98
+ - lib/verizon_api/api.rb
99
+ - lib/verizon_api/cdn.rb
100
+ - lib/verizon_api/config.rb
101
+ - lib/verizon_api/version.rb
102
+ - lib/verizon_api/waf.rb
103
+ - verizon_api.gemspec
104
+ homepage: http://github.com/justintime/verizon_api
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Interact with Verizon's (EdgeCast) API.
128
+ test_files: []