ruby-brightpearl 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdb848704f153ae9ba26d219cf41f6fb2837e47e7aacb4c7f2780d4abfa7e6ce
4
- data.tar.gz: 693496443c266b56693804e2909672306298035e7caf3d266d2b5fa808d446dc
3
+ metadata.gz: d50d3172ec36f06ca6b5ac76a9fc5f69b578df384db02b467d4c57502ede7dae
4
+ data.tar.gz: 89d67376fd2e4a6c5e007c2c6300cd657e2115b202b4f67403c1364921cdf6f0
5
5
  SHA512:
6
- metadata.gz: a8ec1a268a3bc9cc761d7f72f04e7f3130e3edbda988e369945d3fd4c8c7fcd96d22e8c59bed0d9329805bb9c3fe9dc517d8ef2a791bc1fc493eb52bf87714a6
7
- data.tar.gz: 45a15dfbb0f95446c6cbb0625c0ea6998a7786e2e5f39ea917689df2e67e17f05f089aa4b6d29d06a05c4f753f3ae394cb5620f9c0c8d1aff5a2ff0542b8f8a1
6
+ metadata.gz: 7789dbc2a64efb929655e07def14a753246baf3ade6b7b6d3ed750da89b77abe9568ba1974634f7f22f98db54de6f379787c14d5901eddca571c0ced4ce56eb0
7
+ data.tar.gz: d259a5ead61c86d653f866bc150d5a604db202bd907b71530965d3cc27030d50e33f2fb122c0f591a971c515f07bc10c00855b1824535f0b6e9c4e0b525394a0
data/CHANGELOG.md CHANGED
@@ -1,16 +1,39 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.5.0]
3
+ ## [0.7.0] - 2025-11-03
4
+
5
+ ### Added
6
+
7
+ - New API Operation `DELETE`
8
+ - **New resource `Webhook`**
9
+ - Available operations: `GET`, `POST`, `DELETE`
10
+
11
+ ### Changed
12
+ - Improved `Brightpearl::RequestError` message to include error code when available
13
+ - For example, `CMNC-404 - Resource not found` instead of just `Resource not found`
14
+
15
+ ## [0.6.0] - 2025-08-28
16
+
17
+ - New resource `Customer`
18
+ - New resource `CustomerCustomField`
19
+ - Minor fixes on development libs
20
+
21
+ ## [0.5.0] - 2025-03-27
22
+
4
23
  - Add new resource OrderCustomField
5
24
  - Improve test environment to use different bp credentials without breaking the cassettes
6
25
 
7
26
  ## [0.3.0] - 2022-02-03
27
+
8
28
  - New resource TaxCode
9
29
  - Fix minor typos
10
30
  - New optional config `debug_mode`
31
+
11
32
  ## [0.3.0] - 2022-02-03
12
33
  - New resource ProductAvailability
34
+
13
35
  ## [0.2.0] - 2022-02-02
36
+
14
37
  - Add refresh token mechanic with method `use_refresh_token`
15
38
  - Change config values
16
39
  - Add refresh_token to allow automatic update of tokens when calling the new method `use_refresh_token`
data/Gemfile CHANGED
@@ -3,8 +3,4 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in ruby-brightpearl.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rspec", "~> 3.0"
6
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-brightpearl (0.5.0)
4
+ ruby-brightpearl (0.7.0)
5
5
  httparty (~> 0.20)
6
6
 
7
7
  GEM
@@ -9,20 +9,27 @@ GEM
9
9
  specs:
10
10
  addressable (2.8.0)
11
11
  public_suffix (>= 2.0.2, < 5.0)
12
- bigdecimal (3.1.9)
12
+ base64 (0.3.0)
13
+ bigdecimal (3.3.1)
13
14
  byebug (11.1.3)
15
+ coderay (1.1.3)
14
16
  crack (0.4.5)
15
17
  rexml
16
- csv (3.3.3)
18
+ csv (3.3.5)
17
19
  diff-lcs (1.5.0)
20
+ dotenv (3.1.8)
18
21
  hashdiff (1.0.1)
19
- httparty (0.23.0)
22
+ httparty (0.23.2)
20
23
  csv
21
24
  mini_mime (>= 1.0.0)
22
25
  multi_xml (>= 0.5.2)
26
+ method_source (1.1.0)
23
27
  mini_mime (1.1.5)
24
- multi_xml (0.7.1)
28
+ multi_xml (0.7.2)
25
29
  bigdecimal (~> 3.1)
