Module: PlentyClient::Request::ClassMethods
- Defined in:
- lib/plenty_client/request.rb
Instance Method Summary collapse
- #delete(path, body = {}) ⇒ Object
- #get(path, params = {}, &block) ⇒ Object
- #patch(path, body = {}) ⇒ Object
- #post(path, body = {}) ⇒ Object
- #put(path, body = {}) ⇒ Object
- #request(http_method, path, params = {}) ⇒ Object
Instance Method Details
#delete(path, body = {}) ⇒ Object
31 32 33 |
# File 'lib/plenty_client/request.rb', line 31 def delete(path, body = {}) request(:delete, path, body) end |
#get(path, params = {}, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/plenty_client/request.rb', line 35 def get(path, params = {}, &block) page = 1 rval_array = [] if block_given? loop do response = request(:get, path, params.merge(page: page)) yield response['entries'] if block_given? page += 1 break if response['isLastPage'] == true end else rval_array = request(:get, path, params.merge(page: page)) end return rval_array.flatten if rval_array.is_a?(Array) rval_array end |
#patch(path, body = {}) ⇒ Object
27 28 29 |
# File 'lib/plenty_client/request.rb', line 27 def patch(path, body = {}) request(:patch, path, body) end |
#post(path, body = {}) ⇒ Object
19 20 21 |
# File 'lib/plenty_client/request.rb', line 19 def post(path, body = {}) request(:post, path, body) end |
#put(path, body = {}) ⇒ Object
23 24 25 |
# File 'lib/plenty_client/request.rb', line 23 def put(path, body = {}) request(:put, path, body) end |
#request(http_method, path, params = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/plenty_client/request.rb', line 5 def request(http_method, path, params = {}) return false if http_method.nil? || path.nil? return false unless %w[post put patch delete get].include?(http_method.to_s) if PlentyClient::Config.access_token.nil? || time_diff_ms(Time.now, PlentyClient::Config.expiry_date).negative? login_check end start_time = Time.now response = perform(http_method, path, params) body = parse_body(response, http_method, path, params) log_output(http_method, base_url(path), params, time_diff_ms(start_time, Time.now)) if PlentyClient::Config.log body end |