Class: Oksky::Chat::Request
- Inherits:
-
Object
- Object
- Oksky::Chat::Request
- Defined in:
- lib/oksky/chat/request.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#endpoint_path ⇒ Object
Returns the value of attribute endpoint_path.
-
#httpclient ⇒ Object
Returns the value of attribute httpclient.
- #payload ⇒ Hash
Instance Method Summary collapse
- #assert_for_getting_message ⇒ Object
- #assert_for_posting_message ⇒ Object
-
#get ⇒ Net::HTTPResponse
Get content of specified URL.
- #header ⇒ Hash
-
#initialize {|_self| ... } ⇒ Oksky::Chat::Request
constructor
Initializes a new Request.
-
#post ⇒ Net::HTTPResponse
Post content of specified URL.
-
#put ⇒ Net::HTTPResponse
Put content of specified URL.
Constructor Details
#initialize {|_self| ... } ⇒ Oksky::Chat::Request
Initializes a new Request
14 15 16 |
# File 'lib/oksky/chat/request.rb', line 14 def initialize yield(self) if block_given? end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
9 10 11 |
# File 'lib/oksky/chat/request.rb', line 9 def credentials @credentials end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/oksky/chat/request.rb', line 9 def endpoint @endpoint end |
#endpoint_path ⇒ Object
Returns the value of attribute endpoint_path.
9 10 11 |
# File 'lib/oksky/chat/request.rb', line 9 def endpoint_path @endpoint_path end |
#httpclient ⇒ Object
Returns the value of attribute httpclient.
9 10 11 |
# File 'lib/oksky/chat/request.rb', line 9 def httpclient @httpclient end |
#payload ⇒ Hash
19 20 21 |
# File 'lib/oksky/chat/request.rb', line 19 def payload @payload end |
Instance Method Details
#assert_for_getting_message ⇒ Object
63 64 65 |
# File 'lib/oksky/chat/request.rb', line 63 def raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String) end |
#assert_for_posting_message ⇒ Object
67 68 69 |
# File 'lib/oksky/chat/request.rb', line 67 def raise ArgumentError, 'Wrong argument type `endpoint_path`' unless endpoint_path.is_a?(String) end |
#get ⇒ Net::HTTPResponse
Get content of specified URL.
38 39 40 41 |
# File 'lib/oksky/chat/request.rb', line 38 def get httpclient.get(endpoint + endpoint_path, payload, header) end |
#header ⇒ 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 |
#post ⇒ Net::HTTPResponse
Post content of specified URL.
48 49 50 51 |
# File 'lib/oksky/chat/request.rb', line 48 def post httpclient.post(endpoint + endpoint_path, payload.to_json, header) end |
#put ⇒ Net::HTTPResponse
Put content of specified URL.
58 59 60 61 |
# File 'lib/oksky/chat/request.rb', line 58 def put httpclient.put(endpoint + endpoint_path, payload.to_json, header) end |