Class: Oksky::Chat::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Oksky::Chat::Request

Initializes a new Request

Yields:

  • (_self)

Yield Parameters:



14
15
16
# File 'lib/oksky/chat/request.rb', line 14

def initialize
  yield(self) if block_given?
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



9
10
11
# File 'lib/oksky/chat/request.rb', line 9

def credentials
  @credentials
end

#endpointObject

Returns the value of attribute endpoint.



9
10
11
# File 'lib/oksky/chat/request.rb', line 9

def endpoint
  @endpoint
end

#endpoint_pathObject

Returns the value of attribute endpoint_path.



9
10
11
# File 'lib/oksky/chat/request.rb', line 9

def endpoint_path
  @endpoint_path
end

#httpclientObject

Returns the value of attribute httpclient.



9
10
11
# File 'lib/oksky/chat/request.rb', line 9

def httpclient
  @httpclient
end

#payloadHash

Returns:

  • (Hash)


19
20
21
# File 'lib/oksky/chat/request.rb', line 19

def payload
  @payload
end

Instance Method Details

#assert_for_getting_messageObject

Raises:

  • (ArgumentError)


63
64
65
# File 'lib/oksky/chat/request.rb', line 63

def assert_for_getting_message
  raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
end

#assert_for_posting_messageObject

Raises:

  • (ArgumentError)


67
68
69
# File 'lib/oksky/chat/request.rb', line 67

def assert_for_posting_message
  raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String)
end

#getNet::HTTPResponse

Get content of specified URL.

Returns:

  • (Net::HTTPResponse)


38
39
40
41
# File 'lib/oksky/chat/request.rb', line 38

def get
  assert_for_getting_message
  httpclient.get(endpoint + endpoint_path, payload, header)
end

#headerHash

Returns:

  • (Hash)


24
25
26
27
28
29
30
31
32
33
# File 'lib/oksky/chat/request.rb', line 24

def header
  header = {
    'Content-Type' => 'application/vnd.api+json',
    'Accept' => 'application/vnd.api+json',
    'User-Agent' => "OKSKY-CHAT-SDK-Ruby/#{Oksky::Chat::API::VERSION}"
  }
  hash = credentials.inject({}) { |h, (k, v)| h[k] = v.to_s; h }

  header.merge(hash)
end

#postNet::HTTPResponse

Post content of specified URL.

Returns:

  • (Net::HTTPResponse)

Raises:

  • (ArgumentError)


48
49
50
51
# File 'lib/oksky/chat/request.rb', line 48

def post
  assert_for_posting_message
  httpclient.post(endpoint + endpoint_path, payload.to_json, header)
end

#putNet::HTTPResponse

Put content of specified URL.

Returns:

  • (Net::HTTPResponse)

Raises:

  • (ArgumentError)


58
59
60
61
# File 'lib/oksky/chat/request.rb', line 58

def put
  assert_for_posting_message
  httpclient.put(endpoint + endpoint_path, payload.to_json, header)
end