Module: ZephyrRuby::Connection

Included in:
Client
Defined in:
lib/zephyr_ruby/connection.rb

Overview

Connection provides the base functionality for interacting with APIs using get, post, put, and delete operations.

Instance Method Summary collapse

Instance Method Details

#delete(path, params = {}) ⇒ Object



34
35
36
# File 'lib/zephyr_ruby/connection.rb', line 34

def delete(path, params = {})
  request :delete, path, params
end

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



7
8
9
# File 'lib/zephyr_ruby/connection.rb', line 7

def get(path, params = {})
  request :get, path, params
end

#post(path, body, file_path = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zephyr_ruby/connection.rb', line 11

def post(path, body, file_path = nil)
  if file_path
    mime_type = case File.extname(file_path).downcase
                when '.json' then 'application/json'
                when '.xml'  then 'application/xml'
                when '.zip'  then 'application/zip'
                else 'application/octet-stream'
                end

    file = Faraday::UploadIO.new(file_path, mime_type)
    body = { file: file }.merge(body) if body.is_a?(Hash)
  elsif body.is_a?(Hash)
    body = body.to_json
  end

  request :post, path, body
end

#put(path, body) ⇒ Object



29
30
31
32
# File 'lib/zephyr_ruby/connection.rb', line 29

def put(path, body)
  body = body.to_json if body.is_a?(Hash)
  request :put, path, body
end