Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
06d438a
feat: Add delay to plenty requests when plenty's Short-Period-Decay i…
owen2345 Jan 2, 2020
10e17d2
style: print log message when delaying
owen2345 Jan 3, 2020
3131e4d
Merge pull request #4 from ReverseRetail/op-throttle-check
owen2345 Jan 3, 2020
2fb777a
fix: remove false delay
owen2345 Jun 23, 2020
76e8ae5
Merge pull request #6 from ReverseRetail/hotfix/remove-false-delay
CharlieIGG Jun 23, 2020
afb6e2d
fix: fix typo when creating contact address
owen2345 Aug 4, 2020
7b09cea
Merge pull request #7 from ReverseRetail/hotfix/fix-typo-on-create-co…
owen2345 Aug 4, 2020
73df0d4
Fix typo
Dec 9, 2022
1cb9836
Merge pull request #8 from ReverseRetail/fix/typo_market_info
matiasalbarello Dec 9, 2022
bdf9720
feat: v2 endpoints for property group
notorious94 Mar 27, 2026
44640f1
added show, create, update & delete method for property group with do…
sahmed2024 Mar 31, 2026
1837ba9
added :group key in endpoint.rb for build_endpoint to support propert…
sahmed2024 Mar 31, 2026
545bc46
delete docs
sahmed2024 Apr 1, 2026
13fc07f
Merge pull request #11 from BuddyandSelly/istiad/feat/v2/property-groups
notorious94 Apr 1, 2026
0395c91
feat: prop group name endpoints
notorious94 Apr 2, 2026
05e73dc
addded v2 property endpoint for property group
sahmed2024 Apr 3, 2026
32905f8
added property v2 endpont in autoload
sahmed2024 Apr 3, 2026
f33d30d
feat: prop name endpoints
notorious94 Apr 5, 2026
cbbfbf8
Merge pull request #12 from BuddyandSelly/istiad/feat/plenty-v2-pg-name
notorious94 Apr 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Gemfile.lock
.git
.idea
tmp
pkg
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build
run: docker compose build

- name: Run specs
run: docker compose run console rspec
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ test/tmp
test/version_tmp
tmp
vendor/bundle
.idea/
docs/
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ruby:3.1

WORKDIR /gem

RUN gem install 'faraday:1.10.3' 'typhoeus:1.4.0' \
&& gem install json rspec webmock byebug

COPY . .

CMD ["irb", "-I", "lib", "-r", "plenty_client"]
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,46 @@ PlentyClient::Item::Variation.routes
- update all modules to classes and make it inherit from a base class to remove `extend PlentyClient::Request` etc
- create a configure block to set authentication parameters

## Testing with Docker

You can test the gem endpoints in an interactive Ruby console without installing it into a project.

### Prerequisites

- [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/)

### Usage

Build and start the console:

```bash
docker compose run console
```

This drops you into an IRB session with `plenty_client` pre-loaded. Configure your credentials and start testing:

```ruby
PlentyClient::Config.site_url = 'https://your-instance.plentymarkets.com'
PlentyClient::Config.api_user = 'your_user'
PlentyClient::Config.api_password = 'your_password'

# v1 example
PlentyClient::Item.list

# v2 example
PlentyClient::V2::Item::PropertyGroup.list(
'with' => 'names,options',
'orderBy' => 'position',
'itemsPerPage' => 25
)
```

To rebuild after making changes to the Dockerfile or gemspec:

```bash
docker compose build --no-cache
```

## Contributing

Bug reports and pull requests are welcome.
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
console:
build: .
stdin_open: true
tty: true
volumes:
- .:/gem
7 changes: 7 additions & 0 deletions lib/plenty_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,11 @@ module Location
autoload :Level, 'plenty_client/warehouse/location/level'
end
end

module V2
module Item
autoload :Property, 'plenty_client/v2/item/property'
autoload :PropertyGroup, 'plenty_client/v2/item/property_group'
end
end
end
5 changes: 3 additions & 2 deletions lib/plenty_client/account/contact/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def list(contact_id, address_type = '', headers = {}, &block)
headers, &block)
end

