mergent 0.1.0 → 0.2.1

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: 991390648edd146ed10b823a1a47c2c7af7b480cdbf89600018f74d1430f878b
4
- data.tar.gz: cc42af168a1dc2ea25622a24b200cee773cb8ebe54197215bf3e5bbe30b4fff1
3
+ metadata.gz: 11e9b11314fa0fe8f575245b4e412d1cfdad25a6ed3d8ed9c752e70e0dce3f8a
4
+ data.tar.gz: 131a29cc73047bf2eb06850c820d5e4c152510613286826fbfeb9ac96d2c9b72
5
5
  SHA512:
6
- metadata.gz: c12851c47f643729e3f8f2d1a90266bbf71a636ca76c2b51f633886efe62c71f9c0492968842230846f8e78d59877233a17f5c9fad8e461590a9528ab05c4eaa
7
- data.tar.gz: 91179f7fbb9a5cfda2e28e1d87641d98e28b17dac8df398a32a89d18ce354f164adb5848120459479db3157e0d83d0e23340eeebe87d4f5dd6700ec41ffee632
6
+ metadata.gz: fb4fd8c6f5ed38a308d98916a7f7c530d6e88ba15e3c30b2e7094bea68f3b68ca942735c1a082afd3185078a7f9c9dbfb516c4ea6474045d4eecdc2f0a53fff3
7
+ data.tar.gz: 3cf6df4e8e643fa9517052be9b1f047c1427a76d07df1ade6d3d594daaa344b79891e5de97e9a79453e9ab1b247505b6d645cd011dc110aa2bc6a84b30b0929b
data/.rubocop.yml CHANGED
@@ -22,9 +22,6 @@ RSpec/MultipleExpectations:
22
22
  Style/Documentation:
23
23
  Enabled: false
24
24
 
25
- Style/FrozenStringLiteralComment:
26
- Enabled: false
27
-
28
25
  Style/StringLiterals:
29
26
  EnforcedStyle: double_quotes
30
27
 
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.0.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.1] - 2022-01-20
4
+
5
+ - Add `Mergent::RequestValidator` to validate that webhooks came from Mergent's API
6
+
7
+ ## [0.2.0] - 2022-01-20
8
+
9
+ - Add `Mergent::RequestValidator` to validate that webhooks came from Mergent's API
10
+
11
+ ## [0.1.2] - 2022-1-13
12
+
13
+ - Define explicit methods in `Mergent::Task`, to allow for use of verifying doubles when testing against them.
14
+ - Remove deprecated `cron` method definition
15
+
16
+ ## [0.1.1] - 2021-12-21
17
+
18
+ - Define explicit methods in `Mergent::Task`, to allow for use of verifying doubles when testing against them.
19
+ - Update summary and description for RubyGems.org
20
+
3
21
  ## [0.1.0] - 2021-11-21
4
22
 
