lockitron 0.0.3 → 1.0.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.
data/bin/lockitron DELETED
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'thor'
5
- require 'lockitron'
6
-
7
- class LockitronBin < Thor
8
-
9
- desc 'lock LOCK_NAME', 'locks one of the available locks by name'
10
- method_option :access_token, :aliases => '-a', :desc => "Set the access token from Lockitron's REST API"
11
- def lock(name)
12
- Lockitron::Locks.access_token = options[:access_token]
13
- Lockitron::Locks.lock(name)
14
- end
15
-
16
- desc 'unlock LOCK_NAME', 'unlocks one of the available locks by name'
17
- method_option :access_token, :aliases => '-a', :desc => "Set the access token from Lockitron's REST API"
18
- def unlock(name)
19
- Lockitron::Locks.access_token = options[:access_token]
20
- Lockitron::Locks.unlock(name)
21
- end
22
-
23
- desc 'list', "list all of the available locks"
24
- method_option :access_token, :aliases => '-a', :desc => "Set the access token from Lockitron's REST API"
25
- def list
26
- Lockitron::Locks.access_token = options[:access_token]
27
- Lockitron::Locks.list
28
- end
29
-
30
- end
31
-
32
- LockitronBin.start
@@ -1,26 +0,0 @@
1
- DOMAIN = "https://api.lockitron.com"
2
- LOCKS_URL = DOMAIN + "/v1/locks"
3
-
4
- module Lockitron
5
- module Authentication
6
-
7
- def access_token
8
- @@access_token ||= ENV["LOCKITRON_ACCESS_TOKEN"]
9
- invalid_access_token! if @@access_token == "" || @@access_token.nil?
10
- @@access_token
11
- end
12
-
13
- def access_token=(token)
14
- @@access_token = token
15
- end
16
-
17
- def invalid_access_token!
18
- puts "Invalid Access Token!"
19
- puts "I need a valid access token stored in the environment variable LOCKITRON_ACCESS_TOKEN. Head over to \"https://api.lockitron.com/v1/oauth/applications\" to get an access token."
20
- puts "Once you have an access token, run \"export LOCKITRON_ACCESS_TOKEN=ACCESS_TOKEN\", where ACCESS_TOKEN is your access token."
21
- puts "Store the access token as an environment variable in ~/.bashrc if you don't want to have to do this everytime"
22
- exit
23
- end
24
-
25
- end
26
- end
@@ -1,67 +0,0 @@
1
- module Lockitron
2
- class Locks
3
- extend Lockitron::Authentication
4
- DOMAIN = "https://api.lockitron.com"
5
- LOCKS_URL = DOMAIN + "/v1/locks"
6
- SETTINGS_PATH = './settings'
7
-
8
- def self.locks
9
- url = "#{LOCKS_URL}?access_token=#{access_token}"
10
- @@locks ||= RestClient.get url do |response, request, result|
11
- if response.code == 200
12
- JSON.parse(response.to_str)
13
- elsif response.code == 401
14
- invalid_access_token!
15
- self.locks
16
- else
17
- puts "Something went wrong, and I'm not sure what. Please send an email to jarred@lockitron.com and tell him what happened."
18
- end
19
- end
20
- end
21
-
22
- def self.lock_names
23
- @@names ||= locks.collect { |lock| lock['lock']['name'] }
24
- end
25
-
26
- def self.unlock_by_name(name)
27
- @@lock = find_lock_by_name(name)
28
- access_lock(@@lock, "unlock")
29
- end
30
-
31
- def self.lock_by_name(name)
32
- @@lock = find_lock_by_name(name)
33
- access_lock(@@lock, "lock")
34
- end
35
-
36
- def self.access_lock(lock, direction)
37
- url = "#{LOCKS_URL}/#{lock['id']}/#{direction}"
38
- RestClient.post url, :access_token => access_token do |response|
39
- if response.code == 200
40
- puts "Successfully #{direction.capitalize}ed #{lock['name'].capitalize}!"
41
- elsif response.code == 401
42
- invalid_access_token!
43
- access_lock(lock,direction)
44
- else
45
- puts "Something went wrong, and I'm not sure what. Please send an email to jarred@lockitron.com and tell him what happened."
46
- end
47
- end
48
- end
49
-
50
- def self.find_lock_by_name(name)
51
- @@lock = locks.select { |lock| lock['lock']['name'] == name }
52
- if @@lock.empty?
53
- puts "No available lock named #{name}\n\n"
54
- available_locks
55
- exit
56
- else
57
- return @@lock.first["lock"]
58
- end
59
- end
60
-
61
- def self.available_locks
62
- access_token # Ensures that an access token has been selected
63
- puts "Available locks:\n\n"
64
- locks.each { |lock| puts lock['lock']['name'] }
65
- end
66
- end
67
- end
@@ -1,66 +0,0 @@
1
- require 'rubygems'
2
- require 'rest-client'
3
- require 'json'
4
- require 'lockitron/authentication'
5
-
6
- module Lockitron
7
- class Locks
8
- extend Lockitron::Authentication
9
-
10
- def self.all
11
- url = "#{LOCKS_URL}?access_token=#{access_token}"
12
- @@locks ||= RestClient.get url do |response, request, result|
13
- if response.code == 200
14
- JSON.parse(response.to_str)
15
- elsif response.code == 401
16
- invalid_access_token!
17
- else
18
- puts "An unknown error occurred. Please send an email to jarred@lockitron.com and tell him what happened."
19
- end
20
- end
21
- end
22
-
23
- def self.names
24
- @@names ||= all.collect { |lock| lock['lock']['name'] }
25
- end
26
-
27
- def self.unlock(name)
28
- @@lock = find(name)
29
- access(@@lock, "unlock")
30
- end
31
-
32
- def self.lock(name)
33
- @@lock = find(name)
34
- access(@@lock, "lock")
35
- end
36
-
37
- def self.access(lock, direction)
38
- url = "#{LOCKS_URL}/#{lock['id']}/#{direction}"
39
- RestClient.post url, :access_token => access_token do |response|
40
- if response.code == 200
41
- puts "Successfully #{direction.capitalize}ed #{lock['name'].capitalize}!"
42
- elsif response.code == 401
43
- invalid_access_token!
44
- else
45
- puts "An unknown error ocurred. Please send an email to jarred@lockitron.com and tell him what happened."
46
- end
47
- end
48
- end
49
-
50
- def self.find(name)
51
- @@lock = all.select { |lock| lock['lock']['name'] == name }
52
- if @@lock.empty?
53
- puts "No available lock named #{name}\n\n"
54
- list
55
- else
56
- return @@lock.first["lock"]
57
- end
58
- end
59
-
60
- def self.list
61
- access_token # Ensures that an access token has been selected
62
- puts "Available locks:\n"
63
- all.each { |lock| puts lock['lock']['name'] }
64
- end
65
- end
66
- end