Class: DeviceCloud::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/device_cloud/request.rb

Overview

Public: Used to send Net::HTTP requests.

Examples:

get_response = DeviceCloud::Request.new("/ws/FileData").get
post_response = DeviceCloud::Request.new("/ws/sci").post(data)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Public: Create a new instance of Request.

path - The path String to use.



16
17
18
19
# File 'lib/device_cloud/request.rb', line 16

def initialize(options = {})
  @path = options[:path]
  @body = options[:body]
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/device_cloud/request.rb', line 11

def body
  @body
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/device_cloud/request.rb', line 11

def path
  @path
end

Instance Method Details

#deleteObject

Public: Send a DELETE request.

Returns a DeviceCloud::Response instance.



55
56
57
58
59
# File 'lib/device_cloud/request.rb', line 55

def delete
  make_request do
    Net::HTTP::Delete.new request_uri
  end
end

#getObject

Public: Send a GET request.

Returns a DeviceCloud::Response instance.



24
25
26
27
28
# File 'lib/device_cloud/request.rb', line 24

def get
  make_request do
    Net::HTTP::Get.new request_uri
  end
end

#postObject

Public: Send a POST request.

body

Returns a DeviceCloud::Response instance.



35
36
37
38
39
# File 'lib/device_cloud/request.rb', line 35

def post
  make_request do
    Net::HTTP::Post.new request_uri
  end
end

#putObject

Public: Send a PUT request.

body

Returns a DeviceCloud::Response instance.



46
47
48
49
50
# File 'lib/device_cloud/request.rb', line 46

def put
  make_request do
    Net::HTTP::Put.new request_uri
  end
end