Class: FizzyApiClient::Connection

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Connection

Returns a new instance of Connection.



5
6
7
# File 'lib/fizzy_api_client/connection.rb', line 5

def initialize(config)
  @config = config
end

Instance Method Details

#delete(path, params: {}, headers: {}) ⇒ Object



25
26
27
# File 'lib/fizzy_api_client/connection.rb', line 25

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

#follow_location(response) ⇒ Object

Follow a Location header and return the resource



30
31
32
33
34
35
36
37
# File 'lib/fizzy_api_client/connection.rb', line 30

def follow_location(response)
  return response unless response.created_with_location?

  location = response.location
  # Strip .json suffix if present for cleaner path
  path = location.sub(/\.json\z/, "")
  get(path)
end

#get(path, params: {}, headers: {}) ⇒ Object



9
10
11
# File 'lib/fizzy_api_client/connection.rb', line 9

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

#patch(path, body: {}, headers: {}) ⇒ Object



21
22
23
# File 'lib/fizzy_api_client/connection.rb', line 21

def patch(path, body: {}, headers: {})
  request(:patch, path, body: body, headers: headers)
end

#post(path, body: {}, headers: {}) ⇒ Object



13
14
15
# File 'lib/fizzy_api_client/connection.rb', line 13

def post(path, body: {}, headers: {})
  request(:post, path, body: body, headers: headers)
end

#post_multipart(path, fields: {}, files: {}, headers: {}) ⇒ Object



39
40
41
# File 'lib/fizzy_api_client/connection.rb', line 39

def post_multipart(path, fields: {}, files: {}, headers: {})
  request_multipart(:post, path, fields: fields, files: files, headers: headers)
end

#put(path, body: {}, headers: {}) ⇒ Object



17
18
19
# File 'lib/fizzy_api_client/connection.rb', line 17

def put(path, body: {}, headers: {})
  request(:put, path, body: body, headers: headers)
end

#put_multipart(path, fields: {}, files: {}, headers: {}) ⇒ Object



43
44
45
# File 'lib/fizzy_api_client/connection.rb', line 43

def put_multipart(path, fields: {}, files: {}, headers: {})
  request_multipart(:put, path, fields: fields, files: files, headers: headers)
end