Module: PlentyClient::Request::ClassMethods

Defined in:
lib/plenty_client/request.rb

Instance Method Summary collapse

Instance Method Details

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



32
33
34
# File 'lib/plenty_client/request.rb', line 32

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

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/plenty_client/request.rb', line 36

def get(path, params = {})
  page = 1
  rval_array = []
  if block_given?
    loop do
      response = request(:get, path, params.merge('page' => page))
      yield response['entries']
      break if response['isLastPage'] == true
      page += 1
    end
  else
    rval_array = request(:get, path, { 'page' => page }.merge(params))
  end
  return rval_array.flatten if rval_array.is_a?(Array)
  rval_array
end

#patch(path, body = {}) ⇒ Object



28
29
30
# File 'lib/plenty_client/request.rb', line 28

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

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



20
21
22
# File 'lib/plenty_client/request.rb', line 20

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

#put(path, body = {}) ⇒ Object



24
25
26
# File 'lib/plenty_client/request.rb', line 24

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

#request(http_method, path, params = {}) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/plenty_client/request.rb', line 7

def request(http_method, path, params = {})
  raise ArgumentError, "http_method or path is missing" if http_method.nil? || path.nil?
  unless %w[post put patch delete get].include?(http_method.to_s)
    raise ArgumentError, "unsupported http_method: #{http_method}"
  end

   unless PlentyClient::Config.tokens_valid?

  params = stringify_symbol_keys(params) if params.is_a?(Hash)

  perform(http_method, path, params)
end