Class: Megam::Sensors
- Inherits:
-
RestAdapter
- Object
- RestAdapter
- Megam::Sensors
- Defined in:
- lib/megam/core/sensors.rb
Class Method Summary collapse
- .create(params) ⇒ Object
- .from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
- .json_create(o) ⇒ Object
- .list(o) ⇒ Object
-
.show(params) ⇒ Object
Load a account by email_p.
- .update(params) ⇒ Object
Instance Method Summary collapse
- #create ⇒ Object
- #created_at(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
-
#initialize(email = nil, api_key = nil, host = nil) ⇒ Sensors
constructor
A new instance of Sensors.
- #payload(arg = nil) ⇒ Object
- #sensor_type(arg = nil) ⇒ Object
- #sensors ⇒ Object
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat.
- #to_s ⇒ Object
-
#update ⇒ Object
Create the node via the REST API.
Constructor Details
#initialize(email = nil, api_key = nil, host = nil) ⇒ Sensors
Returns a new instance of Sensors.
3 4 5 6 7 8 9 |
# File 'lib/megam/core/sensors.rb', line 3 def initialize(email = nil, api_key = nil, host = nil) @id = nil @sensor_type = nil @payload = {} @created_at = nil super(email, api_key, host) end |
Class Method Details
.create(params) ⇒ Object
102 103 104 105 |
# File 'lib/megam/core/sensors.rb', line 102 def self.create(params) sensors = from_hash(params, params['email'], params['api_key'], params['host']) sensors.create end |
.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) ⇒ Object
88 89 90 91 92 |
# File 'lib/megam/core/sensors.rb', line 88 def self.from_hash(o, tmp_email = nil, tmp_api_key = nil, tmp_host = nil) asm = new(tmp_email, tmp_api_key, tmp_host) asm.from_hash(o) asm end |
.json_create(o) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/megam/core/sensors.rb', line 79 def self.json_create(o) asm = new asm.id(o['id']) if o.key?('id') asm.sensor_type(o['sensor_type']) if o.key?('sensor_type') asm.payload(o['payload']) if o.key?('payload') asm.created_at(o['created_at']) if o.key?('created_at') asm end |
.list(o) ⇒ Object
113 114 115 116 |
# File 'lib/megam/core/sensors.rb', line 113 def self.list(params) sensors = self.new(params["email"], params["api_key"], params["host"]) sensors.megam_rest.get_sensors end |
.show(params) ⇒ Object
Load a account by email_p
108 109 110 111 |
# File 'lib/megam/core/sensors.rb', line 108 def self.show(params) sensors = new(params['email'], params['api_key'], params['host']) sensors.megam_rest.get_sensor(params['id']) end |
.update(params) ⇒ Object
118 119 120 121 |
# File 'lib/megam/core/sensors.rb', line 118 def self.update(params) sensors = from_hash(params, params['email'] || params[:email], params['api_key'] || params[:api_key], params['host'] || params[:host]) sensors.update end |
Instance Method Details
#create ⇒ Object
133 134 135 |
# File 'lib/megam/core/sensors.rb', line 133 def create megam_rest.post_sensors(to_hash) end |
#created_at(arg = nil) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/megam/core/sensors.rb', line 39 def created_at(arg = nil) if !arg.nil? @created_at = arg else @created_at end end |
#error? ⇒ Boolean
47 48 49 |
# File 'lib/megam/core/sensors.rb', line 47 def error? crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error' end |
#for_json ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/megam/core/sensors.rb', line 69 def for_json result = { 'id' => id, 'sensor_type' => sensor_type, 'payload' => payload, 'created_at' => created_at } result end |
#from_hash(o) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/megam/core/sensors.rb', line 94 def from_hash(o) @id = o['id'] if o.key?('id') @sensor_type = o['sensor_type'] if o.key?('sensor_type') @payload = o['payload'] if o.key?('payload') @created_at = o['created_at'] if o.key?('created_at') self end |
#id(arg = nil) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/megam/core/sensors.rb', line 15 def id(arg = nil) if !arg.nil? @id = arg else @id end end |
#payload(arg = nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/megam/core/sensors.rb', line 31 def payload(arg = nil) if !arg.nil? @payload = arg else @payload end end |
#sensor_type(arg = nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/megam/core/sensors.rb', line 23 def sensor_type(arg = nil) if !arg.nil? @sensor_type = arg else @sensor_type end end |
#sensors ⇒ Object
11 12 13 |
# File 'lib/megam/core/sensors.rb', line 11 def sensors self end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/megam/core/sensors.rb', line 52 def to_hash index_hash = {} index_hash['json_claz'] = self.class.name index_hash['id'] = id index_hash['sensor_type'] = sensor_type index_hash['payload'] = payload index_hash['created_at'] = created_at index_hash end |
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.
65 66 67 |
# File 'lib/megam/core/sensors.rb', line 65 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
137 138 139 |
# File 'lib/megam/core/sensors.rb', line 137 def to_s Megam::Stuff.styled_hash(to_hash) end |
#update ⇒ Object
Create the node via the REST API
129 130 131 |
# File 'lib/megam/core/sensors.rb', line 129 def update megam_rest.update_(to_hash) end |