cisco-mse-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTQ5Y2NhMTk5OGI2Yzg1MDNlMTBjNjc4OWMyZjQ4ODYxM2ZlN2MxNw==
5
+ data.tar.gz: !binary |-
6
+ ZTY5YTJjOTM4ZGFlYzc4MWUwZGFkYTMxY2JjOTNjODc1YmMwMDQzMg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YmY1MGMxYWU5ODk4YjQxOWZkNzYzNDRlZTYyNmVkNzA4NDZlZTRhN2RkYjBh
10
+ ODViNDJkODdmZjUzMzBhNzMxOWI5NWJkY2Y3M2Y0YzJmZjkxMDcxODQzY2Ew
11
+ NmNkZmQxMTNhNmIyYWFmMmNkYmMyN2NlYmIwYzJlYWIxMjQ2NjA=
12
+ data.tar.gz: !binary |-
13
+ MzcxYmZhNjIwN2QxNTc0ZWQxMzg5MWE4NTkxNjMwMGRlZDNjYmMxYjkyYzNh
14
+ YzBjZjQzNzUzOTU1NWFiZGY5NGQ2NjYyNTk2ZWYzMzhlZGYwNGQ5NjUwMzgz
15
+ MGY5MzkzNWViYzdkMTdiZjk5OTE4ZDQyOTZlOTk3ZDNmYzg3ZmI=
@@ -0,0 +1,18 @@
1
+ # Ignore the _creds.rb spec file
2
+ spec/_creds.rb
3
+
4
+ # Ignore tempfiles
5
+ *.sw[op]
6
+ .DS_Store
7
+
8
+ # RVM
9
+ .rvmrc
10
+ .ruby-gemset
11
+ .ruby-version
12
+
13
+ # Gems
14
+ *.gem
15
+
16
+ # IDEs
17
+ .idea
18
+ .project
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --backtrace
3
+ --require rspec/instafail
4
+ --format RSpec::Instafail
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :test do
5
+ gem 'rspec', '~> 2.14.1'
6
+ gem 'rspec-instafail', '~> 0.2'
7
+ end
8
+
9
+ group :development, :test do
10
+ gem 'pry'
11
+ end
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cisco-mse-client (0.0.1)
5
+ saddle (~> 0.0.49)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.0.2)
11
+ i18n (~> 0.6, >= 0.6.4)
12
+ minitest (~> 4.2)
13
+ multi_json (~> 1.3)
14
+ thread_safe (~> 0.1)
15
+ tzinfo (~> 0.3.37)
16
+ atomic (1.1.14)
17
+ coderay (1.0.9)
18
+ diff-lcs (1.2.4)
19
+ faraday (0.8.8)
20
+ multipart-post (~> 1.2.0)
21
+ faraday_middleware (0.9.0)
22
+ faraday (>= 0.7.4, < 0.9)
23
+ i18n (0.6.9)
24
+ method_source (0.8.2)
25
+ minitest (4.7.5)
26
+ multi_json (1.8.2)
27
+ multipart-post (1.2.0)
28
+ pry (0.9.12.2)
29
+ coderay (~> 1.0.5)
30
+ method_source (~> 0.8)
31
+ slop (~> 3.4)
32
+ rspec (2.14.1)
33
+ rspec-core (~> 2.14.0)
34
+ rspec-expectations (~> 2.14.0)
35
+ rspec-mocks (~> 2.14.0)
36
+ rspec-core (2.14.4)
37
+ rspec-expectations (2.14.1)
38
+ diff-lcs (>= 1.1.3, < 2.0)
39
+ rspec-instafail (0.2.4)
40
+ rspec-mocks (2.14.3)
41
+ saddle (0.0.49)
42
+ activesupport (>= 3.0)
43
+ faraday (~> 0.8.7)
44
+ faraday_middleware (~> 0.9.0)
45
+ slop (3.4.6)
46
+ thread_safe (0.1.3)
47
+ atomic
48
+ tzinfo (0.3.38)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ cisco-mse-client!
55
+ pry
56
+ rspec (~> 2.14.1)
57
+ rspec-instafail (~> 0.2)
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013, Mike Lewis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # Ruby Cisco MSE (Mobility Services Engine) client
2
+
3
+
4
+ ## Usage
5
+ ```ruby
6
+ client = CiscoMSE::Client.create(
7
+ username: 'YOUR_USERNAME',
8
+ password: 'YOUR_PASSWORD'
9
+ )
10
+
11
+ ```
12
+
13
+
14
+ ## Testing
15
+
16
+ ### from your project
17
+ In your spec_helper.rb, include the following snippet.
18
+ ```ruby
19
+ CiscoMSE::Client.stub!
20
+ ```
21
+ This will prevent `cisco-mse-client` from reaching out to live servers.
22
+ Instead, endpoints will return back [local stubbed data](lib/cisco-mse-client/stub.rb).
23
+
24
+ ### the cisco-mse-client gem
25
+ * Copy spec/_creds.stub.rb to spec/_creds.rb
26
+ * Update it to include a valid token
27
+ * bundle exec rspec
28
+
29
+
30
+ ## License
31
+ (c) Mike Lewis 2013
32
+ Released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/cisco-mse-client/version', __FILE__)
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'cisco-mse-client'
9
+ s.version = ::CiscoMSE::VERSION
10
+ s.authors = ['Mike Lewis']
11
+ s.email = ['mlewis.mail@gmail.com']
12
+ s.description = %q{Cisco MSE client}
13
+ s.summary = %q{
14
+ This is a Cisco MSE client implemented on Saddle
15
+ }
16
+ s.homepage = 'https://github.com/mLewisLogic/cisco-mse-client'
17
+ s.license = 'MIT'
18
+
19
+ s.require_path = 'lib'
20
+ s.files = `git ls-files`.split($\)
21
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
23
+
24
+ s.add_dependency 'saddle', '~> 0.0.49'
25
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'saddle'
4
+
5
+ require 'cisco-mse-client/exceptions'
6
+ require 'cisco-mse-client/middleware/authentication'
7
+ require 'cisco-mse-client/middleware/exception_raiser'
8
+ require 'cisco-mse-client/middleware/set_format'
9
+ require 'cisco-mse-client/stub'
10
+ require 'cisco-mse-client/version'
11
+
12
+
13
+
14
+ module CiscoMSE
15
+
16
+ class Client < Saddle::Client
17
+ extend CiscoMSE::Stub
18
+
19
+ def self.host
20
+ 'localhost'
21
+ end
22
+
23
+ def self.path_prefix
24
+ 'api/contextaware/v1'
25
+ end
26
+
27
+ def self.use_ssl
28
+ true
29
+ end
30
+
31
+
32
+ add_middleware({
33
+ klass: CiscoMSE::Middleware::ExceptionRaiser,
34
+ })
35
+
36
+ add_middleware({
37
+ klass: CiscoMSE::Middleware::Request::Authentication,
38
+ })
39
+
40
+ add_middleware({
41
+ klass: CiscoMSE::Middleware::Request::SetFormat,
42
+ })
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'saddle/endpoint'
4
+
5
+
6
+
7
+ module CiscoMSE
8
+ module Endpoints
9
+
10
+ class Location < Saddle::TraversalEndpoint
11
+
12
+ def clients(_id, opts = {})
13
+ begin
14
+ get("clients/#{_id}", opts)['WirelessClientLocation']
15
+ rescue CiscoMSE::NotFoundError => e
16
+ nil
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: UTF-8
2
+
3
+ ##
4
+ # Exceptions for using the Cisco MSE client
5
+ # It is recommended that you handle these.
6
+ ##
7
+
8
+ module CiscoMSE
9
+
10
+ class GenericException < StandardError; end
11
+
12
+ class TimeoutError < GenericException; end
13
+
14
+ # Some problems might take care of themselves if you try again later. Others won't.
15
+ class TemporaryError < GenericException; end # fire warnings on these
16
+ class PermanentError < GenericException; end # fire errors on these
17
+
18
+ # 404 (Not found)
19
+ class NotFoundError < GenericException; end
20
+
21
+ # 500 (Server error)
22
+ class ServiceError < GenericException; end
23
+
24
+ end
@@ -0,0 +1,28 @@
1
+ require 'base64'
2
+
3
+ require 'faraday'
4
+
5
+
6
+
7
+ module CiscoMSE
8
+ module Middleware
9
+ module Request
10
+
11
+ # Authenticate our request
12
+ class Authentication < Faraday::Middleware
13
+ def call(env)
14
+ if env[:request][:client_options][:username] && env[:request][:client_options][:password]
15
+ username = env[:request][:client_options][:username]
16
+ password = env[:request][:client_options][:password]
17
+ encoded_string = Base64.encode64("#{username}:#{password}")
18
+
19
+ env[:request_headers]['Authorization'] = "Basic #{encoded_string}"
20
+ end
21
+
22
+ @app.call(env)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'faraday'
4
+
5
+ require 'cisco-mse-client/exceptions'
6
+
7
+
8
+
9
+ module CiscoMSE
10
+ module Middleware
11
+
12
+ ## Raise beautiful exceptions
13
+ #
14
+ class ExceptionRaiser < Faraday::Middleware
15
+
16
+ ## For handling errors, the message that gets returned is of the following format:
17
+ # {:status => env[:status], :headers => env[:response_headers], :body => env[:body]}
18
+
19
+ def call(env)
20
+ begin
21
+ @app.call(env)
22
+ rescue Faraday::Error::ClientError => e
23
+ exception =
24
+ case e.response[:status]
25
+ when 404
26
+ CiscoMSE::NotFoundError
27
+ when 500
28
+ CiscoMSE::ServiceError
29
+ else
30
+ CiscoMSE::GenericException
31
+ end
32
+ raise exception, e.response
33
+ rescue Saddle::TimeoutError => e
34
+ raise CiscoMSE::TimeoutError, e.response
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ require 'faraday'
2
+
3
+
4
+
5
+ module CiscoMSE
6
+ module Middleware
7
+ module Request
8
+
9
+ # Let the service know that we expect/accept JSON
10
+
11
+ class SetFormat < Faraday::Middleware
12
+ def call(env)
13
+ env[:request_headers]['Accept'] = 'application/json'
14
+
15
+ @app.call(env)
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'cisco-mse-client/endpoints/location'
4
+
5
+ # This allows us to stub out live calls when testing from calling projects
6
+
7
+ module CiscoMSE
8
+ module Stub
9
+
10
+ # Setup stubbing for all endpoints
11
+ def stub!
12
+ CiscoMSE::Endpoints::Location.any_instance.stub(:clients).and_return( Stub::Data::Location::CLIENTS )
13
+ end
14
+
15
+ # Test data for stubs to return
16
+ module Data
17
+ module Location
18
+ CLIENTS = {
19
+ 'macAddress' => '00:00:00:00:00:00',
20
+ 'currentlyTracked' => true,
21
+ 'confidenceFactor' => 200.0,
22
+ 'band' => 'UNKNOWN',
23
+ 'isGuestUser' => false,
24
+ 'dot11Status' => 'PROBING',
25
+ 'MapInfo' => {
26
+ 'mapHierarchyString' => 'Campus>Building>1st Floor',
27
+ 'floorRefId' => 1234567890,
28
+ 'Dimension' => {
29
+ 'length' => 228.1,
30
+ 'width' => 319.4,
31
+ 'height' => 14.0,
32
+ 'offsetX' => 0.0,
33
+ 'offsetY' => 0.0,
34
+ 'unit' => 'FEET',
35
+ },
36
+ 'Image' => {
37
+ 'imageName' => 'domain_0_1381271699478.jpg',
38
+ },
39
+ },
40
+ 'MapCoordinate' =>{
41
+ 'x' => 106.71,
42
+ 'y' => 167.93,
43
+ 'unit' => 'FEET',
44
+ },
45
+ 'Statistics' => {
46
+ 'currentServerTime' => '2013-12-16T18:25:00.752-0500',
47
+ 'firstLocatedTime' => '2013-12-13T10:50:01.581-0500',
48
+ 'lastLocatedTime' => '2013-12-16T18:24:00.050-0500',
49
+ }
50
+ }
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+
3
+ module CiscoMSE
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+
3
+ TEST_HOSTNAME = 'localhost'
4
+ TEST_USERNAME = 'YOUR_USERNAME'
5
+ TEST_PASSWORD = 'YOUR_PASSWORD'
@@ -0,0 +1,38 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+ ###
7
+ # NOTE: This spec will actually hit CiscoMSE's servers
8
+ ###
9
+
10
+ describe 'CiscoMSE::Endpoints::Location' do
11
+ context "Test integration of location endpoints" do
12
+
13
+ # Skip if the creds aren't setup
14
+ if defined?(TEST_HOSTNAME) && defined?(TEST_USERNAME) && defined?(TEST_PASSWORD)
15
+
16
+ before :each do
17
+ @client = CiscoMSE::Client.create(
18
+ host: TEST_HOSTNAME,
19
+ username: TEST_USERNAME,
20
+ password: TEST_PASSWORD,
21
+ extra_env: {
22
+ ssl: {
23
+ verify: false,
24
+ },
25
+ }
26
+ )
27
+ end
28
+
29
+ it 'should get client data' do
30
+ @client.location.clients('test')
31
+ end
32
+
33
+ else
34
+ puts "You should put valid creds in _creds.rb"
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+ describe CiscoMSE::Middleware::ExceptionRaiser do
7
+
8
+ describe "Test raising various exceptions using stubs" do
9
+
10
+ before :each do
11
+ @stubs = Faraday::Adapter::Test::Stubs.new
12
+ @client = CiscoMSE::Client.create(stubs: @stubs)
13
+ end
14
+
15
+
16
+ it 'should detect a not found error' do
17
+ @stubs.get("#{CiscoMSE::Client.path_prefix}/") { [ 404, {}, {} ] }
18
+ expect { @client.requester.get('') }.to raise_error(CiscoMSE::NotFoundError)
19
+ end
20
+
21
+ it 'should detect a service error' do
22
+ @stubs.get("#{CiscoMSE::Client.path_prefix}/") { [ 500, {}, {} ] }
23
+ expect { @client.requester.get('') }.to raise_error(CiscoMSE::ServiceError)
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'cisco-mse-client'
4
+
5
+
6
+ # Load credentials from ENV if possible, or load from _creds.rb
7
+ if ENV['TEST_USERNAME'] && ENV['TEST_PASSWORD']
8
+ TEST_HOSTNAME = ENV['TEST_HOSTNAME']
9
+ TEST_USERNAME = ENV['TEST_USERNAME']
10
+ TEST_PASSWORD = ENV['TEST_PASSWORD']
11
+ else
12
+ begin
13
+ require '_creds'
14
+ rescue LoadError
15
+ puts "Using _creds.stub.rb, create a _creds.rb with actual credentials for a live test."
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+
6
+
7
+ describe CiscoMSE::Stub do
8
+ context 'can stub out calls' do
9
+
10
+ before :each do
11
+ CiscoMSE::Client.stub!
12
+ @client = CiscoMSE::Client.create
13
+ end
14
+
15
+ describe 'and return test data' do
16
+ it 'for location.clients' do
17
+ @client.location.clients('test').should == CiscoMSE::Stub::Data::Location::CLIENTS
18
+ end
19
+ end
20
+
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cisco-mse-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Lewis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: saddle
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.49
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.49
27
+ description: Cisco MSE client
28
+ email:
29
+ - mlewis.mail@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - .rspec
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE
39
+ - README.md
40
+ - cisco-mse-client.gemspec
41
+ - lib/cisco-mse-client.rb
42
+ - lib/cisco-mse-client/endpoints/location.rb
43
+ - lib/cisco-mse-client/exceptions.rb
44
+ - lib/cisco-mse-client/middleware/authentication.rb
45
+ - lib/cisco-mse-client/middleware/exception_raiser.rb
46
+ - lib/cisco-mse-client/middleware/set_format.rb
47
+ - lib/cisco-mse-client/stub.rb
48
+ - lib/cisco-mse-client/version.rb
49
+ - spec/_creds.stub.rb
50
+ - spec/integration/location_spec.rb
51
+ - spec/middleware/exception_raiser_spec.rb
52
+ - spec/spec_helper.rb
53
+ - spec/stub/stub_spec.rb
54
+ homepage: https://github.com/mLewisLogic/cisco-mse-client
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.1.11
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: This is a Cisco MSE client implemented on Saddle
78
+ test_files:
79
+ - spec/_creds.stub.rb
80
+ - spec/integration/location_spec.rb
81
+ - spec/middleware/exception_raiser_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/stub/stub_spec.rb