30
+ pry (0.15.2)
31
+ coderay (~> 1.1)
32
+ method_source (~> 1.0)
26
33
  public_suffix (4.0.6)
27
34
  rake (13.0.6)
28
35
  rexml (3.2.5)
@@ -39,7 +46,8 @@ GEM
39
46
  diff-lcs (>= 1.2.0, < 2.0)
40
47
  rspec-support (~> 3.10.0)
41
48
  rspec-support (3.10.3)
42
- vcr (6.0.0)
49
+ vcr (6.3.1)
50
+ base64
43
51
  webmock (3.14.0)
44
52
  addressable (>= 2.8.0)
45
53
  crack (>= 0.3.2)
@@ -50,10 +58,12 @@ PLATFORMS
50
58
 
51
59
  DEPENDENCIES
52
60
  byebug
61
+ dotenv
62
+ pry
53
63
  rake (~> 13.0)
54
64
  rspec (~> 3.0)
55
65
  ruby-brightpearl!
56
- vcr (~> 6.0)
66
+ vcr (~> 6.3.1)
57
67
  webmock
58
68
 
59
69
  BUNDLED WITH
@@ -0,0 +1,9 @@
1
+ module Brightpearl
2
+ module APIOperations
3
+ module Delete
4
+ def delete(id)
5
+ send_request(path: "#{resource_path}/#{id}", method: :delete)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -2,4 +2,5 @@ require 'brightpearl/api_operations/get'
2
2
  require 'brightpearl/api_operations/post'
3
3
  require 'brightpearl/api_operations/patch'
4
4
  require 'brightpearl/api_operations/put'
5
- require 'brightpearl/api_operations/options'
5
+ require 'brightpearl/api_operations/options'
6
+ require 'brightpearl/api_operations/delete'
@@ -54,6 +54,7 @@ module Brightpearl
54
54
  elsif response.code == 401
55
55
  raise Brightpearl::InvalidToken.new(json["response"], response: json, status: 401)
56
56
  elsif !!json["errors"]
57
+ # Request Error is the fallback message. If response has a tangible error message, first one will be used from response json
57
58
  raise Brightpearl::RequestError.new("Request Error", response: json, status: response.code)
58
59
  end
59
60
 
@@ -3,9 +3,11 @@ module Brightpearl
3
3
  attr_reader :response, :code, :status
4
4
  def initialize(msg, response: nil, status: nil)
5
5
  if response["errors"] && response["errors"].size == 1 # If error is easily identifiable then set it as the Error message
6
- error = response["errors"][0]["message"]
6
+ error_message = response["errors"][0]["message"]
7
7
  @code = response["errors"][0]["code"]
8
- super(error)
8
+
9
+ error_message = "#{@code} - #{error_message}" if @code
10
+ super(error_message)
9
11
  else
10
12
  super(msg)
11
13
  end
