spanx-client 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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/lib/spanx/client.rb +45 -0
- data/lib/spanx/client/version.rb +5 -0
- data/spanx-client.gemspec +25 -0
- data/spec/spanx/client_spec.rb +38 -0
- data/spec/spec_helper.rb +19 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 96b1033484f4caf48443c6a5822e45aa2c33194e
|
4
|
+
data.tar.gz: d3f7d05d0ea9e0307bc28ce87d4daad6c577ac00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1b395afff3dc07d756e900f6515446fccab554ba1aea7161113e0cdb341b3c1fe28518f20c607de8a252d423c07525c088d56371d0a436b4ffb81e6844476af8
|
7
|
+
data.tar.gz: 538090ea0fc53f002ef81d83ce6246afb35b3dc5905193b23f42f876f098b93ca0cc100e5690322570b19e46fdbc11e17bb2221c3772c9ca5dc72e4595988efe
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Paul Henry
|
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,57 @@
|
|
1
|
+
# Spanx::Client
|
2
|
+
|
3
|
+
This gem connects to the API of spanx and allows for:
|
4
|
+
|
5
|
+
* Listing of blocked IPs
|
6
|
+
* Unblocking of a specific IP
|
7
|
+
* Unblocking all ips (TODO)
|
8
|
+
* Disabling Spanx (TODO)
|
9
|
+
* Enabling Spanx (TODO)
|
10
|
+
* Blocking a specific IP (TODO)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'spanx-client'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install spanx-client
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Configuration
|
29
|
+
|
30
|
+
To configure where the spanx api server lives:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
Spanx::Client.configure do |c|
|
34
|
+
c.url = "http://some-server-in-outer-space.com"
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
### Listing all blocked ips
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Spanx::Client.blocked_ips
|
42
|
+
# => ["127.0.0.1", "192.168.1.1"]
|
43
|
+
```
|
44
|
+
|
45
|
+
### Unblocking a specific IP
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
Spanx::Client.unblock("192.168.1.1")
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it ( https://github.com/[my-github-username]/spanx-api-client/fork )
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/spanx/client.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spanx/client/version'
|
2
|
+
require "uri"
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Spanx
|
7
|
+
class Client
|
8
|
+
def self.url=(url)
|
9
|
+
@url = url
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.url
|
13
|
+
@url || "http://localhost:6060"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.blocked_ips
|
21
|
+
response = request "/ips/blocked" do |uri|
|
22
|
+
Net::HTTP::Get.new(uri.request_uri)
|
23
|
+
end
|
24
|
+
|
25
|
+
JSON.parse(response.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.unblock(ip)
|
29
|
+
request "/ips/blocked/#{ip}" do |uri|
|
30
|
+
Net::HTTP::Delete.new(uri.request_uri)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def self.request(path)
|
37
|
+
uri = URI.parse(url + path)
|
38
|
+
|
39
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
40
|
+
request = yield uri
|
41
|
+
|
42
|
+
http.request(request)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spanx/client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "spanx-client"
|
8
|
+
spec.version = Spanx::Client::VERSION
|
9
|
+
spec.authors = ["Paul Henry"]
|
10
|
+
spec.email = ["paul@wanelo.com"]
|
11
|
+
spec.summary = %q{Client for connecting to Spanx's API}
|
12
|
+
spec.description = %q{API Client for connecting to spanx.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "webmock"
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spanx/client'
|
3
|
+
|
4
|
+
describe Spanx::Client do
|
5
|
+
describe '#configure' do
|
6
|
+
it 'allows configuration of the url' do
|
7
|
+
expect(Spanx::Client.url).to eq("http://localhost:6060")
|
8
|
+
|
9
|
+
Spanx::Client.configure do |c|
|
10
|
+
c.url = "http://localhost:2302"
|
11
|
+
end
|
12
|
+
|
13
|
+
expect(Spanx::Client.url).to eq("http://localhost:2302")
|
14
|
+
|
15
|
+
Spanx::Client.url = nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.blocked_ips' do
|
20
|
+
it 'returns an array of blocked ips from spanx' do
|
21
|
+
stub_request(:get, "http://localhost:6060/ips/blocked").
|
22
|
+
to_return(:status => 200, :body => '["127.0.0.1","192.168.1.1"]', :headers => {})
|
23
|
+
|
24
|
+
expect(Spanx::Client.blocked_ips).to eq(["127.0.0.1", "192.168.1.1"])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.unblock' do
|
29
|
+
it 'makes a request to unblock the ip' do
|
30
|
+
request = stub_request(:delete, "http://localhost:6060/ips/blocked/192.168.1.1").
|
31
|
+
to_return(:status => 204, :body => '', :headers => {})
|
32
|
+
|
33
|
+
Spanx::Client.unblock('192.168.1.1')
|
34
|
+
|
35
|
+
request.should have_been_requested
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
6
|
+
# loaded once.
|
7
|
+
#
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spanx-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Henry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-24 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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: rspec
|
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: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: API Client for connecting to spanx.
|
70
|
+
email:
|
71
|
+
- paul@wanelo.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/spanx/client.rb
|
83
|
+
- lib/spanx/client/version.rb
|
84
|
+
- spanx-client.gemspec
|
85
|
+
- spec/spanx/client_spec.rb
|
86
|
+
- spec/spec_helper.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.2.0
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Client for connecting to Spanx's API
|
111
|
+
test_files:
|
112
|
+
- spec/spanx/client_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
has_rdoc:
|