milk_maid 0.2.8 → 0.3.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: 85e14c83ac66b5a28f743a59b9821f75d4e50ef6
4
- data.tar.gz: 8a7238c82a83a9108fbdfc01f22b18fd24e45b90
3
+ metadata.gz: 33a6d723a5681ed0a09d2dd811cbb81bed6e59cf
4
+ data.tar.gz: 0736df68f79f62ca94beb0e8f614e4461952efb2
5
5
  SHA512:
6
- metadata.gz: 2d6fe840d2ab159843b80a81cef2319b48ba7ce730bde261991596f8aaebbca857c9449e8a468c08bae383eedb320412bcdda5598ab075f53514e49f67df1206
7
- data.tar.gz: 69da5db52b4d23a5d53c8b9fc5e7362914d3f23a54dafac6b3359a08c9782285b81b9c41078a72636b133112761f1e6aaede38cd57be1525cba71cdb48dc1b3a
6
+ metadata.gz: deb4cb3f62e2861aef25e6191686c3a0af9ba1418af18f1c4ac0227edaae40a05276b00e363027abdc4e1dee0640edcfbfd17e0f20ace442c94b8aca4be1d380
7
+ data.tar.gz: 77b6ab9c9c650d340d4d1db2f721ea8dc73ca1d0434baa0dce8920a942664144ac99a02e21da4a8ba018faede8dcead0a56ec9c305fd95cf80570e2464e3f1a6
@@ -1,10 +1,11 @@
1
1
  require 'firebase'
2
+ require 'pry'
2
3
  require 'yaml'
3
4
 
4
5
  module MilkMaid
5
6
  module FirebaseNotifier
6
7
  class BatchRecord
7
- attr_accessor :name, :guid, :duration, :base_temperature, :batch_size, :status, :record
8
+ attr_accessor :name, :guid, :duration, :base_temperature, :batch_size, :status, :record, :id
8
9
 
9
10
  CACHE_THRESHOLD = 20
10
11
 
@@ -16,18 +17,20 @@ module MilkMaid
16
17
  batch_data.each { |key, value| send("#{key}=", value) }
17
18
  @status = 'Started'
18
19
 
19
- self.create_remote_record
20
+ @id = create_remote_record
20
21
  end
21
22
 
22
23
  def create_remote_record
23
24
  @response = @firebase.push("batches", {
24
- :guid => guid,
25
25
  :name => name,
26
+ :guid => guid,
26
27
  :duration => duration,
27
28
  :base_temperature => base_temperature,
28
29
  :batch_size => batch_size,
29
30
  :status => status
30
31
  })
32
+
33
+ @response.body['name']
31
34
  end
32
35
 
33
36
  def add_event(event_type, data = 0)
@@ -43,7 +46,7 @@ module MilkMaid
43
46
  end
44
47
 
45
48
  def close_batch
46
- @firebase.update("/batches/#{guid}", :status => 'Completed')
49
+ @firebase.update("/batches/#{id}", :status => 'Completed')
47
50
  end
48
51
 
49
52
  def complete!
@@ -61,7 +64,7 @@ module MilkMaid
61
64
 
62
65
  def send_events!
63
66
  events.each do |event|
64
- @firebase.push("/batches/#{guid}/events", event.to_h)
67
+ @firebase.push("/batches/#{id}/events", event.to_h)
65
68
  end
66
69
 
67
70
  @events = []
@@ -1,3 +1,3 @@
1
1
  module MilkMaid
2
- VERSION = "0.2.8"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/milk_maid.rb CHANGED
@@ -2,7 +2,6 @@ require 'milk_maid/batch'
2
2
  require 'milk_maid/cli'
3
3
  require 'milk_maid/console_notifier'
4
4
  require 'milk_maid/parse_notifier'
5
- require 'milk_maid/remote_notifier/batch_record'
6
5
  require 'milk_maid/firebase_notifier/batch_record'
7
6
  require 'milk_maid/temperature_sensor'
8
7
  require 'milk_maid/version'
data/milk_maid.gemspec CHANGED
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec"
36
36
  spec.add_development_dependency "guard-rspec"
37
+ spec.add_development_dependency "pry"
37
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milk_maid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Newell
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Reads data from Raspberry PI sensor and posts to Firebase
126
140
  email:
127
141
  - steve.newell@mx.com
@@ -146,7 +160,6 @@ files:
146
160
  - lib/milk_maid/firebase_notifier.rb
147
161
  - lib/milk_maid/firebase_notifier/batch_record.rb
148
162
  - lib/milk_maid/parse_notifier.rb
149
- - lib/milk_maid/remote_notifier/batch_record.rb
150
163
  - lib/milk_maid/temperature_sensor.rb
151
164
  - lib/milk_maid/version.rb
152
165
  - milk_maid.gemspec
@@ -1,80 +0,0 @@
1
- require 'parse-ruby-client'
2
-
3
- module MilkMaid
4
- module RemoteNotifier
5
- class BatchRecord
6
- attr_accessor :name, :guid, :duration, :base_temperature, :batch_size, :status, :record
7
-
8
- def initialize
9
- Parse.init(
10
- :application_id => 'JxuqdmEaI0DYwxcDV1imv2S64PWMLNjJq3wpGcVC',
11
- :api_key => 'dsEh8Uqc3gwT9kYcG6OvR9W6pRlzcZlG6X9NeClS'
12
- )
13
- end
14
-
15
- def start(batch_data = {})
16
- batch_data.each { |key, value| send("#{key}=", value) }
17
- @status = 'Started'
18
- self.create_remote_record
19
- end
20
-
21
- def create_remote_record
22
- @record = ::Parse::Object.new('BatchRecords')
23
- @record[:name] = name
24
- @record[:guid] = guid
25
- @record[:duration] = duration
26
- @record[:base_temperature] = base_temperature
27
- @record[:batch_size] = batch_size
28
- @record[:status] = status
29
-
30
- @record.save
31
- end
32
-
33
- def add_event(event_type, data = 0)
34
- events << ::MilkMaid::RemoteNotifier::Event.new(name: event_name_from_type(event_type), data: data, timestamp: timestamp)
35
- return if event_type == :temperature
36
- send_events!
37
- end
38
-
39
- def close_batch
40
- @record[:status] = 'Completed'
41
- @record.save
42
- end
43
-
44
- def complete!
45
- add_event(:batch_completed)
46
- close_batch
47
- end
48
-
49
- def event_name_from_type(event)
50
- event.to_s.split(/_/).map(&:capitalize).join(' ')
51
- end
52
-
53
- def events
54
- @events ||= []
55
- end
56
-
57
- def send_events!
58
- events.each do |event|
59
- event.save
60
- @record.array_add_relation("BatchRecordEvents", event.pointer)
61
- @record.save
62
- end
63
-
64
- end
65
-
66
- def timestamp
67
- Time.now
68
- end
69
- end
70
-
71
- class Event < ::Parse::Object
72
- def initialize(params = {})
73
- super('Events')
74
- self[:name] = params.fetch(:name)
75
- self[:data] = params.fetch(:data)
76
- self[:timestamp] = params.fetch(:timestamp)
77
- end
78
- end
79
- end
80
- end