@@ -0,0 +1,60 @@
1
+ module Brightpearl
2
+ # https://api-docs.brightpearl.com/contact/contact/index.html
3
+ class Customer < Resource
4
+ extend Brightpearl::APIOperations::Get
5
+ extend Brightpearl::APIOperations::Post
6
+ extend Brightpearl::APIOperations::Patch
7
+ extend Brightpearl::APIOperations::Options
8
+
9
+ attr_accessor :id, :primary_email, :secondary_email, :tertiary_email,
10
+ :first_name, :last_name, :is_supplier, :company_name,
11
+ :is_staff, :is_customer, :created_on, :updated_on, :last_contacted_on,
12
+ :last_ordered_on, :nominal_code, :is_primary, :pri, :sec,
13
+ :mob, :exact_company_name, :title
14
+
15
+ class << self
16
+ def resource_path
17
+ "contact-service/contact"
18
+ end
19
+
20
+ # https://api-docs.brightpearl.com/contact/contact/get.html
21
+ # https://api-docs.brightpearl.com/contact/contact/post.html
22
+ # https://api-docs.brightpearl.com/contact/contact/patch.html
23
+ # https://api-docs.brightpearl.com/contact/contact/options.html
24
+
25
+ # https://api-docs.brightpearl.com/contact/contact/search.html
26
+ def search(query_params = {})
27
+ response = send_request(path: "contact-service/contact-search?#{to_query(query_params)}", method: :get)
28
+ return response.merge({ # modify final payload to set search results as objects
29
+ records: response[:payload]["response"]["results"].map { |item| Customer.new(item) },
30
+ })
31
+ end
32
+ end
33
+
34
+ # ARA => API Record Array
35
+ def initialize(ara)
36
+ @id = ara[0]
37
+ @primary_email = ara[1]
38
+ @secondary_email = ara[2]
39
+ @tertiary_email = ara[3]
40
+ @first_name = ara[4]
41
+ @last_name = ara[5]
42
+ @is_supplier = ara[6]
43
+ @company_name = ara[7]
44
+ @is_staff = ara[8]
45
+ @is_customer = ara[9]
46
+ @created_on = ara[10]
47
+ @updated_on = ara[11]
48
+ @last_contacted_on = ara[12]
49
+ @last_ordered_on = ara[13]
50
+ @nominal_code = ara[14]
51
+ @is_primary = ara[15]
52
+ @pri = ara[16]
53
+ @sec = ara[17]
54
+ @mob = ara[18]
55
+ @exact_company_name = ara[19]
56
+ @title = ara[20]
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,18 @@
1
+ module Brightpearl
2
+ # Contact custom fields are the user-defined data held against Brightpearl contacts. Several data types are available. Custom fields are separated between Supplier contacts and Customer contacts, and may only be assigned to one of these groups.
3
+ # https://api-docs.brightpearl.com/contact/custom-field/index.html
4
+ class CustomerCustomField < Resource
5
+ class << self
6
+ # https://api-docs.brightpearl.com/contact/custom-field/get.html
7
+ def get(contact_id)
8
+ send_request(path: "contact-service/contact/#{contact_id}/custom-field", method: :get)
9
+ end
10
+
11
+ # https://api-docs.brightpearl.com/contact/custom-field/patch.html
12
+ def patch(contact_id, params)
13
+ send_request(path: "contact-service/contact/#{contact_id}/custom-field", method: :patch, body: params)
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -60,7 +60,7 @@ module Brightpearl
60
60
  @order_shipping_status_id = nil
61
61
  @external_ref = ara["reference"]
62
62
  @installed_integration_instance_id = nil
63
- @warehouse_id = ara["warehousrId"]
63
+ @warehouse_id = ara["warehouseId"]
64
64
  @staff_owner_contact_id = ara["assignment"]["current"]["staffOwnerContactId"]
65
65
  @tax_date = ara["invoices"][0] && ara["invoices"][0]["taxDate"]
66
66
  @department_id = nil
@@ -0,0 +1,19 @@
1
+ module Brightpearl
2
+ # Webhooks are used to define a 'callback contract' between Brightpearl and some third-party system. They specify the circumstances under which Brightpearl should send an HTTP message to the third-party system and the format of that message.
3
+ #
4
+ # They are typically used to notify a remote server supporting some integration of a change in the state of a resource in a customer's Brightpearl account. For example, a carrier integration will want to know when Goods-Out Notes are picked or packed.
5
+ #
6
+ # Please read Brightpearl webhooks for more information on how and when to use webhooks.
7
+ # https://api-docs.brightpearl.com/integration/webhook/index.html
8
+ class Webhook < Resource
9
+ extend Brightpearl::APIOperations::Get # /integration-service/webhook/{ID-SET}
10
+ extend Brightpearl::APIOperations::Post # /integration-service/webhook
11
+ extend Brightpearl::APIOperations::Delete # /integration-service/webhook/{ID}
12
+
13
+ class << self
14
+ def resource_path
15
+ "integration-service/webhook"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,13 +1,22 @@
1
1
  require 'brightpearl/resource'
2
+
3
+ require 'brightpearl/resources/customer'
4
+ require 'brightpearl/resources/customer_custom_field'
5
+
2
6
  require 'brightpearl/resources/order'
3
7
  require 'brightpearl/resources/order_row'
4
8
  require 'brightpearl/resources/order_shipping_status'
5
9
  require 'brightpearl/resources/order_status'
6
10
  require 'brightpearl/resources/order_status_update'
7
11
  require 'brightpearl/resources/order_custom_field'
12
+
8
13
  require 'brightpearl/resources/product'
9
14
  require 'brightpearl/resources/product_price'
10
15
  require 'brightpearl/resources/price_list'
11
16
  require 'brightpearl/resources/product_availability'
17
+
18
+ # Integration
19
+ require 'brightpearl/resources/webhook'
20
+
12
21
  # Accounting
13
22
  require 'brightpearl/resources/tax_code'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Brightpearl
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/playground.rb CHANGED
@@ -1,14 +1,18 @@
1
1
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
2
2
 
3
3
  require 'pry'
4
+ require 'dotenv'
5
+ require 'json'
4
6
  require_relative './lib/brightpearl.rb'
5
7
 
