Class: MonogotoApi::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/monogoto_api/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, password) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
# File 'lib/monogoto_api/client.rb', line 11

def initialize(user, password)
    auth = { "UserName" => user, "Password" => password }
    jwt_response = post(
        "/Auth",
        body: auth.to_json, headers: { "Content-Type" => "application/json" }
    )

    @jwt         = jwt_response["token"]
    @customer_id = jwt_response["CustomerId"]
end

Instance Method Details

#thing(iccid) ⇒ Object



27
28
29
30
# File 'lib/monogoto_api/client.rb', line 27

def thing(iccid)
    resp = get("/thing/ThingId_ICCID_#{ iccid }", headers: auth_header)
    MonogotoApi::Thing.parse(resp.parsed_response)
end

#thing_events(iccid, limit: 20) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/monogoto_api/client.rb', line 41

def thing_events(iccid, limit: 20)
    body = { "ThingIdELK" => "ThingId_ICCID_#{ iccid }", "limit" => limit }
    # body.merge!(opts) if opts.any?
    resp = post(
        "/thing/searchCDR",
        body:,
        headers: apikey_headers
    )
    MonogotoApi::Event::List.parse(resp)
end

#thing_ping(iccid) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/monogoto_api/client.rb', line 52

def thing_ping(iccid)
    thing_data = thing(iccid)
    resp = post(
        "/thing/ThingId_ICCID_#{ iccid }/ping",
        body: { "IPAddress" => thing_data.ip },
        headers: apikey_headers
    )
    MonogotoApi::Ping::List.parse(resp)
end

#thing_refresh_connection(iccid) ⇒ Object



62
63
64
65
# File 'lib/monogoto_api/client.rb', line 62

def thing_refresh_connection(iccid)
    resp = get("/thing/ThingId_ICCID_#{ iccid }/refreshConnection", headers: auth_header)
    resp.success?
end

#thing_session_status(iccid) ⇒ Object



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

def thing_session_status(iccid)
    resp = get("/thing/status/?ThingIds=ThingId_ICCID_#{ iccid }", headers: auth_header)
    MonogotoApi::SessionStatus.parse(resp.parsed_response)
end

#thing_state(iccid) ⇒ Object



32
33
34
# File 'lib/monogoto_api/client.rb', line 32

def thing_state(iccid)
    get("/thing/ThingId_ICCID_#{ iccid }/state", headers: auth_header).body
end

#thingsObject



22
23
24
25
# File 'lib/monogoto_api/client.rb', line 22

def things
    resp = get("/things", headers: auth_header)
    MonogotoApi::Thing.parse_many(resp.parsed_response)
end