Class: Xplenty::Kensa::PlanChangeCheck

Inherits:
ApiCheck show all
Includes:
HTTP
Defined in:
lib/xplenty/kensa/check.rb

Instance Attribute Summary

Attributes inherited from Check

#data, #screen

Instance Method Summary collapse

Methods included from HTTP

#delete, #get, #post, #put, #request

Methods inherited from ApiCheck

#base_path, #credentials, #xplenty_id

Methods inherited from Check

#call, #check, #env, #error, #initialize, #run, #test, #to_proc, #url

Constructor Details

This class inherits a constructor from Xplenty::Kensa::Check

Instance Method Details

#call!Object

Raises:

  • (ArgumentError)


374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/xplenty/kensa/check.rb', line 374

def call!
  id = data[:id]
  raise ArgumentError, "No id specified" if id.nil?

  new_plan = data[:plan]
  raise ArgumentError, "No plan specified" if new_plan.nil?

  path = "#{base_path}/#{CGI::escape(id.to_s)}"
  payload = {:plan => new_plan, :xplenty_id => xplenty_id}

  test "PUT #{path}"
  check "response" do
    code, _ = put(credentials, path, payload)
    if code == 200
      true
    elsif code == -1
      error("unable to connect to #{url}")
    else
      error("expected 200, got #{code}")
    end
  end

  check "authentication" do
    wrong_credentials = ['wrong', 'secret']
    code, _ = put(wrong_credentials, path, payload)
    error("expected 401, got #{code}") if code != 401
    true
  end
end