mergent 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 991390648edd146ed10b823a1a47c2c7af7b480cdbf89600018f74d1430f878b
4
+ data.tar.gz: cc42af168a1dc2ea25622a24b200cee773cb8ebe54197215bf3e5bbe30b4fff1
5
+ SHA512:
6
+ metadata.gz: c12851c47f643729e3f8f2d1a90266bbf71a636ca76c2b51f633886efe62c71f9c0492968842230846f8e78d59877233a17f5c9fad8e461590a9528ab05c4eaa
7
+ data.tar.gz: 91179f7fbb9a5cfda2e28e1d87641d98e28b17dac8df398a32a89d18ce354f164adb5848120459479db3157e0d83d0e23340eeebe87d4f5dd6700ec41ffee632
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+
6
+ AllCops:
7
+ NewCops: enable
8
+ TargetRubyVersion: 2.6
9
+
10
+ Layout/LineLength:
11
+ Max: 120
12
+
13
+ Metrics/BlockLength:
14
+ IgnoredMethods: ["context", "describe"]
15
+
16
+ RSpec/ExampleLength:
17
+ Enabled: false
18
+
19
+ RSpec/MultipleExpectations:
20
+ Enabled: false
21
+
22
+ Style/Documentation:
23
+ Enabled: false
24
+
25
+ Style/FrozenStringLiteralComment:
26
+ Enabled: false
27
+
28
+ Style/StringLiterals:
29
+ EnforcedStyle: double_quotes
30
+
31
+ Style/StringLiteralsInInterpolation:
32
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-11-21
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rake"
6
+ gem "rspec"
7
+ gem "rubocop"
8
+ gem "rubocop-performance"
9
+ gem "rubocop-rake"
10
+ gem "rubocop-rspec"
11
+ gem "webmock"
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mergent (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.8.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ ast (2.4.2)
12
+ crack (0.4.5)
13
+ rexml
14
+ diff-lcs (1.4.4)
15
+ hashdiff (1.0.1)
16
+ parallel (1.21.0)
17
+ parser (3.0.2.0)
18
+ ast (~> 2.4.1)
19
+ public_suffix (4.0.6)
20
+ rainbow (3.0.0)
21
+ rake (13.0.6)
22
+ regexp_parser (2.1.1)
23
+ rexml (3.2.5)
24
+ rspec (3.10.0)
25
+ rspec-core (~> 3.10.0)
26
+ rspec-expectations (~> 3.10.0)
27
+ rspec-mocks (~> 3.10.0)
28
+ rspec-core (3.10.1)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-expectations (3.10.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-mocks (3.10.2)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.2)
37
+ rubocop (1.22.3)
38
+ parallel (~> 1.10)
39
+ parser (>= 3.0.0.0)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8, < 3.0)
42
+ rexml
43
+ rubocop-ast (>= 1.12.0, < 2.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 3.0)
46
+ rubocop-ast (1.12.0)
47
+ parser (>= 3.0.1.1)
48
+ rubocop-performance (1.12.0)
49
+ rubocop (>= 1.7.0, < 2.0)
50
+ rubocop-ast (>= 0.4.0)
51
+ rubocop-rake (0.6.0)
52
+ rubocop (~> 1.0)
53
+ rubocop-rspec (2.5.0)
54
+ rubocop (~> 1.19)
55
+ ruby-progressbar (1.11.0)
56
+ unicode-display_width (2.1.0)
57
+ webmock (3.14.0)
58
+ addressable (>= 2.8.0)
59
+ crack (>= 0.3.2)
60
+ hashdiff (>= 0.4.0, < 2.0.0)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ mergent!
67
+ rake
68
+ rspec
69
+ rubocop
70
+ rubocop-performance
71
+ rubocop-rake
72
+ rubocop-rspec
73
+ webmock
74
+
75
+ BUNDLED WITH
76
+ 2.2.31
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021- Mergent Labs Inc. (https://mergent.co)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Mergent
2
+
3
+ The Mergent Ruby library provides convenient access to the Mergent API from
4
+ applications written in the Ruby language.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "mergent"
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install mergent
21
+
22
+ ## Usage
23
+
24
+ The library needs to be configured with your project's API key. Set
25
+ `Mergent.api_key` to its value:
26
+
27
+ ```ruby
28
+ # set the Mergent API key
29
+ Mergent.api_key = "..."
30
+
31
+ # create a Task
32
+ task = Mergent::Task.create({ request: { url: "https://example.com" } })
33
+
34
+ # get the newly created Task's name
35
+ task.name
36
+ ```
37
+
38
+ See the [Mergent Ruby docs](https://docs.mergent.co/libraries/ruby) for more
39
+ details.
40
+
41
+ ## Development
42
+
43
+ After checking out the repo, run `bundle` to install dependencies. Then, run
44
+ `rake spec` to run the tests.
45
+
46
+ 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).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at
55
+ https://github.com/mergentlabs/mergent-ruby.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the
60
+ [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "rubocop/rake_task"
7
+
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
@@ -0,0 +1,34 @@
1
+ require "net/http"
2
+ require "json"
3
+
4
+ module Mergent
5
+ class Client
6
+ def self.post(resource, params) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
7
+ uri = URI("https://api.mergent.co/v1/#{resource}")
8
+ headers = {
9
+ Authorization: "Bearer #{Mergent.api_key}",
10
+ "Content-Type": "application/json"
11
+ }
12
+ request = Net::HTTP::Post.new(uri, headers)
13
+ request.body = params.to_json
14
+
15
+ https = Net::HTTP.new(uri.host, uri.port)
16
+ https.use_ssl = true
17
+ response = https.request(request)
18
+
19
+ case response
20
+ when Net::HTTPSuccess
21
+ JSON.parse(response.read_body, object_class: Mergent::Object)
22
+ else
23
+ begin
24
+ body = JSON.parse(response.read_body)
25
+ rescue JSON::ParserError
26
+ body = {}
27
+ end
28
+ raise Mergent::Error, body["message"]
29
+ end
30
+ rescue EOFError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, SocketError
31
+ raise Mergent::ConnectionError
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Mergent
2
+ class Error < StandardError; end
3
+
4
+ class ConnectionError < Error; end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Mergent
2
+ class Object < OpenStruct; end
3
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "client"
2
+ require_relative "object"
3
+
4
+ module Mergent
5
+ class Task < Mergent::Object
6
+ def self.create(params = {})
7
+ object = Client.post("tasks", params)
8
+ new(object)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Mergent
2
+ VERSION = "0.1.0".freeze
3
+ end
data/lib/mergent.rb ADDED
@@ -0,0 +1,9 @@
1
+ require_relative "mergent/errors"
2
+ require_relative "mergent/task"
3
+ require_relative "mergent/version"
4
+
5
+ module Mergent
6
+ class << self
7
+ attr_accessor :api_key
8
+ end
9
+ end
data/mergent.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ require_relative "lib/mergent/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "mergent"
5
+ spec.version = Mergent::VERSION
6
+ spec.author = "Mergent"
7
+ spec.email = "support@mergent.co"
8
+
9
+ spec.summary = "Ruby bindings for the Mergent API"
10
+ spec.description = "See https://mergent.co for details."
11
+ spec.homepage = "https://mergent.co"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = ">= 2.6.0"
14
+
15
+ 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
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mergent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mergent
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-11-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: See https://mergent.co for details.
14
+ email: support@mergent.co
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".rspec"
20
+ - ".rubocop.yml"
21
+ - CHANGELOG.md
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.md
25
+ - README.md
26
+ - Rakefile
27
+ - lib/mergent.rb
28
+ - lib/mergent/client.rb
29
+ - lib/mergent/errors.rb
30
+ - lib/mergent/object.rb
31
+ - lib/mergent/task.rb
32
+ - lib/mergent/version.rb
33
+ - mergent.gemspec
34
+ homepage: https://mergent.co
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ 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
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.6.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.2.22
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Ruby bindings for the Mergent API
60
+ test_files: []