def create(body = {})
post("#{CONTACT_ADDRESS_BASE_PATH}#{CREATE_A_CONTACT_ADDRESS}", body)
def create(contact_id, body = {})
post(build_endpoint("#{CONTACT_ADDRESS_BASE_PATH}#{CREATE_A_CONTACT_ADDRESS}",
contact: contact_id), body)
end

def update(contact_id, address_id, body = {})
Expand Down
1 change: 1 addition & 0 deletions lib/plenty_client/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class InvalidCredentials < StandardError; end

class << self
attr_accessor :site_url, :api_user, :api_password, :access_token, :refresh_token, :log, :expiry_date, :plenty_id
attr_accessor :request_wait_until
attr_writer :attempt_count

def validate_credentials
Expand Down
1 change: 1 addition & 0 deletions lib/plenty_client/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def build_endpoint(api_endpoint_template, arguments = {})
directory: /\{directoryId\}/,
document: /\{documentId\}/,
fitment: /\{fitmentId\}/,
group: /\{groupId\}/,
image: /\{imageId\}/,
item: /\{itemId\}/,
item_set: /\{itemSetId\}/,
Expand Down
4 changes: 3 additions & 1 deletion lib/plenty_client/listing/market/info.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# frozen_string_literal: true

# PlentyClient::Listing::Market::Info.list
module PlentyClient
module Listing
module Market
class Info
include PlentyClient::Endpoint
include PlentyClient::Request

LIST_LISTINGS_MARKET_INFO = '/listings/markets/info'
# https://developers.plentymarkets.com/en-gb/plentymarkets-rest-api/index.html#/Listing/get_rest_listings_markets_infos
LIST_LISTINGS_MARKET_INFO = '/listings/markets/infos'

class << self
def list(headers = {}, &block)
Expand Down
17 changes: 16 additions & 1 deletion lib/plenty_client/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def request(http_method, path, params = {})

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

throttle_delay_request

perform(http_method, path, params)
end

Expand Down Expand Up @@ -84,6 +86,7 @@ def perform(http_method, path, params = {})
verb = http_method.to_s.downcase
params = params.to_json unless %w[get delete].include?(verb)
response = conn.send(verb, base_url(path), params)
throttle_check_short_period(response)
assert_success_status_code(response)
parse_body(response)
end
Expand Down Expand Up @@ -111,7 +114,19 @@ def throttle_check_short_period(response_header)
short_calls_left = response_header['X-Plenty-Global-Short-Period-Calls-Left']
short_seconds_left = response_header['X-Plenty-Global-Short-Period-Decay']
return if short_calls_left&.empty? || short_seconds_left&.empty?
sleep(short_seconds_left.to_i + 1) if short_calls_left.to_i <= 10 && short_seconds_left.to_i < 3
return if short_calls_left.to_i > 1

PlentyClient::Config.request_wait_until = Time.now + short_seconds_left.to_i
end

def throttle_delay_request
delay_time = PlentyClient::Config.request_wait_until
return unless delay_time
return if Time.now > delay_time

wait_until = (delay_time - Time.now)
STDOUT.write "Plenty client => delaying request: #{wait_until} seconds"
sleep(wait_until.round)
end

def parse_body(response)
Expand Down
42 changes: 42 additions & 0 deletions lib/plenty_client/v2/item/property.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

module PlentyClient
module V2
module Item
class Property
include PlentyClient::Endpoint
include PlentyClient::Request

autoload :Name, 'plenty_client/v2/item/property/name'

LIST_PROPERTIES = '/v2/properties'
GET_PROPERTY = '/v2/properties/{propertyId}'
CREATE_PROPERTY = '/v2/properties'
UPDATE_PROPERTY = '/v2/properties/{propertyId}'
DELETE_PROPERTY = '/v2/properties/{propertyId}'

class << self
def list(params = {}, &block)
get(build_endpoint(LIST_PROPERTIES), params, &block)
end

