Class: CoRE::CoAP::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/core/coap/client.rb

Overview

CoAP client library

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client


15
16
17
18
19
20
21
22
23
24
# File 'lib/core/coap/client.rb', line 15

def initialize(options = {})
  @max_payload = options[:max_payload] || 256

  @host = options[:host]
  @port = options[:port] || CoAP::PORT

  @options = options

  @logger = CoAP.logger
end

Instance Attribute Details

#hostObject

Returns the value of attribute host


7
8
9
# File 'lib/core/coap/client.rb', line 7

def host
  @host
end

#max_payloadObject

Returns the value of attribute max_payload


7
8
9
# File 'lib/core/coap/client.rb', line 7

def max_payload
  @max_payload
end

#portObject

Returns the value of attribute port


7
8
9
# File 'lib/core/coap/client.rb', line 7

def port
  @port
end

Instance Method Details

#delete(*args) ⇒ Object

DELETE


114
115
116
# File 'lib/core/coap/client.rb', line 114

def delete(*args)
  client(:delete, *args)
end

#delete_by_uri(uri, *args) ⇒ Object

DELETE by URI


125
126
127
# File 'lib/core/coap/client.rb', line 125

def delete_by_uri(uri, *args)
  delete(*decode_uri(uri), *args)
end

#get(*args) ⇒ Object

GET


42
43
44
# File 'lib/core/coap/client.rb', line 42

def get(*args)
  client(:get, *args)
end

#get_by_uri(uri, *args) ⇒ Object

GET by URI


53
54
55
# File 'lib/core/coap/client.rb', line 53

def get_by_uri(uri, *args)
  get(*decode_uri(uri), *args)
end

#observe(path, host, port, callback, payload = nil, options = {}) ⇒ Object

OBSERVE


140
141
142
143
# File 'lib/core/coap/client.rb', line 140

def observe(path, host, port, callback, payload = nil, options = {})
  options[:observe] = 0
  client(:get, path, host, port, payload, options, callback)
end

#observe_by_uri(uri, *args) ⇒ Object

OBSERVE by URI


154
155
156
# File 'lib/core/coap/client.rb', line 154

def observe_by_uri(uri, *args)
  observe(*decode_uri(uri), *args)
end

#post(*args) ⇒ Object

POST


66
67
68
# File 'lib/core/coap/client.rb', line 66

def post(*args)
  client(:post, *args)
end

#post_by_uri(uri, *args) ⇒ Object

POST by URI


77
78
79
# File 'lib/core/coap/client.rb', line 77

def post_by_uri(uri, *args)
  post(*decode_uri(uri), *args)
end

#put(*args) ⇒ Object

PUT


90
91
92
# File 'lib/core/coap/client.rb', line 90

def put(*args)
  client(:put, *args)
end

#put_by_uri(uri, *args) ⇒ Object

PUT by URI


101
102
103
# File 'lib/core/coap/client.rb', line 101

def put_by_uri(uri, *args)
  put(*decode_uri(uri), *args)
end

#use_dtlsObject

Enable DTLS socket.


27
28
29
30
31
# File 'lib/core/coap/client.rb', line 27

def use_dtls
  require 'CoDTLS'
  @options[:socket] = CoDTLS::SecureSocket
  self
end