8
+ Dotenv.load('.env')
9
+
6
10
  Brightpearl.config.api_domain = ENV["RUBY_BRIGHTPEARL_ENDPOINT"]
7
11
  Brightpearl.config.app_ref = ENV["RUBY_BRIGHTPEARL_APP_REF"]
8
12
  Brightpearl.config.dev_ref = ENV["RUBY_BRIGHTPEARL_DEV_REF"]
9
13
  Brightpearl.config.account = ENV["RUBY_BRIGHTPEARL_ACCOUNT"]
10
14
  Brightpearl.config.token = ENV["RUBY_BRIGHTPEARL_TOKEN"] # It expires
11
15
 
12
- puts "hello"
16
+ puts "The following request should work without issues if the token is valid"
13
17
 
14
18
  puts Brightpearl::Order.get(1)
@@ -31,13 +31,17 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
33
 
34
- # Uncomment to register a new dependency of your gem
34
+ # Runtime dependencies - what users need to use your gem
35
35
  spec.add_dependency 'httparty', '~> 0.20'
36
- # spec.add_dependency "example-gem", "~> 1.0"
37
36
 
38
- spec.add_development_dependency("vcr", "~> 6.0")
37
+ # Development dependencies - what developers need to work on the gem
38
+ spec.add_development_dependency("vcr", "~> 6.3.1")
39
39
  spec.add_development_dependency("webmock")
40
40
  spec.add_development_dependency("byebug")
41
+ spec.add_development_dependency("rspec", "~> 3.0")
42
+ spec.add_development_dependency("rake", "~> 13.0")
43
+ spec.add_development_dependency("dotenv")
44
+ spec.add_development_dependency("pry")
41
45
 
42
46
  # For more information and examples about making a new gem, check out our
43
47
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-brightpearl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vicvans20
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-03-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: httparty
@@ -30,14 +29,14 @@ dependencies:
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '6.0'
32
+ version: 6.3.1
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '6.0'
39
+ version: 6.3.1
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: webmock
43
42
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +65,62 @@ dependencies:
66
65
  - - ">="
67
66
  - !ruby/object:Gem::Version
68
67
  version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rake
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '13.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '13.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: dotenv
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
69
124
  description: Simple Ruby client to interact with brightpearl API.
70
125
  email:
71
126
  - vicvans20@gmail.com
@@ -85,6 +140,7 @@ files:
85
140
  - bin/setup
86
141
  - lib/brightpearl.rb
87
142
  - lib/brightpearl/api_operations.rb
143
+ - lib/brightpearl/api_operations/delete.rb
88
144
  - lib/brightpearl/api_operations/get.rb
89
145
  - lib/brightpearl/api_operations/options.rb
90
146
  - lib/brightpearl/api_operations/patch.rb
@@ -96,6 +152,8 @@ files:
96
152
  - lib/brightpearl/errors.rb
97
153
  - lib/brightpearl/resource.rb
98
154
  - lib/brightpearl/resources.rb
155
+ - lib/brightpearl/resources/customer.rb
156
+ - lib/brightpearl/resources/customer_custom_field.rb
99
157
  - lib/brightpearl/resources/order.rb
100
158
  - lib/brightpearl/resources/order_custom_field.rb
101
159
  - lib/brightpearl/resources/order_row.rb
@@ -107,6 +165,7 @@ files:
107
165
  - lib/brightpearl/resources/product_availability.rb
108
166
  - lib/brightpearl/resources/product_price.rb
109
167
  - lib/brightpearl/resources/tax_code.rb
168
+ - lib/brightpearl/resources/webhook.rb
110
169
  - lib/brightpearl/version.rb
111
170
  - playground.rb
112
171
  - ruby-brightpearl.gemspec
@@ -119,7 +178,6 @@ metadata:
119
178
  homepage_uri: https://github.com/vicvans20/ruby-brightpearl
120
179
  source_code_uri: https://github.com/vicvans20/ruby-brightpearl
121
180
  changelog_uri: https://github.com/vicvans20/ruby-brightpearl/blob/master/CHANGELOG.md
122
- post_install_message:
123
181
  rdoc_options: []
124
182
  require_paths:
125
183
  - lib
@@ -134,8 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
192
  - !ruby/object:Gem::Version
135
193
  version: '0'
136
194
  requirements: []
137
- rubygems_version: 3.5.3
138
- signing_key:
195
+ rubygems_version: 3.6.9
139
196
  specification_version: 4
140
197
  summary: Brightpearl API ruby client.
141
198
  test_files: []