def find(property_id, params = {}, &block)
get(build_endpoint(GET_PROPERTY, property: property_id), params, &block)
end

def create(body = {})
post(build_endpoint(CREATE_PROPERTY), body)
end

def update(property_id, body = {})
put(build_endpoint(UPDATE_PROPERTY, property: property_id), body)
end

def destroy(property_id)
delete(build_endpoint(DELETE_PROPERTY, property: property_id))
end
end
end
end
end
end
37 changes: 37 additions & 0 deletions lib/plenty_client/v2/item/property/name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module PlentyClient
module V2
module Item
class Property
class Name
include PlentyClient::Endpoint
include PlentyClient::Request

CREATE_PROPERTY_NAME = '/v2/properties/names'
GET_PROPERTY_NAME = '/v2/properties/names/{nameId}'
UPDATE_PROPERTY_NAME = '/v2/properties/names/{nameId}'
DELETE_PROPERTY_NAME = '/v2/properties/names/{nameId}'

class << self
def find(name_id, params = {}, &block)
get(build_endpoint(GET_PROPERTY_NAME, name: name_id), params, &block)
end

def create(body = {})
post(build_endpoint(CREATE_PROPERTY_NAME), body)
end

def update(name_id, body = {})
put(build_endpoint(UPDATE_PROPERTY_NAME, name: name_id), body)
end

def destroy(name_id)
delete(build_endpoint(DELETE_PROPERTY_NAME, name: name_id))
end
end
end
end
end
end
end
42 changes: 42 additions & 0 deletions lib/plenty_client/v2/item/property_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

module PlentyClient
module V2
module Item
class PropertyGroup
include PlentyClient::Endpoint
include PlentyClient::Request

autoload :Name, 'plenty_client/v2/item/property_group/name'

LIST_PROPERTY_GROUPS = '/v2/properties/groups'
GET_PROPERTY_GROUP = '/v2/properties/groups/{groupId}'
CREATE_PROPERTY_GROUP = '/v2/properties/groups'
UPDATE_PROPERTY_GROUP = '/v2/properties/groups/{groupId}'
DELETE_PROPERTY_GROUP = '/v2/properties/groups/{groupId}'

class << self
def list(params = {}, &block)
get(build_endpoint(LIST_PROPERTY_GROUPS), params, &block)
end

def find(group_id, params = {}, &block)
get(build_endpoint(GET_PROPERTY_GROUP, group: group_id), params, &block)
end

def create(body = {})
post(build_endpoint(CREATE_PROPERTY_GROUP), body)
end

def update(group_id, body = {})
put(build_endpoint(UPDATE_PROPERTY_GROUP, group: group_id), body)
end

def destroy(group_id)
delete(build_endpoint(DELETE_PROPERTY_GROUP, group: group_id))
end
end
end
end
end
end
37 changes: 37 additions & 0 deletions lib/plenty_client/v2/item/property_group/name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module PlentyClient
module V2
module Item
class PropertyGroup
class Name
include PlentyClient::Endpoint
include PlentyClient::Request

CREATE_PROPERTY_GROUP_NAME = '/v2/properties/groups/names'
GET_PROPERTY_GROUP_NAME = '/v2/properties/groups/names/{nameId}'
UPDATE_PROPERTY_GROUP_NAME = '/v2/properties/groups/names/{nameId}'
DELETE_PROPERTY_GROUP_NAME = '/v2/properties/groups/names/{nameId}'

class << self
def find(name_id, params = {}, &block)
get(build_endpoint(GET_PROPERTY_GROUP_NAME, name: name_id), params, &block)
end

def create(body = {})
post(build_endpoint(CREATE_PROPERTY_GROUP_NAME), body)
end

def update(name_id, body = {})
put(build_endpoint(UPDATE_PROPERTY_GROUP_NAME, name: name_id), body)
end

def destroy(name_id)
delete(build_endpoint(DELETE_PROPERTY_GROUP_NAME, name: name_id))
end
end
end
end
end
end
end
Loading