Class: Imified::Request

Inherits:
Net::HTTP::Post
  • Object
show all
Defined in:
lib/imified/request.rb

Overview

request.rb

Net::HTTP::Post wrapper

All API calls for requesting user details and sending messages should be sent via HTTP POST to the following URL: www.imified.com/api/bot/.

Authentication is managed using Basic HTTP authentication. Every request must include the Authorization HTTP header with your IMified username and password.

Constant Summary collapse

URL =
URI.parse(Imified::URL)

Instance Method Summary collapse

Constructor Details

#initialize(api_method = 'getallusers') ⇒ Request

Construct a Net::HTTP::Post object. Prepare basic authentication using the username and password specified in the configuration.

Usage

Imified::Request.new

@return



24
25
26
27
28
29
30
31
# File 'lib/imified/request.rb', line 24

def initialize(api_method = 'getallusers')
  Imified.validate_configuration!
  super(URL.path)

  self.basic_auth Imified.email_address, Imified.password
  self.add_field 'apimethod', api_method
  self.add_field 'botkey', Imified.botkey
end

Instance Method Details

#submitObject

Submit the request to Imified.



34
35
36
37
38
# File 'lib/imified/request.rb', line 34

def submit
  http = Net::HTTP.new(URL.host, URL.port)
  http.use_ssl = true
  http.start { |send| send.request(self) }.body
end