cradlepoint 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b22d2f2d6acac43af74052aa2196bd1ddd32c19
4
- data.tar.gz: e94608b410b016ac61ea0ea5aeb0868d2c86f049
3
+ metadata.gz: fc0607e7966ce67469b3016b970518cb4f083fa1
4
+ data.tar.gz: 89d811424d1b64f56a4e93e542e5abed215199a6
5
5
  SHA512:
6
- metadata.gz: da2b87096d7035ac878390ae23601276141bc928b25e9dd51b18896fc3720105c0a357f481f8df56eb9de7c1535d52bfa4e78bac4eb6050aada77a0640a3659d
7
- data.tar.gz: 72f5bd64be30d269b9bcdb7ff448dff63b09257cc1310f134c01ef766c696a3b3ab01858e8708b95feaf3c5db503b265f83fa5c2d44cc0b0655035cd9df8cd82
6
+ metadata.gz: b8bd523c938895c2e7d2c4f29fc1cc517e2da04a48251f18d651597246d9851c4aea5b10dc672c1d1159275bf30f7a38c82386cb825a6b5897fce4c398face2a
7
+ data.tar.gz: ea2bdcdbf822b8dfd2a9448f122e5b6e301a6950dba010e7d12835280b47357e66f279525aed34084bd8fbbb99df846cdb9ff1c3d99302796ffeaf3401377907
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+
6
+ notifications:
7
+ email:
8
+ - john@uceem.com
9
+ - doug@uceem.com
@@ -3,7 +3,7 @@ require 'rest-client'
3
3
 
4
4
  require 'cradlepoint/version'
5
5
 
6
- require 'cradlepoint/hash_helpers'
6
+ require 'utils/hash_helpers'
7
7
 
8
8
  require 'cradlepoint/cradlepoint_object'
9
9
  require 'cradlepoint/account'
@@ -62,7 +62,7 @@ module Cradlepoint
62
62
  end
63
63
 
64
64
  parsed_response['success'] ?
65
- Cradlepoint::HashHelpers.symbolize_keys(parsed_response['data']) :
66
- raise("Unsuccessful response received.") # TODO: Handle more elegantly.
65
+ Utils::HashHelpers.symbolize_keys(parsed_response['data']) :
66
+ raise("Unsuccessful response received: #{ parsed_response.inspect }") # TODO: Handle more elegantly.
67
67
  end
68
68
  end
@@ -20,5 +20,25 @@ module Cradlepoint
20
20
  def params
21
21
  { params: { format: :json } }
22
22
  end
23
+
24
+ def self.successful_response?(response)
25
+ return false unless response
26
+ return false if response.is_a?(Hash) and !response[:success]
27
+ true
28
+ end
29
+
30
+ def successful_response?(response)
31
+ Cradlepoint::CradlepointObject.successful_response?(response)
32
+ end
33
+
34
+ def self.ecm_object_blob?(object_blob)
35
+ return false unless object_blob
36
+ return false unless object_blob.is_a?(Hash) and object_blob[:id]
37
+ true
38
+ end
39
+
40
+ def ecm_object_blob?(object_blob)
41
+ Cradlepoint::CradlepointObject.ecm_object_blob?(object_blob)
42
+ end
23
43
  end
24
44
  end
@@ -1,6 +1,5 @@
1
1
  module Cradlepoint
2
2
  class NetDevice < CradlepointObject
3
- include Cradlepoint::HashHelpers
4
3
 
5
4
  attr_accessor :id, :router, :data, :bytes_in, :bytes_out, :carrier, :esn, :imei, :info,
6
5
  :ip_address, :mac, :mode, :name, :type, :uptime, :netmask, :dns0, :dns1,
@@ -41,6 +40,10 @@ module Cradlepoint
41
40
  assign_attributes_from_data(group: true)
42
41
  end
43
42
 
43
+ def get_all_from_router_as_hash
44
+ Cradlepoint.make_request(:get, build_url(rel_url_from_router))
45
+ end
46
+
44
47
  def assign_attributes_from_data(options = {})
45
48
  return unless self.data and self.data.any?
46
49
  raw_data = self.data
@@ -64,6 +67,7 @@ module Cradlepoint
64
67
  def assign_attributes_from_blob(blob = {})
65
68
  return unless blob and blob.any?
66
69
 
70
+ self.data = blob
67
71
  self.connection_state = blob[:connection_state]
68
72
  self.bytes_in = blob[:bytes_in]
69
73
  self.bytes_out = blob[:bytes_out]
@@ -18,11 +18,13 @@ module Cradlepoint
18
18
 
19
19
  def get
20
20
  raise 'You must provide a mac' unless self.mac
21
+ return self.data if self.data
21
22
  self.data = Cradlepoint.make_request(:get, build_new_url(rel_url), params)
22
23
  end
23
24
 
24
25
  def get_status
25
26
  raise 'You must provide a mac' unless self.mac
27
+ return self.status_data if self.status_data
26
28
  self.status_data = Cradlepoint.make_request(:get, build_new_url("#{ rel_url }/status"), params)
27
29
  end
28
30
 
@@ -1,6 +1,5 @@
1
1
  module Cradlepoint
2
2
  class Router < CradlepointObject
3
- include Cradlepoint::HashHelpers
4
3
 
5
4
  attr_accessor :id, :data, :ecm_firmware_uri, :ecm_configuration_uri,
