autoremote 0.0.5 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a342da83ca1bb192892e144c1c806745f60f1ec7
4
- data.tar.gz: 0cda4445d977ff6c01143e5b19c8258ce36efbf6
3
+ metadata.gz: 5a7b2d0b7620a21484db8c002d2a295eebd59bda
4
+ data.tar.gz: 2825fff65839f16ce93cd35134185e22ebdec542
5
5
  SHA512:
6
- metadata.gz: 069d130dcaaf0128597c61239e446c70ccda93d753f9b2fc03d1959773fe5375c54529ce3c4a438536a027c32bff741d43a8dbad808f8f9b7b6b8469c58c921c
7
- data.tar.gz: f8e8184c36845b564dfc2536d7e8df6f404e2be9fbf69a0e04ff1e90c2222342daae357a9b34ec57ef6a26fb7df8b7ee383ac91d0bb1146673d0fc83fecdccd0
6
+ metadata.gz: f522bfb3c914254549b6f2bfcb1697098b7ec8d5575e3c539fcc08d5b9c7f3bd24bd17c0ab71d09ff0ba5022575c4500f578235263f5ddad7156a962419a5e8c
7
+ data.tar.gz: 9e06942d9472ea015fc22007920cc3fdafccb14cdee8a6f2fc32dc5c8cb4c55082bc69ecf45184bd19f0ecf5c16ae1f75fbfcb3550e845de8fed3258499dcc03
data/README.md CHANGED
@@ -16,7 +16,8 @@ This project incudes both a library and an executable that uses the library.
16
16
 
17
17
  Devices are saved with sqlite3 in ~/.autoremote/devices.db
18
18
 
19
- If you don't know how to get your personal key [follow this link](http://joaoapps.com/autoremote/personal/)
19
+ If you don't know how to get your personal key [follow this link](http://joaoapps.com/autoremote/personal/)
20
+ Since version 0.1.0 you can use the goo.gl url instead of the key when adding devices.
20
21
 
21
22
  ## Installation
22
23
 
@@ -25,8 +26,9 @@ If you don't know how to get your personal key [follow this link](http://joaoapp
25
26
  ## Usage
26
27
 
27
28
  ### Executable
28
- $ autoremote add NAME KEY Save device
29
+ $ autoremote add NAME KEY|URL Save device
29
30
  $ autoremote remove NAME Removes device
31
+ $ autoremote delete NAME Same as above
30
32
  $ autoremote list [WITHKEY] Lists all devices. Displays keys if WITHKEY equals to true, t, yes, y, ja, j or 1
31
33
  $ autoremote message NAME MESSAGE Send a message to a device
32
34
  $ autoremote register NAME HOST Register this computer to the device
