lono-api 0.1.3 → 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: 03a9d1cad80af84c136783dc0bbf146527ab10ea
4
- data.tar.gz: 2231608cb3d981ae837e174a8fc7490bcdecc96c
3
+ metadata.gz: e4d9685478f7b2c25c2abc57c506ccf2d39909ed
4
+ data.tar.gz: 48d9e10cc70f50098453f7901d8e9405b967ebb0
5
5
  SHA512:
6
- metadata.gz: 16a698d000985b09fc82e150f5bf608a37fdbb9182e9e311407966ee453eb92fae3e6c2c024a21eae619012bd09e36fb32a8a6c6a35914c96a379db495136607
7
- data.tar.gz: 5ca3d05687b0633d392b0240d36ad52038d42a8ad8f62dc9054319710010499dcffb749e97b32ec91b8949bf44f0fb537968c802a9fe3fc481f0ffb62481d2dd
6
+ metadata.gz: d25c6535b4793a6741303306b451c78a9149269cef23006ebe7775d94a8c0795dce40b5cc1c613e82d5f275213d93950ae3757c98b7e0b77ed73c08fad961443
7
+ data.tar.gz: 8d2277aa0b921786d53688cc7883da926d1dd0c6ce02105086bb8c292305cbc59dc0957922cac00398bee7f959a76e6c8bde8e967d98135f3503d1d121512b67
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lono-api (0.1.3)
4
+ lono-api (0.2.0)
5
5
  unirest (~> 1.1.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -29,7 +29,7 @@ Or install it yourself as:
29
29
  Lono.configure do |config|
30
30
  config.client_secret = 'secret'
31
31
  config.client_id = 'id'
32
- config.access_token = 'access_token'
32
+ config.auth_token = 'auth_token'
33
33
  config.scope = ['write']
34
34
  end
35
35
  ```
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lono-api"
5
+
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ # IRB.start
16
+
17
+ Lono.configure do |config|
18
+ config.client_id = '256a8990-1c86-4d3a-9037-4e1495da510e'
19
+ config.client_secret = '21e75918-9961-42c3-aea5-f4aecea115b3'
20
+ config.auth_token = 'e9bed6e8-e6dd-46e3-95d4-5a93c5930718'
21
+ config.scope = ['write']
22
+ end
23
+ puts Lono::AuthUrl.fetch "http://lono.io"
24
+
25
+ token = Lono::SessionToken.fetch
26
+ device = Lono::Device.new "34ffda053257333933870457", token
27
+ # device.set_zone(0, true)
28
+ # sleep 5
29
+ # device.set_zone(0, false)
30
+
31
+
32
+ # device.set_led("#FF0000", 255)
33
+ device.set_led_options({
34
+ color: "#FF0000",
35
+ mode: "color"
36
+ })
37
+
@@ -17,6 +17,21 @@ module Lono
17
17
  }
18
18
  end
19
19
 
20
+ # get_zone(cb)
21
+ #
22
+ # Get the current zone that is enabled on Lono (No zone on will be None).
23
+ #
24
+ # > lc = LonoClient(client_id="...", ...) # etc...
25
+ # ** connect to lono cloud **
26
+ # > lc.get_device("device id").get_zone(function() {})
27
+ def get_zone
28
+ query_device @id, {
29
+ :url => "zones/state",
30
+ :method => "get"
31
+ }
32
+ end
33
+
34
+
20
35
  def set_led(color, brightness)
21
36
  query_device @id, {
22
37
  :url => "state",
@@ -38,6 +53,61 @@ module Lono
38
53
 
39
54
 
40
55
 
56
+ # get_lono_info()
57
+ #
58
+ # Get a bunch of metadata that is stored internally with Lono, like
59
+ # hardware revision information and basic sceduling options.
60
+ #
61
+ def get_lono_info
62
+ query_device @id, {
63
+ :url => "",
64
+ :method => "get"
65
+ }
66
+ end
67
+
68
+
69
+ # get_zones_info()
70
+ #
71
+ # Get a bunch of metadata that is stored internally with each Zone, like
72
+ # cycle time and soil type.
73
+ #
74
+ def get_zones_info
75
+ query_device @id, {
76
+ :url => "zones",
77
+ :method => "get"
78
+ }
79
+ end
80
+
81
+
82
+ # detect_zones()
83
+ #
84
+ # Run a zone detect sequence to discover which zones have been attached to
85
+ # Lono.
86
+ #
87
+ def detect_zones
88
+ query_device @id, {
89
+ :url => "zones/detect",
90
+ :method => "post"
91
+ }
92
+ end
93
+
94
+
95
+ # put_zones(zones)
96
+ #
97
+ # Update the zones zonnected to a Lono with the zones specified. zones is
98
+ # an array of zone objects (like what you'd receive from get_zones_info).
99
+ #
100
+ def put_zones(zones)
101
+ query_device @id, {
102
+ :url => "zones",
103
+ :method => "put",
104
+ :body => {
105
+ :zones => zones
106
+ }
107
+ }
108
+ end
109
+
110
+
41
111
  # other api methods
42
112
  # def something_else do
43
113
  # query_device @id, {
@@ -59,11 +129,11 @@ module Lono
59
129
  "content-type" => "application/json",
60
130
  "Authorization" => "bearer #{@session_token.access_token}"
61
131
  },
62
- parameters: query[:body].to_json
132
+ parameters: query[:body] && query[:body].to_json || "{}"
63
133
  )
64
134
 
65
135
  if response.code == 200 and response.body.has_key? "name" and response.body["name"] =~ /success/
66
- true
136
+ response.body || true
67
137
  else
68
138
  raise Lono::CloudUnsuccessfulError.new(response.body['error'])
69
139
  end
@@ -1,4 +1,4 @@
1
1
  module Lono
2
2
  API_VERSION = 'v1'
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 1egoman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-27 00:00:00.000000000 Z
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,6 +81,7 @@ files:
81
81
  - LICENSE.txt
82
82
  - README.md
83
83
  - Rakefile
84
+ - bin/console
84
85
  - bin/setup
85
86
  - lib/lono-api.rb
86
87
  - lib/lono-api/.DS_Store