Module: PlentyClient::Request
- Included in:
- Accounting, Authentication, Authorization, Basket, Basket::Item, Category, Category::Branch, Category::Template, Comment, Item, Item::Attribute, Item::Barcode, Item::CrossSelling, Item::Image, Item::Manufacturer, Item::Manufacturer::Commission, Item::Property, Item::PropertyGroup, Item::PropertyGroupName, Item::SalesPrice, Item::ShippingProfile, Item::Unit, Item::UnitName, Item::Variation, Item::Variation::Barcode, Item::Variation::Bundle, Item::Variation::Category, Item::Variation::Client, Item::Variation::DefaultCategory, Item::Variation::Description, Item::Variation::Image, Item::Variation::Market, Item::Variation::MarketIdentNumber, Item::Variation::Sku, Item::Variation::Stock, Item::Variation::Supplier, Item::Variation::Warehouse, Item::VariationProperty, ItemSet, ItemSet::Config, Order, Order::ContactWish, Order::CouponCode, Order::CouponCode::Contact, Order::CouponCode::Validation, Order::Currency, Order::Date, Order::Item, Order::Item::Date, Order::Item::Property, Order::Item::SerialNumber, Order::Property, Order::Referrer, Order::Shipping, Order::Shipping::Country, Order::Shipping::Information, Order::Shipping::Package, Order::Shipping::Profile, Order::Shipping::ServiceProvider, SalesPrice::Account, SalesPrice::Country, SalesPrice::Currency, SalesPrice::CustomerClass, SalesPrice::Name, SalesPrice::OnlineStore
- 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
28 29 30 |
# File 'lib/plenty_client/request.rb', line 28 def delete(path, body = {}) request(:delete, path, body) end |
#get(path, params = {}, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/plenty_client/request.rb', line 32 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 rval_array.flatten end |
#patch(path, body = {}) ⇒ Object
24 25 26 |
# File 'lib/plenty_client/request.rb', line 24 def patch(path, body = {}) request(:patch, path, body) end |
#post(path, body = {}) ⇒ Object
16 17 18 |
# File 'lib/plenty_client/request.rb', line 16 def post(path, body = {}) request(:post, path, body) end |
#put(path, body = {}) ⇒ Object
20 21 22 |
# File 'lib/plenty_client/request.rb', line 20 def put(path, body = {}) request(:put, path, body) end |
#request(http_method, path, params = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/plenty_client/request.rb', line 4 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) login if PlentyClient::Config.access_token.nil? 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 |