@@ -36,8 +38,10 @@ If you don't know how to get your personal key [follow this link](http://joaoapp
36
38
  ```ruby
37
39
  require 'autoremote'
38
40
 
39
- # This will save a device for use later
40
- AutoRemote.addDevice( name, key )
41
+ # Adding devices can be done either with the key
42
+ AutoRemote.addDevice( name, "A VERY LONG STRING OF CHARACTERS" )
43
+ # Or with your 'goo.gl' address
44
+ AutoRemote.addDevice( name, "http://goo.gl/XXXXXX" )
41
45
 
42
46
  # Removes a device
43
47
  AutoRemote.removeDevice( name )
@@ -6,8 +6,8 @@ require 'autoremote/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "autoremote"
8
8
  spec.version = AutoRemote::VERSION
9
- spec.authors = [ "AltonV" ]
10
- spec.email = [ "altonv@yurijware.com" ]
9
+ spec.authors = [ "Magnus Smedberg" ]
10
+ spec.email = [ "magnus.smedberg@yurijware.com" ]
11
11
  spec.summary = %q{A library for interacting with autoremote devices http://joaoapps.com/autoremote/}
12
12
  spec.homepage = "https://github.com/AltonV/autoremote"
13
13
  spec.license = "MIT"
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency 'activerecord', '~> 4.2', '~> 4.2'
24
24
  spec.add_runtime_dependency 'sqlite3', '~> 1.3', '~> 1.3'
25
+ spec.add_runtime_dependency 'httparty', '~> 0.13', '~> 0.13'
25
26
  end
@@ -12,8 +12,9 @@ end
12
12
  def print_help
13
13
  puts "AutoRemote v" + AutoRemote::VERSION
14
14
  puts "\nArguments:"
15
- puts " add DEVICE KEY Save device"
15
+ puts " add DEVICE KEY|URL Save device either with a 'goo.gl' url or personal key"
16
16
  puts " remove DEVICE Removes device"
17
+ puts " delete DEVICE Same as above"
17
18
  puts " list [WITHKEY] Lists all devices"
18
19
  puts " message DEVICE MESSAGE Send a message to a device"
19
20
  puts " register DEVICE HOST Register this computer to the device"
@@ -34,7 +35,7 @@ elsif arg0 == "add" && ARGV[1] && ARGV[2]
34
35
  puts "Error: #{e.message}"
35
36
  end
36
37
 
37
- elsif arg0 == "remove" && ARGV[1]
38
+ elsif ( arg0 == "remove" || arg0 == "delete" ) && ARGV[1]
38
39
  puts "Removing device"
39
40
  begin
40
41
  AutoRemote.removeDevice( ARGV[1] )
@@ -4,6 +4,7 @@ require 'sqlite3'
4
4
  require 'active_record'
5
5
  require 'net/http'
6
6
  require 'socket'
7
+ require 'httparty'
7
8
 
8
9
  ## Establish the database connection
9
10
  ActiveRecord::Base.establish_connection(
@@ -30,25 +31,41 @@ module AutoRemote
30
31
 
31
32
  # Add a device
32
33
  # @param name [String] The name of the device
33
- # @param key [String] The personal key of the device
34
+ # @param input [String] Can either be the 'goo.gl' url or the personal key of the device
34
35
  # @raise [AutoRemote::DeviceAlreadyExist] if the device already exits
36
+ # @raise [AutoRemote::InvalidKey] if the key or url is invalid
35
37
  # @return [void]
36
- def AutoRemote::addDevice( name, key )
37
- ## Check if the name is taken
38
- if Device.find_by_name( name ) || Device.find_by_key(key)
39
- raise self::DeviceAlreadyExist
40
- end
38
+ def AutoRemote::addDevice( name, input )
41
39
 
42
- ## Validate key
43
- result = self.urlRequest( VALIDATIONURL.sub( /%YOUR_KEY%/, key ) )
40
+ ## Validation if input is a 'goo.gl' url
41
+ if input.match( /^(https?:\/{2})?(goo.gl\/[\S]*)$/i )
42
+ result = self.urlRequest( input )
43
+
44
+ ## Get the key from the resulting url
45
+ begin
46
+ input = CGI.parse( result.request.last_uri.query )['key'][0]
47
+ rescue
48
+ raise self::InvalidKey
49
+ end
50
+
51
+ ## If not a 'goo.gl' url, check if it is a valid key
52
+ else
53
+ ## Validate key
54
+ result = self.urlRequest( VALIDATIONURL.sub( /%YOUR_KEY%/, input ) )
55
+
56
+ ## Check result
57
+ if result.body != "OK"
58
+ raise self::InvalidKey
59
+ end
60
+ end
44
61
 
45
- ## Check result
46
- if result.body != "OK"
47
- raise self::InvalidKey
62
+ ## Check if the device already exist
63
+ if Device.find_by_name( name ) || Device.find_by_key( input )
64
+ raise self::DeviceAlreadyExist
48
65
  end
49
66
 
50
67
  ## Save the device
51
- Device.create(:name => name, :key => key)
68
+ Device.create(:name => name, :key => input)
52
69
  end
53
70
 
54
71
  # Remove a specific device
@@ -145,10 +162,11 @@ module AutoRemote
145
162
  # Performs a http request
146
163
  # @param url [String]
147
164
  def AutoRemote::urlRequest( url )
148
- url = URI.parse( url )
149
- result = Net::HTTP.start(url.host, url.port) {|http|
150
- http.request( Net::HTTP::Get.new( url.to_s ) )
151
- }
152
- return result
165
+ ## Add http:// to the url if not present
166
+ if ! url.match( /^https?:\/{2}/i )
167
+ url = "http://" + url
168
+ end
169
+
170
+ return HTTParty.get( url )
153
171
  end
154
172
  end
@@ -1,3 +1,3 @@
1
1
  module AutoRemote
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  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.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - AltonV
7
+ - Magnus Smedberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-19 00:00:00.000000000 Z
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,9 +66,23 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
69
83
  description:
70
84
  email:
71
- - altonv@yurijware.com
85
+ - magnus.smedberg@yurijware.com
72
86
  executables:
73
87
  - autoremote
74
88
  extensions: []