miles 0.0.1

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/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ notifications:
5
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'httparty', '0.10.2'
4
+
5
+ group :test do
6
+ gem 'rake', '0.9.2.2'
7
+ gem 'rspec', '2.12.0'
8
+ gem 'rspec-mocks', '2.12.0'
9
+ gem 'vcr', '2.4.0'
10
+ gem 'webmock', '1.9.3'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.3)
5
+ crack (0.3.2)
6
+ diff-lcs (1.1.3)
7
+ httparty (0.10.2)
8
+ multi_json (~> 1.0)
9
+ multi_xml (>= 0.5.2)
10
+ multi_json (1.6.1)
11
+ multi_xml (0.5.3)
12
+ rake (0.9.2.2)
13
+ rspec (2.12.0)
14
+ rspec-core (~> 2.12.0)
15
+ rspec-expectations (~> 2.12.0)
16
+ rspec-mocks (~> 2.12.0)
17
+ rspec-core (2.12.2)
18
+ rspec-expectations (2.12.1)
19
+ diff-lcs (~> 1.1.3)
20
+ rspec-mocks (2.12.0)
21
+ vcr (2.4.0)
22
+ webmock (1.9.3)
23
+ addressable (>= 2.2.7)
24
+ crack (>= 0.3.2)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ httparty (= 0.10.2)
31
+ rake (= 0.9.2.2)
32
+ rspec (= 2.12.0)
33
+ rspec-mocks (= 2.12.0)
34
+ vcr (= 2.4.0)
35
+ webmock (= 1.9.3)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = 'spec/*_spec.rb'
7
+ spec.rspec_opts = ['--backtrace', '--format documentation']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,58 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Miles
5
+ class Endpoint
6
+ include HTTParty
7
+
8
+ attr_reader :host, :port, :base_uri
9
+
10
+ def initialize(host, port=80)
11
+ @host = host
12
+ @port = port
13
+ @base_uri = "#{host}#{port != 80 ? ':' + @port.to_s : ''}"
14
+ self.class.base_uri @base_uri
15
+ end
16
+
17
+
18
+ def get_pin(pinnum)
19
+ response = self.class.get("/pin/#{pinnum}")
20
+ pin = JSON.parse(response.body)
21
+ return pin
22
+ end
23
+
24
+ def set_pin_mode(pinnum, mode)
25
+ if not mode == :input and not mode == :output
26
+ raise Exception
27
+ end
28
+
29
+ response = self.class.get("/pin/#{pinnum}/mode/#{mode.to_s}")
30
+ return JSON.parse(response.body)
31
+ end
32
+
33
+ def set_pin_high(pinnum)
34
+ response = self.class.post("/pin/#{pinnum}")
35
+ return JSON.parse(response.body)
36
+ end
37
+
38
+ def set_pin_low(pinnum)
39
+ response = self.class.delete("/pin/#{pinnum}")
40
+ return JSON.parse(response.body)
41
+ end
42
+
43
+ def temperature
44
+ response = self.class.get("/sensor/climate/temperature")
45
+ return JSON.parse(response.body)
46
+ end
47
+
48
+ def humidity
49
+ response = self.class.get("/sensor/climate/humidity")
50
+ return JSON.parse(response.body)
51
+ end
52
+
53
+ def dewpoint
54
+ response = self.class.get("/sensor/climate/dewpoint")
55
+ return JSON.parse(response.body)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Miles
2
+ VERSION = "0.0.1"
3
+ end
data/lib/miles.rb ADDED
@@ -0,0 +1 @@
1
+ require 'miles/endpoint'
data/miles.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/miles/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Brian McClain"]
6
+ gem.email = ["brianmmcclain@gmail.com"]
7
+ gem.description = %q{Miles Platform Library}
8
+ gem.summary = gem.summary
9
+ gem.homepage = "https://github.com/MilesPlatform/libmiles-ruby"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "miles"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Miles::VERSION
17
+ end
@@ -0,0 +1,138 @@
1
+ require 'spec_helper'
2
+
3
+ describe Miles::Endpoint do
4
+
5
+ before(:all) do
6
+ @endpoint = Miles::Endpoint.new('192.168.1.50')
7
+ end
8
+
9
+ it 'should instantiate' do
10
+ endpoint = Miles::Endpoint.new('192.168.1.50')
11
+
12
+ endpoint.should_not be_nil
13
+ endpoint.host.should == '192.168.1.50'
14
+ endpoint.port.should == 80
15
+ end
16
+
17
+ it 'should get the state of a pin' do
18
+ VCR.use_cassette('endpoint_get_pin') do
19
+ response = @endpoint.get_pin(5)
20
+
21
+ response.should be_a_kind_of(Hash)
22
+
23
+ response.should have_key('category')
24
+ response.should have_key('command')
25
+ response.should have_key('key')
26
+ response.should have_key('value')
27
+ response.should have_key('success')
28
+
29
+ response['category'].should == 'pin'
30
+ response['command'].should == 'value'
31
+ response['key'].should eq(5)
32
+ response['value'].should eq(0)
33
+ response['success'].should eq(true)
34
+ end
35
+ end
36
+
37
+ it 'should set pin mode' do
38
+ VCR.use_cassette('endpoint_set_pin_mode') do
39
+ response = @endpoint.set_pin_mode(5, :output)
40
+
41
+ response.should be_a_kind_of(Hash)
42
+
43
+ response.should have_key('category')
44
+ response.should have_key('command')
45
+ response.should have_key('key')
46
+ response.should have_key('value')
47
+ response.should have_key('success')
48
+
49
+ response['category'].should == 'pin'
50
+ response['command'].should == 'mode'
51
+ response['key'].should eq(5)
52
+ response['value'].should == "output"
53
+ response['success'].should eq(true)
54
+ end
55
+ end
56
+
57
+ it 'should set pin high' do
58
+ VCR.use_cassette('endpoint_set_pin_high') do
59
+ response = @endpoint.set_pin_high(5)
60
+
61
+ response.should be_a_kind_of(Hash)
62
+
63
+ response.should have_key('category')
64
+ response.should have_key('command')
65
+ response.should have_key('key')
66
+ response.should have_key('value')
67
+ response.should have_key('success')
68
+
69
+ response['category'].should == 'pin'
70
+ response['command'].should == 'value'
71
+ response['key'].should eq(5)
72
+ response['value'].should eq(1)
73
+ response['success'].should eq(true)
74
+ end
75
+ end
76
+
77
+ it 'should set pin low' do
78
+ VCR.use_cassette('endpoint_set_pin_low') do
79
+ response = @endpoint.set_pin_low(5)
80
+
81
+ response.should be_a_kind_of(Hash)
82
+
83
+ response.should have_key('category')
84
+ response.should have_key('command')
85
+ response.should have_key('key')
86
+ response.should have_key('value')
87
+ response.should have_key('success')
88
+
89
+ response['category'].should == 'pin'
90
+ response['command'].should == 'value'
91
+ response['key'].should eq(5)
92
+ response['value'].should eq(0)
93
+ response['success'].should eq(true)
94
+ end
95
+ end
96
+
97
+ it "should get the temperature" do
98
+ VCR.use_cassette('endpoint_temperature') do
99
+ response = @endpoint.temperature
100
+
101
+ response['category'].should == 'sensor'
102
+ response['command'].should == 'climate'
103
+ response['key'].should == 'temperature'
104
+ response['value'].should be_a_kind_of(Hash)
105
+ response['value'].should have_key('fahrenheit')
106
+ response['value'].should have_key('celsius')
107
+ response['value'].should have_key('kelvin')
108
+ response['value']['fahrenheit'].should eq(73.4)
109
+ response['value']['celsius'].should eq(23.0)
110
+ response['value']['kelvin'].should eq(296.15)
111
+ response['success'].should eq(true)
112
+ end
113
+ end
114
+
115
+ it "should get the humidity" do
116
+ VCR.use_cassette('endpoint_humidity') do
117
+ response = @endpoint.humidity
118
+
119
+ response['category'].should == 'sensor'
120
+ response['command'].should == 'climate'
121
+ response['key'].should == 'humidity'
122
+ response['value'].should eq(34.0)
123
+ response['success'].should eq(true)
124
+ end
125
+ end
126
+
127
+ it "should get the dew point" do
128
+ VCR.use_cassette('endpoint_dewpoint') do
129
+ response = @endpoint.dewpoint
130
+
131
+ response['category'].should == 'sensor'
132
+ response['command'].should == 'climate'
133
+ response['key'].should == 'dewpoint'
134
+ response['value'].should eq(6.32)
135
+ response['success'].should eq(true)
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,27 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://192.168.1.50/sensor/climate/dewpoint
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - Webduino/1.7
17
+ Access-Control-Allow-Origin:
18
+ - ! '*'
19
+ Content-Type:
20
+ - application/json
21
+ body:
22
+ encoding: US-ASCII
23
+ string: ! '{"category": "sensor","command": "climate","key": "dewpoint","success":
24
+ true, "value": 6.32}'
25
+ http_version:
26
+ recorded_at: Sun, 03 Mar 2013 07:57:32 GMT
27
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,27 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://192.168.1.50/pin/5
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - Webduino/1.7
17
+ Access-Control-Allow-Origin:
18
+ - ! '*'
19
+ Content-Type:
20
+ - application/json
21
+ body:
22
+ encoding: US-ASCII
23
+ string: ! '{"category": "pin", "command": "value", "key": 5, "value": 0, "success":
24
+ true}'
25
+ http_version:
26
+ recorded_at: Sun, 03 Mar 2013 07:08:12 GMT
27
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,27 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://192.168.1.50/sensor/climate/humidity
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - Webduino/1.7
17
+ Access-Control-Allow-Origin:
18
+ - ! '*'
19
+ Content-Type:
20
+ - application/json
21
+ body:
22
+ encoding: US-ASCII
23
+ string: ! '{"category": "sensor","command": "climate","key": "humidity","success":
24
+ true, "value": 34.00}'
25
+ http_version:
26
+ recorded_at: Sun, 03 Mar 2013 07:55:12 GMT
27
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,27 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://192.168.1.50/pin/5
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - Webduino/1.7
17
+ Access-Control-Allow-Origin:
18
+ - ! '*'
19
+ Content-Type:
20
+ - application/json
21
+ body:
22
+ encoding: US-ASCII
23
+ string: ! '{"category": "pin", "command": "value", "key": 5, "value": 1, "success":
24
+ true}'
25
+ http_version:
26
+ recorded_at: Sun, 03 Mar 2013 07:42:11 GMT
27
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,27 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: http://192.168.1.50/pin/5
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - Webduino/1.7
17
+ Access-Control-Allow-Origin:
18
+ - ! '*'
19
+ Content-Type:
20
+ - application/json
21
+ body:
22
+ encoding: US-ASCII
23
+ string: ! '{"category": "pin", "command": "value", "key": 5, "value": 0, "success":
24
+ true}'
25
+ http_version:
26
+ recorded_at: Sun, 03 Mar 2013 07:45:10 GMT
27
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,27 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://192.168.1.50/pin/5/mode/output
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - Webduino/1.7
17
+ Access-Control-Allow-Origin:
18
+ - ! '*'
19
+ Content-Type:
20
+ - application/json
21
+ body:
22
+ encoding: US-ASCII
23
+ string: ! '{"category": "pin", "command": "mode", "key": 5, "value": "output",
24
+ "success": true}'
25
+ http_version:
26
+ recorded_at: Sun, 03 Mar 2013 07:35:37 GMT
27
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,27 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://192.168.1.50/sensor/climate/temperature
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - Webduino/1.7
17
+ Access-Control-Allow-Origin:
18
+ - ! '*'
19
+ Content-Type:
20
+ - application/json
21
+ body:
22
+ encoding: US-ASCII
23
+ string: ! '{"category": "sensor","command": "climate","key": "temperature","success":
24
+ true, "value": {"fahrenheit": 73.40,"celsius": 23.00,"kelvin": 296.15}}'
25
+ http_version:
26
+ recorded_at: Sun, 03 Mar 2013 07:50:19 GMT
27
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,9 @@
1
+ require_relative '../lib/miles'
2
+
3
+ require 'vcr'
4
+ require 'webmock'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
8
+ c.hook_into :webmock
9
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: miles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian McClain
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Miles Platform Library
15
+ email:
16
+ - brianmmcclain@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .travis.yml
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - Rakefile
26
+ - lib/miles.rb
27
+ - lib/miles/endpoint.rb
28
+ - lib/miles/version.rb
29
+ - miles.gemspec
30
+ - spec/endpoint_spec.rb
31
+ - spec/fixtures/vcr_cassettes/endpoint_dewpoint.yml
32
+ - spec/fixtures/vcr_cassettes/endpoint_get_pin.yml
33
+ - spec/fixtures/vcr_cassettes/endpoint_humidity.yml
34
+ - spec/fixtures/vcr_cassettes/endpoint_set_pin_high.yml
35
+ - spec/fixtures/vcr_cassettes/endpoint_set_pin_low.yml
36
+ - spec/fixtures/vcr_cassettes/endpoint_set_pin_mode.yml
37
+ - spec/fixtures/vcr_cassettes/endpoint_temperature.yml
38
+ - spec/spec_helper.rb
39
+ homepage: https://github.com/MilesPlatform/libmiles-ruby
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ segments:
52
+ - 0
53
+ hash: 3896679767492851176
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.24
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: ''
66
+ test_files:
67
+ - spec/endpoint_spec.rb
68
+ - spec/fixtures/vcr_cassettes/endpoint_dewpoint.yml
69
+ - spec/fixtures/vcr_cassettes/endpoint_get_pin.yml
70
+ - spec/fixtures/vcr_cassettes/endpoint_humidity.yml
71
+ - spec/fixtures/vcr_cassettes/endpoint_set_pin_high.yml
72
+ - spec/fixtures/vcr_cassettes/endpoint_set_pin_low.yml
73
+ - spec/fixtures/vcr_cassettes/endpoint_set_pin_mode.yml
74
+ - spec/fixtures/vcr_cassettes/endpoint_temperature.yml
75
+ - spec/spec_helper.rb