Class: MonogotoApi::Thing

Inherits:
Object
  • Object
show all
Defined in:
lib/monogoto_api/thing.rb

Overview

Thing refer to Monogoto SIM

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ Thing

Returns a new instance of Thing.



8
9
10
11
12
13
14
15
# File 'lib/monogoto_api/thing.rb', line 8

def initialize(**attributes)
    @iccid    = attributes[:iccid]
    @imei     = attributes[:imei]
    @operator = attributes[:operator]
    @state    = attributes[:state]
    @name     = attributes[:name]
    @ips      = attributes[:ips]
end

Instance Attribute Details

#iccidObject (readonly)

Returns the value of attribute iccid.



6
7
8
# File 'lib/monogoto_api/thing.rb', line 6

def iccid
  @iccid
end

#imeiObject (readonly)

Returns the value of attribute imei.



6
7
8
# File 'lib/monogoto_api/thing.rb', line 6

def imei
  @imei
end

#ipsObject (readonly)

Returns the value of attribute ips.



6
7
8
# File 'lib/monogoto_api/thing.rb', line 6

def ips
  @ips
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/monogoto_api/thing.rb', line 6

def name
  @name
end

#operatorObject (readonly)

Returns the value of attribute operator.



6
7
8
# File 'lib/monogoto_api/thing.rb', line 6

def operator
  @operator
end

#stateObject (readonly)

Returns the value of attribute state.



6
7
8
# File 'lib/monogoto_api/thing.rb', line 6

def state
  @state
end

Class Method Details

.parse(hash_thing) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/monogoto_api/thing.rb', line 25

def self.parse(hash_thing)
    ips = MonogotoApi::IP.parse_many(hash_thing["IPs"])
    new(
        imei: hash_thing["IMEI"],
        name: hash_thing["ThingName"],
        iccid: hash_thing["ExternalUniqueId"],
        operator: hash_thing["MnoName"],
        state: hash_thing["State"],
        ips:
    )
end

.parse_many(response) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/monogoto_api/thing.rb', line 17

def self.parse_many(response)
    output = []
    response.each do |pre_thing|
        output.push(parse(pre_thing))
    end
    output
end

Instance Method Details

#ipObject



37
38
39
# File 'lib/monogoto_api/thing.rb', line 37

def ip
    @ips.first.ip
end