5
23
  - Initial release
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mergent (0.1.0)
4
+ mergent (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -11,15 +11,15 @@ GEM
11
11
  ast (2.4.2)
12
12
  crack (0.4.5)
13
13
  rexml
14
- diff-lcs (1.4.4)
14
+ diff-lcs (1.5.0)
15
15
  hashdiff (1.0.1)
16
16
  parallel (1.21.0)
17
- parser (3.0.2.0)
17
+ parser (3.1.0.0)
18
18
  ast (~> 2.4.1)
19
19
  public_suffix (4.0.6)
20
- rainbow (3.0.0)
20
+ rainbow (3.1.1)
21
21
  rake (13.0.6)
22
- regexp_parser (2.1.1)
22
+ regexp_parser (2.2.0)
23
23
  rexml (3.2.5)
24
24
  rspec (3.10.0)
25
25
  rspec-core (~> 3.10.0)
@@ -27,30 +27,30 @@ GEM
27
27
  rspec-mocks (~> 3.10.0)
28
28
  rspec-core (3.10.1)
29
29
  rspec-support (~> 3.10.0)
30
- rspec-expectations (3.10.1)
30
+ rspec-expectations (3.10.2)
31
31
  diff-lcs (>= 1.2.0, < 2.0)
32
32
  rspec-support (~> 3.10.0)
33
33
  rspec-mocks (3.10.2)
34
34
  diff-lcs (>= 1.2.0, < 2.0)
35
35
  rspec-support (~> 3.10.0)
36
- rspec-support (3.10.2)
37
- rubocop (1.22.3)
36
+ rspec-support (3.10.3)
37
+ rubocop (1.24.1)
38
38
  parallel (~> 1.10)
39
39
  parser (>= 3.0.0.0)
40
40
  rainbow (>= 2.2.2, < 4.0)
41
41
  regexp_parser (>= 1.8, < 3.0)
42
42
  rexml
43
- rubocop-ast (>= 1.12.0, < 2.0)
43
+ rubocop-ast (>= 1.15.1, < 2.0)
44
44
  ruby-progressbar (~> 1.7)
45
45
  unicode-display_width (>= 1.4.0, < 3.0)
46
- rubocop-ast (1.12.0)
46
+ rubocop-ast (1.15.1)
47
47
  parser (>= 3.0.1.1)
48
- rubocop-performance (1.12.0)
48
+ rubocop-performance (1.13.2)
49
49
  rubocop (>= 1.7.0, < 2.0)
50
50
  rubocop-ast (>= 0.4.0)
51
51
  rubocop-rake (0.6.0)
52
52
  rubocop (~> 1.0)
53
- rubocop-rspec (2.5.0)
53
+ rubocop-rspec (2.7.0)
54
54
  rubocop (~> 1.19)
55
55
  ruby-progressbar (1.11.0)
56
56
  unicode-display_width (2.1.0)
@@ -73,4 +73,4 @@ DEPENDENCIES
73
73
  webmock
74
74
 
75
75
  BUNDLED WITH
76
- 2.2.31
76
+ 2.3.4
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # Mergent
1
+ # Mergent Ruby Library
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/mergent.svg)](https://badge.fury.io/rb/mergent)
4
+ [![CI](https://github.com/mergentlabs/mergent-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/mergentlabs/mergent-ruby/actions/workflows/ci.yml)
2
5
 
3
6
  The Mergent Ruby library provides convenient access to the Mergent API from
4
7
  applications written in the Ruby language.
@@ -44,10 +47,11 @@ After checking out the repo, run `bundle` to install dependencies. Then, run
44
47
  `rake spec` to run the tests.
45
48
 
46
49
  To install this gem onto your local machine, run `bundle exec rake install`.
47
- To release a new version, update the version number in `version.rb`, and then
48
- run `bundle exec rake release`, which will create a git tag for the version,
49
- push git commits and the created tag, and push the `.gem` file to
50
- [rubygems.org](https://rubygems.org).
50
+
51
+ To release a new version, update the changelog, bump the version number in
52
+ `version.rb`, commit that change, and then run `bundle exec rake release`, which
53
+ will create a git tag for the version, push git commits and the created tag, and
54
+ push the `.gem` file to [rubygems.org](https://rubygems.org).
51
55
 
52
56
  ## Contributing
53
57
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "net/http"
2
4
  require "json"
3
5
 
4
6
  module Mergent
5
7
  class Client
6
8
  def self.post(resource, params) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
7
- uri = URI("https://api.mergent.co/v1/#{resource}")
9
+ uri = URI("#{Mergent.endpoint}/#{resource}")
8
10
  headers = {
9
11
  Authorization: "Bearer #{Mergent.api_key}",
10
12
  "Content-Type": "application/json"
@@ -13,22 +15,32 @@ module Mergent
13
15
  request.body = params.to_json
14
16
 
15
17
  https = Net::HTTP.new(uri.host, uri.port)
16
- https.use_ssl = true
18
+ https.use_ssl = Mergent.endpoint.start_with?("https")
17
19
  response = https.request(request)
18
20
 
19
21
  case response
20
22
  when Net::HTTPSuccess
21
- JSON.parse(response.read_body, object_class: Mergent::Object)
23
+ JSON.parse(response.read_body)
22
24
  else
23
25
  begin
24
26
  body = JSON.parse(response.read_body)
25
27
  rescue JSON::ParserError
26
28
  body = {}
27
29
  end
28
- raise Mergent::Error, body["message"]
30
+ raise Mergent::Error, error_message(body)
29
31
  end
30
32
  rescue EOFError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, SocketError
31
33
  raise Mergent::ConnectionError
32
34
  end
35
+
36
+ private
37
+
38
+ def self.error_message(body)
39
+ breakdown = body.fetch("errors", []).map { |error| error.fetch("message", nil) }.compact.join(", ")
40
+ msg = body["message"]
41
+ msg << " - #{breakdown}" unless breakdown.empty?
42
+ msg
43
+ end
44
+ private_class_method :error_message
33
45
  end
34
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mergent
2
4
  class Error < StandardError; end
3
5
 
@@ -1,3 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mergent
2
- class Object < OpenStruct; end
4
+ class Object
5
+ attr_reader :_data
6
+
7
+ def initialize(data = {})
8
+ @_data = data.transform_keys(&:to_sym)
9
+ end
10
+ end
3
11
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mergent
4
+ class RequestValidator
5
+ def initialize(api_key)
6
+ @api_key = api_key || Mergent.api_key
7
+ end
8
+
9
+ def build_signature_for(body)
10
+ digest = OpenSSL::Digest.new("sha1")
11
+ Base64.strict_encode64(OpenSSL::HMAC.digest(digest, @api_key, body || ""))
12
+ end
13
+
14
+ def valid_signature?(body, signature)
15
+ build_signature_for(body) == signature
16
+ end
17
+ end
18
+ end
data/lib/mergent/task.rb CHANGED
@@ -1,11 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "client"
2
4
  require_relative "object"
3
5
 
4
6
  module Mergent
5
7
  class Task < Mergent::Object
8
+ ATTRS = %i[name description status request scheduled_for created_at].freeze
9
+
10
+ ATTRS.each do |name|
11
+ define_method(name) do
12
+ @_data[name]
13
+ end
14
+ end
15
+
6
16
  def self.create(params = {})
7
- object = Client.post("tasks", params)
8
- new(object)
17
+ data = Client.post("tasks", params)
18
+ new(data)
9
19
  end
10
20
  end
11
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mergent
2
- VERSION = "0.1.0".freeze
4
+ VERSION = "0.2.1"
3
5
  end
data/lib/mergent.rb CHANGED
@@ -1,9 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "mergent/errors"
4
+ require_relative "mergent/request_validator"
2
5
  require_relative "mergent/task"
3
6
  require_relative "mergent/version"
4
7
 
5
8
  module Mergent
9
+ ENDPOINT = "https://api.mergent.co/v1"
10
+
6
11
  class << self
7
- attr_accessor :api_key
12
+ attr_accessor :api_key, :endpoint
8
13
  end
9
14
  end
15
+
16
+ Mergent.endpoint = Mergent::ENDPOINT
data/mergent.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "lib/mergent/version"
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -6,15 +8,16 @@ Gem::Specification.new do |spec|
6
8
  spec.author = "Mergent"
7
9
  spec.email = "support@mergent.co"
8
10
 
9
- spec.summary = "Ruby bindings for the Mergent API"
10
- spec.description = "See https://mergent.co for details."
11
+ spec.summary = "Ruby library for the Mergent API."
12
+ spec.description = "Ruby library for the Mergent API. See https://mergent.co for details."
11
13
  spec.homepage = "https://mergent.co"
12
14
  spec.license = "MIT"
13
15
  spec.required_ruby_version = ">= 2.6.0"
14
16
 
15
17
  spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = "https://github.com/jamescmartinez/mergent-ruby"
17
- spec.metadata["changelog_uri"] = "https://github.com/jamescmartinez/mergent-ruby/blob/main/CHANGELOG.md"
18
+ spec.metadata["source_code_uri"] = "https://github.com/mergentlabs/mergent-ruby"
19
+ spec.metadata["changelog_uri"] = "https://github.com/mergentlabs/mergent-ruby/blob/main/CHANGELOG.md"
20
+ spec.metadata["rubygems_mfa_required"] = "true"
18
21
 
19
22
  # Specify which files should be added to the gem when it is released.
20
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mergent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mergent
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-21 00:00:00.000000000 Z
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: See https://mergent.co for details.
13
+ description: Ruby library for the Mergent API. See https://mergent.co for details.
14
14
  email: support@mergent.co
15
15
  executables: []
16
16
  extensions: []
@@ -18,6 +18,7 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - ".rspec"
20
20
  - ".rubocop.yml"
21
+ - ".ruby-version"
21
22
  - CHANGELOG.md
22
23
  - Gemfile
23
24
  - Gemfile.lock
@@ -28,6 +29,7 @@ files:
28
29
  - lib/mergent/client.rb
29
30
  - lib/mergent/errors.rb
30
31
  - lib/mergent/object.rb
32
+ - lib/mergent/request_validator.rb
31
33
  - lib/mergent/task.rb
32
34
  - lib/mergent/version.rb
33
35
  - mergent.gemspec
@@ -36,8 +38,9 @@ licenses:
36
38
  - MIT
37
39
  metadata:
38
40
  homepage_uri: https://mergent.co
39
- source_code_uri: https://github.com/jamescmartinez/mergent-ruby
40
- changelog_uri: https://github.com/jamescmartinez/mergent-ruby/blob/main/CHANGELOG.md
41
+ source_code_uri: https://github.com/mergentlabs/mergent-ruby
42
+ changelog_uri: https://github.com/mergentlabs/mergent-ruby/blob/main/CHANGELOG.md
43
+ rubygems_mfa_required: 'true'
41
44
  post_install_message:
42
45
  rdoc_options: []
43
46
  require_paths:
@@ -53,8 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
56
  - !ruby/object:Gem::Version
54
57
  version: '0'
55
58
  requirements: []
56
- rubygems_version: 3.2.22
59
+ rubygems_version: 3.3.3
57
60
  signing_key:
58
61
  specification_version: 4
59
- summary: Ruby bindings for the Mergent API
62
+ summary: Ruby library for the Mergent API.
60
63
  test_files: []