autoremote 0.1.0 → 0.2.0

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: 5a7b2d0b7620a21484db8c002d2a295eebd59bda
4
- data.tar.gz: 2825fff65839f16ce93cd35134185e22ebdec542
3
+ metadata.gz: 556baa7cab3df31f1515bb062d933440923499b0
4
+ data.tar.gz: 8d2c4700f0ea3c49502f4928c38e8e5ad6494ed5
5
5
  SHA512:
6
- metadata.gz: f522bfb3c914254549b6f2bfcb1697098b7ec8d5575e3c539fcc08d5b9c7f3bd24bd17c0ab71d09ff0ba5022575c4500f578235263f5ddad7156a962419a5e8c
7
- data.tar.gz: 9e06942d9472ea015fc22007920cc3fdafccb14cdee8a6f2fc32dc5c8cb4c55082bc69ecf45184bd19f0ecf5c16ae1f75fbfcb3550e845de8fed3258499dcc03
6
+ metadata.gz: a621b850030b061cea9be09cd2f2a09106dc6f07029856276dbe0929ff86c99250104758e679c22ec45b62f8666861a981818ce9cfeeef417c28e948a6a96e1b
7
+ data.tar.gz: d42f3720da620411a193ca9c3aa385b3a436579548ca11d0ac5d7ce523f7081a13e2cd6008038938cf40ae2e0202c0094adda76fc30fd1cf2617871e0e7ba067
data/README.md CHANGED
@@ -4,12 +4,13 @@
4
4
  [![Dependency Status](http://img.shields.io/gemnasium/AltonV/autoremote.svg)][gemnasium]
5
5
  [![Gem Downloads](https://img.shields.io/gem/dt/autoremote.svg)][gem]
6
6
  [![Code Climate](https://codeclimate.com/github/AltonV/autoremote/badges/gpa.svg)][codeclimate]
7
+ [![Inline docs](http://inch-ci.org/github/AltonV/autoremote.svg?branch=master&style=shields)][inch-ci]
7
8
 
8
9
  [licence]: http://choosealicense.com/licenses/mit/
9
10
  [gem]: https://rubygems.org/gems/autoremote
10
11
  [gemnasium]: https://gemnasium.com/AltonV/autoremote
11
- [bitdeli]: https://bitdeli.com/free "Bitdeli Badge"
12
12
  [codeclimate]: https://codeclimate.com/github/AltonV/autoremote
13
+ [inch-ci]: http://inch-ci.org/github/AltonV/autoremote
13
14
 
14
15
  A library that makes it easier to interact with your other autoremote devices.
15
16
  This project incudes both a library and an executable that uses the library.
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
2
3
 
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = [ "Magnus Smedberg" ]
10
10
  spec.email = [ "magnus.smedberg@yurijware.com" ]
11
11
  spec.summary = %q{A library for interacting with autoremote devices http://joaoapps.com/autoremote/}
12
- spec.homepage = "https://github.com/AltonV/autoremote"
12
+ spec.homepage = "http://altonv.github.io/autoremote/"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.7"
21
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rake", "~> 10"
22
+ spec.add_development_dependency "rspec", "~> 3"
22
23
 
23
24
  spec.add_runtime_dependency 'activerecord', '~> 4.2', '~> 4.2'
24
25
  spec.add_runtime_dependency 'sqlite3', '~> 1.3', '~> 1.3'
@@ -2,7 +2,7 @@
2
2
  require 'autoremote'
3
3
  require 'rbconfig'
4
4
 
5
- def to_bool( string )
5
+ def to_bool(string)
6
6
  return false if string.class == NilClass || string.empty? || string.downcase =~ (/^(false|f|no|n|nej|0)$/i)
7
7
  return true if string.downcase =~ (/^(true|t|yes|y|ja|j|1)$/i)
8
8
  raise ArgumentError, "Invalid value: #{string}"
@@ -10,75 +10,69 @@ end
10
10
 
11
11
  ## Prints help
12
12
  def print_help
13
- puts "AutoRemote v" + AutoRemote::VERSION
13
+ puts 'AutoRemote v' + AutoRemote::VERSION
14
14
  puts "\nArguments:"
15
- puts " add DEVICE KEY|URL Save device either with a 'goo.gl' url or personal key"
16
- puts " remove DEVICE Removes device"
17
- puts " delete DEVICE Same as above"
18
- puts " list [WITHKEY] Lists all devices"
19
- puts " message DEVICE MESSAGE Send a message to a device"
20
- puts " register DEVICE HOST Register this computer to the device"
15
+ puts ' add DEVICE KEY|URL Save device either with a \'goo.gl\' url or personal key'
16
+ puts ' remove DEVICE Removes device'
17
+ puts ' delete DEVICE Same as above'
18
+ puts ' list [WITHKEY] Lists all devices'
19
+ puts ' message DEVICE MESSAGE Send a message to a device'
20
+ puts ' register DEVICE HOST Register this computer to the device'
21
21
  exit()
22
22
  end
23
23
 
24
24
  arg0 = ARGV[0].downcase if ARGV[0]
25
25
 
26
- if arg0 == "help" || arg0 == "-h" || arg0 == "--help"
26
+ if arg0 == 'help' || arg0 == '-h' || arg0 == '--help'
27
27
  print_help
28
-
29
- elsif arg0 == "add" && ARGV[1] && ARGV[2]
30
- puts "Adding device"
28
+ elsif arg0 == 'add' && ARGV[1] && ARGV[2]
29
+ puts 'Adding device'
31
30
  begin
32
- AutoRemote.addDevice( ARGV[1], ARGV[2] )
33
- puts "Device added successfully"
31
+ AutoRemote.addDevice(ARGV[1], ARGV[2])
32
+ puts 'Device added successfully'
34
33
  rescue Exception => e
35
34
  puts "Error: #{e.message}"
36
35
  end
37
-
38
- elsif ( arg0 == "remove" || arg0 == "delete" ) && ARGV[1]
39
- puts "Removing device"
36
+ elsif ( arg0 == 'remove' || arg0 == 'delete' ) && ARGV[1]
37
+ puts 'Removing device'
40
38
  begin
41
- AutoRemote.removeDevice( ARGV[1] )
42
- puts "Device removed successfully"
39
+ AutoRemote.removeDevice(ARGV[1])
40
+ puts 'Device removed successfully'
43
41
  rescue Exception => e
44
42
  puts "Error: #{e.message}"
45
43
  end
46
-
47
- elsif arg0 == "list"
44
+ elsif arg0 == 'list'
48
45
  withkey = to_bool(ARGV[1])
49
- puts "Listing devices"
46
+ puts 'Listing devices'
50
47
 
51
48
  AutoRemote.listDevices.each do|device|
52
49
  print "Name: #{device.name}"
53
50
  print " Key: #{device.key}" if withkey
54
51
  puts
55
52
  end
56
-
57
- elsif arg0 == "message" && ARGV[1] && ARGV[2]
53
+ elsif arg0 == 'message' && ARGV[1] && ARGV[2]
58
54
  begin
59
- AutoRemote::sendMessage( ARGV[1], ARGV[2] )
60
- puts "Message sent successfully"
55
+ AutoRemote.sendMessage(ARGV[1], ARGV[2])
56
+ puts 'Message sent successfully'
61
57
  rescue Exception => e
62
58
  puts "Error: #{e.message}"
63
59
  end
64
-
65
- elsif arg0 == "register" && ARGV[1] && ARGV[2]
60
+ elsif arg0 == 'register' && ARGV[1] && ARGV[2]
66
61
  if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/i
67
- puts "Are you sure you want to register a windows computer?"
68
- print "You will need an SSH server on the computer. (y/n)"
69
- if ! to_bool($stdin.gets.chomp)
70
- puts "Registering interrupted"
62
+ puts 'Are you sure you want to register a windows computer?'
63
+ print 'You will need an SSH server on the computer. (y/n)'
64
+ unless to_bool($stdin.gets.chomp)
65
+ puts 'Registering interrupted'
71
66
  exit
72
67
  end
73
68
  end
74
69
 
75
70
  begin
76
- AutoRemote::registerOnDevice( ARGV[1], ARGV[2] )
77
- puts "Device registered successfully"
71
+ AutoRemote.registerOnDevice(ARGV[1], ARGV[2])
72
+ puts 'Device registered successfully'
78
73
  rescue Exception => e
79
74
  puts "Error: #{e.message}"
80
75
  end
81
-
82
76
  else
83
77
  print_help
84
78
  end
@@ -1,5 +1,5 @@
1
- require "autoremote/version"
2
- require "autoremote/exceptions"
1
+ require 'autoremote/version'
2
+ require 'autoremote/exceptions'
3
3
  require 'sqlite3'
4
4
  require 'active_record'
5
5
  require 'net/http'
@@ -25,9 +25,9 @@ ActiveRecord::Schema.define do
25
25
  end
26
26
 
27
27
  module AutoRemote
28
- REGURL = "http://autoremotejoaomgcd.appspot.com/registerpc?key=%YOUR_KEY%&name=%DISPLAY_NAME%&id=%UNIQUE_ID%&type=linux&publicip=%PUBLIC_HOST%&localip=%IP_ADDRESS%"
29
- MSGURL = "http://autoremotejoaomgcd.appspot.com/sendmessage?key=%YOUR_KEY%&message=%MESSAGE%&sender=%SENDER_ID%"
30
- VALIDATIONURL = "http://autoremotejoaomgcd.appspot.com/sendmessage?key=%YOUR_KEY%"
28
+ REGURL = 'http://autoremotejoaomgcd.appspot.com/registerpc?key=%YOUR_KEY%&name=%DISPLAY_NAME%&id=%UNIQUE_ID%&type=linux&publicip=%PUBLIC_HOST%&localip=%IP_ADDRESS%'
29
+ MSGURL = 'http://autoremotejoaomgcd.appspot.com/sendmessage?key=%YOUR_KEY%&message=%MESSAGE%&sender=%SENDER_ID%'
30
+ VALIDATIONURL = 'http://autoremotejoaomgcd.appspot.com/sendmessage?key=%YOUR_KEY%'
31
31
 
32
32
  # Add a device
33
33
  # @param name [String] The name of the device
@@ -35,15 +35,15 @@ module AutoRemote
35
35
  # @raise [AutoRemote::DeviceAlreadyExist] if the device already exits
36
36
  # @raise [AutoRemote::InvalidKey] if the key or url is invalid
37
37
  # @return [void]
38
- def AutoRemote::addDevice( name, input )
38
+ def AutoRemote::addDevice(name, input)
39
39
 
40
40
  ## Validation if input is a 'goo.gl' url
41
- if input.match( /^(https?:\/{2})?(goo.gl\/[\S]*)$/i )
42
- result = self.urlRequest( input )
41
+ if input.match(/^(https?:\/{2})?(goo.gl\/[\S]*)$/i)
42
+ result = self.urlRequest(input)
43
43
 
44
44
  ## Get the key from the resulting url
45
45
  begin
46
- input = CGI.parse( result.request.last_uri.query )['key'][0]
46
+ input = CGI.parse(result.request.last_uri.query)['key'][0]
47
47
  rescue
48
48
  raise self::InvalidKey
49
49
  end
@@ -51,16 +51,16 @@ module AutoRemote
51
51
  ## If not a 'goo.gl' url, check if it is a valid key
52
52
  else
53
53
  ## Validate key
54
- result = self.urlRequest( VALIDATIONURL.sub( /%YOUR_KEY%/, input ) )
54
+ result = self.urlRequest(VALIDATIONURL.sub(/%YOUR_KEY%/, input))
55
55
 
56
56
  ## Check result
57
- if result.body != "OK"
57
+ if result.body != 'OK'
58
58
  raise self::InvalidKey
59
59
  end
60
60
  end
61
61
 
62
62
  ## Check if the device already exist
63
- if Device.find_by_name( name ) || Device.find_by_key( input )
63
+ if Device.find_by_name(name) || Device.find_by_key(input)
64
64
  raise self::DeviceAlreadyExist
65
65
  end
66
66
 
@@ -72,9 +72,8 @@ module AutoRemote
72
72
  # @param name [String] The name of the device
73
73
  # @raise [AutoRemote::DeviceNotFound] if the device didn't exist
74
74
  # @return [void]
75
- def AutoRemote::removeDevice( name )
75
+ def AutoRemote::removeDevice(name)
76
76
  if device = Device.find_by_name(name)
77
-
78
77
  ## Remove the device
79
78
  Device.delete(device.id)
80
79
  else
@@ -85,13 +84,13 @@ module AutoRemote
85
84
  # Returns a list with all devices
86
85
  # @return [Device::ActiveRecord_Relation]
87
86
  def AutoRemote::listDevices
88
- return Device.order("name").all
87
+ return Device.order('name').all
89
88
  end
90
89
 
91
90
  # Returns one specific device
92
91
  # @return [Device]
93
- def AutoRemote::getDevice( name )
94
- return Device.find_by_name( name )
92
+ def AutoRemote::getDevice(name)
93
+ return Device.find_by_name(name)
95
94
  end
96
95
 
97
96
  # Sends a message to a device
@@ -100,20 +99,20 @@ module AutoRemote
100
99
  # @raise [AutoRemote::DeviceNotFound] if the device didn't exits
101
100
  # @raise [TypeError] if message isn't a string
102
101
  # @return [void]
103
- def AutoRemote::sendMessage( device, message )
104
- if ! device.kind_of?( Device ) && ! ( device = Device.find_by_name( device ) )
102
+ def AutoRemote::sendMessage(device, message)
103
+ if ! device.kind_of?(Device) && ! (device = Device.find_by_name(device))
105
104
  raise self::DeviceNotFound
106
- elsif ! message.kind_of?( String )
107
- raise TypeError, "Message must be a string"
105
+ elsif ! message.kind_of?(String)
106
+ raise TypeError, 'Message must be a string'
108
107
  end
109
108
 
110
109
  hostname = `hostname`.strip
111
110
 
112
111
  ## Send the message
113
- result = self.urlRequest( MSGURL.sub( /%YOUR_KEY%/, device.key ).sub( /%MESSAGE%/, message ).sub( /%SENDER_ID%/, hostname ) )
112
+ result = self.urlRequest(MSGURL.sub(/%YOUR_KEY%/, device.key).sub(/%MESSAGE%/, CGI.escape(message)).sub(/%SENDER_ID%/, hostname))
114
113
 
115
114
  ## Check result
116
- if result.body != "OK"
115
+ if result.body != 'OK'
117
116
  raise self::InvalidKey
118
117
  end
119
118
  end
@@ -125,22 +124,22 @@ module AutoRemote
125
124
  # @raise [AutoRemote::UnsupportedAction] if running from windows
126
125
  # @raise [TypeError] if message isn't a string or less than 5 characters
127
126
  # @return [void]
128
- def AutoRemote::registerOnDevice( device, remotehost )
129
- if ! device.kind_of?( Device ) && ! ( device = Device.find_by_name( device ) )
127
+ def AutoRemote::registerOnDevice(device, remotehost)
128
+ if ! device.kind_of?(Device) && ! (device = Device.find_by_name(device))
130
129
  raise self::DeviceNotFound
131
- elsif ! remotehost.kind_of?( String ) || remotehost.length < 5
132
- raise ArgumentError, "remotehost must be a string of 5 chars or more"
130
+ elsif ! remotehost.kind_of?(String) || remotehost.length < 5
131
+ raise ArgumentError, 'remotehost must be a string of 5 chars or more'
133
132
  end
134
133
 
135
134
  hostname = `hostname`.strip
136
135
  ipAddress = AutoRemote::getIpAddress.ip_address
137
136
 
138
137
  ## Perform the registration
139
- result = self.urlRequest( REGURL.sub( /%YOUR_KEY%/, device.key ).sub(/%DISPLAY_NAME%/, hostname ).sub(/%UNIQUE_ID%/, hostname ).sub(/%PUBLIC_HOST%/, remotehost ).sub(/%IP_ADDRESS%/, ipAddress ) )
138
+ result = self.urlRequest(REGURL.sub(/%YOUR_KEY%/, device.key).sub(/%DISPLAY_NAME%/, hostname).sub(/%UNIQUE_ID%/, hostname).sub(/%PUBLIC_HOST%/, remotehost).sub(/%IP_ADDRESS%/, ipAddress))
140
139
 
141
140
  ## Check result
142
- if result.body != "OK"
143
- raise self::AutoRemoteException, "Something went wrong when registering on the device"
141
+ if result.body != 'OK'
142
+ raise self::AutoRemoteException, 'Something went wrong when registering on the device'
144
143
  end
145
144
  end
146
145
 
@@ -156,17 +155,15 @@ module AutoRemote
156
155
  # Gets the ip address of the system
157
156
  # @return [String]
158
157
  def AutoRemote::getIpAddress
159
- return Socket.ip_address_list.detect{|ipInfo| ipInfo.ipv4_private?}
158
+ return Socket.ip_address_list.detect { |ipInfo| ipInfo.ipv4_private? }
160
159
  end
161
160
 
162
161
  # Performs a http request
163
162
  # @param url [String]
164
- def AutoRemote::urlRequest( url )
163
+ def AutoRemote::urlRequest(url)
165
164
  ## Add http:// to the url if not present
166
- if ! url.match( /^https?:\/{2}/i )
167
- url = "http://" + url
168
- end
165
+ url = 'http://' + url unless url.match(/^https?:\/{2}/i)
169
166
 
170
- return HTTParty.get( url )
167
+ return HTTParty.get(url)
171
168
  end
172
169
  end
@@ -1,23 +1,23 @@
1
- module AutoRemote
2
- class AutoRemoteException < StandardError
3
- end
4
-
5
- class DeviceNotFound < AutoRemoteException
6
- def message
7
- "Device doesn't exist"
8
- end
9
- end
10
-
11
- class DeviceAlreadyExist < AutoRemoteException
12
- def message
13
- "Device already exist"
14
- end
15
- end
16
-
17
- class InvalidKey < AutoRemoteException
18
- def message
19
- "The key is invalid"
20
- end
21
- end
22
-
23
- end
1
+ module AutoRemote
2
+ class AutoRemoteException < StandardError
3
+ end
4
+
5
+ class DeviceNotFound < AutoRemoteException
6
+ def message
7
+ "Device doesn't exist"
8
+ end
9
+ end
10
+
11
+ class DeviceAlreadyExist < AutoRemoteException
12
+ def message
13
+ "Device already exist"
14
+ end
15
+ end
16
+
17
+ class InvalidKey < AutoRemoteException
18
+ def message
19
+ "The key is invalid"
20
+ end
21
+ end
22
+
23
+ end
@@ -1,3 +1,3 @@
1
1
  module AutoRemote
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper.rb'
2
+ require 'autoremote'
3
+
4
+ TEST_NAME = 'TestDevice'
5
+ TEST_URL = 'http://goo.gl/CyA66h'
6
+ TEST_KEY = 'APA91bFKEjtBfVU5WoJJ8KyfmR3LfmUpcVrePdQQ_T5oN1h8KcLptzhCvDE-FP1IQPimb9bk4Osm2FzTUvUT5YRylgjTMTHbS7HqbveHE-ZhgwtJEsfoKvo_JAN8Oh5NLpk-mvWEMBaZtpZVXqb3oP-G_7iKmY4UrNhXhrx9CNKOEWjhuluM0Js'
7
+ TEST_MSG = 'This is a test message'
8
+
9
+ describe AutoRemote do
10
+ describe '#addDevice' do
11
+ it 'adds a device' do
12
+ AutoRemote.addDevice(TEST_NAME, TEST_URL)
13
+ end
14
+ end
15
+
16
+ describe '#listDevices' do
17
+ it 'returns a list of devices' do
18
+ list = AutoRemote.listDevices
19
+ expect(list).not_to eq(nil)
20
+ expect(list.count).to be > 0
21
+ end
22
+ end
23
+
24
+ describe '#getDevice' do
25
+ it 'returns a device' do
26
+ device = AutoRemote.getDevice(TEST_NAME)
27
+ expect(device).to be_instance_of(Device)
28
+ expect(device.name).to eq(TEST_NAME)
29
+ expect(device.key).to eq(TEST_KEY)
30
+ end
31
+ end
32
+
33
+ describe 'sends a message' do
34
+ it do
35
+ AutoRemote.sendMessage(TEST_NAME, TEST_MSG)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |c|
3
+ c.syntax = :expect
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoremote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus Smedberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: activerecord
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +112,9 @@ files:
98
112
  - lib/autoremote.rb
99
113
  - lib/autoremote/exceptions.rb
100
114
  - lib/autoremote/version.rb
101
- homepage: https://github.com/AltonV/autoremote
115
+ - spec/autoremote_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: http://altonv.github.io/autoremote/
102
118
  licenses:
103
119
  - MIT
104
120
  metadata: {}
@@ -122,5 +138,7 @@ rubygems_version: 2.4.5
122
138
  signing_key:
123
139
  specification_version: 4
124
140
  summary: A library for interacting with autoremote devices http://joaoapps.com/autoremote/
125
- test_files: []
141
+ test_files:
142
+ - spec/autoremote_spec.rb
143
+ - spec/spec_helper.rb
126
144
  has_rdoc: