Class: Cubits::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/cubits/connection.rb

Constant Summary collapse

CONTENT_TYPE =
'application/vnd.api+json'

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Connection

Creates a new Connection object

Parameters:

  • params (Hash)
  • params (:key)
    String
  • params (:secret)
    String


17
18
19
20
21
22
# File 'lib/cubits/connection.rb', line 17

def initialize(params)
  fail ArgumentError, 'String is expected as :key' unless params[:key].is_a?(String)
  fail ArgumentError, 'String is expected as :secret' unless params[:secret].is_a?(String)
  @key = params[:key]
  @secret = params[:secret]
end

Instance Method Details

#get(path, data = {}) ⇒ Object

Executes a GET request



26
27
28
29
30
# File 'lib/cubits/connection.rb', line 26

def get(path, data = {})
  fail ArgumentError, 'Hash is expected as request data' unless data.is_a?(Hash)
  encoded_data = URI.encode_www_form(data)
  request(:get, path, encoded_data)
end

#post(path, data = {}) ⇒ Object

Executes a POST request



34
35
36
37
38
# File 'lib/cubits/connection.rb', line 34

def post(path, data = {})
  fail ArgumentError, 'Hash is expected as request data' unless data.is_a?(Hash)
  encoded_data = data.to_json
  request(:post, path, encoded_data)
end