6
5
  :ecm_configuration_manager_uri, :ecm_configuration_manager_data,
@@ -62,7 +61,7 @@ module Cradlepoint
62
61
 
63
62
  def firmware_data
64
63
  check_for_id_or_raise_error
65
- Cradlepoint.make_request(:get, build_url(firmware_uri.split('/api/v1').last))
64
+ Cradlepoint.make_request(:get, build_url(firmware_uri.split('/api/v1').last)) if firmware_uri
66
65
  end
67
66
 
68
67
  def firmware_uri
@@ -112,12 +111,12 @@ module Cradlepoint
112
111
  private
113
112
 
114
113
  def self.build_array_of_routers_from_response(response)
115
- return unless response and response.any?
114
+ return false unless successful_response?(response)
116
115
  response.map { |r| create_and_assign_attributes_from_data(r) }
117
116
  end
118
117
 
119
118
  def self.create_and_assign_attributes_from_data(data)
120
- return unless data and data.any? and data[:id]
119
+ return unless ecm_object_blob?(data)
121
120
  router = Cradlepoint::Router.new(data[:id], data: data)
122
121
  router.assign_attributes_from_data
123
122
  router
@@ -1,3 +1,3 @@
1
1
  module Cradlepoint
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,4 +1,4 @@
1
- module Cradlepoint
1
+ module Utils
2
2
  module HashHelpers
3
3
  # From
4
4
  # http://devblog.avdi.org/2009/07/14/recursively-symbolize-keys/
@@ -19,5 +19,19 @@ describe Cradlepoint::CradlepointObject do
19
19
  it 'should return the correct url' do
20
20
  cradlepoint_object.build_url('/blah').should == url
21
21
  end
22
+
23
+ describe '.successful_response?' do
24
+
25
+ let(:successful_response) { [] }
26
+ let(:unsuccessful_responses) { [nil, { success: false }] }
27
+
28
+ it 'should think a successful response is successful' do
29
+ cradlepoint_object.successful_response?(successful_response).should be_true
30
+ end
31
+
32
+ it 'should think unsuccessful responses are unsuccessful' do
33
+ unsuccessful_responses.each { |r| cradlepoint_object.successful_response?(r).should be_false }
34
+ end
35
+ end
22
36
  end
23
37
  end
@@ -16,11 +16,25 @@ describe Cradlepoint::NetDevice do
16
16
 
17
17
  context 'when authenticated' do
18
18
 
19
+ let(:router) { Cradlepoint::Router.new(ROUTER_ID) }
20
+
19
21
  before { login }
20
22
 
23
+ describe '.get_all_from_router_as_hash' do
24
+
25
+ let(:response) { net_device.new(nil, router).get_all_from_router_as_hash }
26
+
27
+ subject { response }
28
+ it { should be }
29
+
30
+ it 'should return a an array of hashes' do
31
+ response.is_a?(Array).should be_true
32
+ response.each { |h| h.is_a?(Hash).should be_true }
33
+ end
34
+ end
35
+
21
36
  describe '.get_all_from_router' do
22
37
 
23
- let(:router) { Cradlepoint::Router.new(ROUTER_ID) }
24
38
  let(:device) { net_device.new(nil, router) }
25
39
  let(:devices) { device.get_all_from_router }
26
40
 
@@ -69,14 +69,10 @@ describe Cradlepoint::Router do
69
69
 
70
70
  let(:the_router) { router.new(ROUTER_ID) }
71
71
 
72
- it 'should have gotten the firmware data' do
73
- pending 'Waiting for updates to the firmware on the API side.'
74
- the_router.firmware_data['success'].should be_true
72
+ it 'should return nil when no firmware_uri exists' do
73
+ the_router.ecm_firmware_uri = nil
74
+ the_router.firmware_data.should be_nil
75
75
  end
76
76
  end
77
-
78
- describe '.apply_new_config' do
79
-
80
- end
81
77
  end
82
78
  end
@@ -32,4 +32,4 @@ def logout
32
32
  Cradlepoint.password = nil
33
33
  end
34
34
 
35
- include Cradlepoint::HashHelpers
35
+ include Utils::HashHelpers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cradlepoint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - uceem
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-20 00:00:00.000000000 Z
11
+ date: 2013-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - .gitignore
91
+ - .travis.yml
91
92
  - Gemfile
92
93
  - LICENSE.txt
93
94
  - README.md
@@ -97,12 +98,12 @@ files:
97
98
  - lib/cradlepoint/account.rb
98
99
  - lib/cradlepoint/config.rb
99
100
  - lib/cradlepoint/cradlepoint_object.rb
100
- - lib/cradlepoint/hash_helpers.rb
101
101
  - lib/cradlepoint/net_device.rb
102
102
  - lib/cradlepoint/net_flow.rb
103
103
  - lib/cradlepoint/router.rb
104
104
  - lib/cradlepoint/version.rb
105
105
  - lib/cradlepoint/wlan_survey.rb
106
+ - lib/utils/hash_helpers.rb
106
107
  - script/.gitkeep
107
108
  - spec/account_spec.rb
108
109
  - spec/config_spec.rb
@@ -132,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  version: '0'
133
134
  requirements: []
134
135
  rubyforge_project:
135
- rubygems_version: 2.0.5
136
+ rubygems_version: 2.0.7
136
137
  signing_key:
137
138
  specification_version: 4
138
139
  summary: Cradlepoint ECM API gem