omcms-ruby-client 1.1.0 → 1.3.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: 486c879393ce195be83ee8ada89010f426cafd4370cb507f61c8f9811648526b
4
- data.tar.gz: 464298d9dcd752ca1a456518c2a0ba88c1b23f962a7c170c27cca584ea415791
3
+ metadata.gz: b46ca753a8a873163b0932806bb79e938fc68458c8437c562853115c9548395b
4
+ data.tar.gz: ac3525d85b4d9b6dea51f70d96b2228cf79dda3ff3fe530c939010d03079dba3
5
5
  SHA512:
6
- metadata.gz: 82dc8d0d1db64df172f23275d82a4e30c51df260e233b53b02853ecad580e3a7df2b64f76a09cb554b34911f5d5a32d3af5fdbff8f2638703d6618233fd1f4f8
7
- data.tar.gz: dd72cf8dc05bf78827a61dfbd91c9f96828a870e1d5fedb092a8cec2925b9528ceb46e00cc1422c79573b90c679f6dff9a5de0eb6e31c3cf36ec350028beb93a
6
+ metadata.gz: 730fb31217a78bfe393d8dd69d893e9a177ecd5899eeecf5910f0dcd4ff79837a6b2169c87826add1affcddecabdc2eaf2055c8fb2a1779810061291ca19da22
7
+ data.tar.gz: d37727a2f6dd96c26383013c74d2a17b045a0de7ea15afd98a37ecd1b67e0db717d1bea1661fc383f073d2a3e9296032ace1eeba7fade66be9fcda821968b9e2
data/.gitignore CHANGED
@@ -7,6 +7,8 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  Gemfile.lock
10
+ .rubocop.yml
11
+ omcms-ruby-client-*.gem
10
12
 
11
13
  # rspec failure tracking
12
14
  .rspec_status
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in omcms-ruby-client.gemspec
4
6
  gemspec
7
+
8
+ group :development, :test do
9
+ gem "bundler", ">= 2.0"
10
+ gem "rake", ">= 10.0"
11
+ gem "rspec", ">= 3.0"
12
+ end
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "omcms"
data/lib/omcms/client.rb CHANGED
@@ -1,40 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class Client
3
5
  attr_reader :client
4
6
 
5
7
  def initialize(opts)
6
8
  configure_credentials(opts)
7
- configure_client
8
- end
9
-
10
- def faraday &block
11
- @faraday = block if block
12
- @faraday
9
+ @client = configure_client
13
10
  end
14
11
 
15
12
  def configure_client
16
- @client ||= Faraday.new do |f|
17
- f.request :basic_auth, @username, @password
13
+ @configure_client ||= Faraday.new do |f|
14
+ f.request :authorization, :basic, @username, @password
18
15
  f.options[:open_timeout] = @open_timeout
19
16
  f.options[:timeout] = @timeout
20
17
  f.request :omcms_set_header
21
18
  f.response :omcms_parse_response
22
- f.response :json, :content_type => /\bjson$/
23
- faraday.call(f) if faraday
24
- f.adapter Faraday.default_adapter unless faraday
19
+ f.response :json, content_type: /\bjson$/
20
+ f.adapter :httpclient
25
21
  end
26
22
  end
27
23
 
28
24
  def offerings
29
- OMCMS::Offering.new(@client, @response, @host)
25
+ OMCMS::Offering.new(@client, @host, @response)
30
26
  end
31
27
 
32
28
  private
33
29
 
34
30
  def configure_credentials(opts)
35
- raise ArgumentError.new "Public Key is missing for the OMCMS client" if opts[:public_key].to_s.empty?
36
- raise ArgumentError.new "Private Key is missing for the OMCMS client" if opts[:private_key].to_s.empty?
37
- raise ArgumentError.new "Host is missing for the OMCMS client" if opts[:host].to_s.empty?
31
+ raise ArgumentError, "Public Key is missing for the OMCMS client" if opts[:public_key].to_s.empty?
32
+ raise ArgumentError, "Private Key is missing for the OMCMS client" if opts[:private_key].to_s.empty?
33
+ raise ArgumentError, "Host is missing for the OMCMS client" if opts[:host].to_s.empty?
38
34
 
39
35
  @username = opts[:public_key]
40
36
  @password = opts[:private_key]
@@ -43,4 +39,4 @@ module OMCMS
43
39
  @timeout = opts[:timeout] || 20
44
40
  end
45
41
  end
46
- end
42
+ end
@@ -1,18 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class ParseResponse < Faraday::Middleware
3
- def initialize app
4
- super app
5
+ def initialize(app)
6
+ super(app)
5
7
  @app = app
6
8
  end
7
9
 
8
- def on_complete response_env
9
- if response_env.status >= 400
10
- return OMCMS::Response::Error.new(response_env)
11
- else
12
- return response_env.body
13
- end
14
- rescue => error
15
- return OMCMS::Response::Error.new(error)
10
+ def on_complete(response_env)
11
+ return OMCMS::Response::Error.new(response_env) if response_env.status >= 400
12
+
13
+ response_env.body
14
+ rescue StandardError => e
15
+ OMCMS::Response::Error.new(e)
16
16
  end
17
17
  end
18
18
  end
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class SetHeader < Faraday::Middleware
3
5
  HEADERS = {
4
- :"user-agent" => "omcms/ruby/client/#{VERSION}"
5
- }
6
+ "user-agent": "omcms/ruby/client/#{VERSION}"
7
+ }.freeze
6
8
 
7
- def initialize app
8
- super app
9
+ def initialize(app)
10
+ super(app)
9
11
  @app = app
10
12
  end
11
13
 
12
- def on_request request_env
14
+ def on_request(request_env)
13
15
  request_env[:request_headers].merge! HEADERS
14
16
  end
15
17
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class Component < Resource
3
- def initialize(client, response = {}, host)
5
+ def initialize(client, host, response = {})
4
6
  @offering_id = response["id"]
5
7
  super
6
8
  end
7
9
 
8
10
  def all
9
- perform_run self, request_path()
11
+ perform_run self, request_path
10
12
  end
11
13
 
12
14
  def get(id)
@@ -1,11 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class Offering < Resource
3
- def initialize(client, response, host)
4
- super
5
- end
6
-
7
5
  def all
8
- perform_run self, request_path()
6
+ perform_run self, request_path
9
7
  end
10
8
 
11
9
  def get(id)
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class OfferingData < Resource
3
- def initialize(client, response = {}, host)
5
+ def initialize(client, host, response = {})
4
6
  @offering_id = response["id"]
5
7
  super
6
8
  end
7
9
 
8
10
  def all
9
- perform_run self, request_path()
11
+ perform_run self, request_path
10
12
  end
11
13
 
12
14
  def get(id)
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class Resource
3
- def initialize(client, response = {}, host = nil)
5
+ def initialize(client, host = nil, _response = {})
4
6
  @client = client
5
7
  @host = host
6
8
  end
@@ -16,8 +18,9 @@ module OMCMS
16
18
  class_name = instance.class.name.split("::").last
17
19
  response = @client.get request_url
18
20
 
19
- return response if response.class == OMCMS::Response::Error
20
- response_class(class_name).new(@client, response, @host)
21
+ return response if response.instance_of?(OMCMS::Response::Error)
22
+
23
+ response_class(class_name).new(@client, @host, response)
21
24
  end
22
25
  end
23
26
  end
@@ -1,44 +1,45 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  module Response
3
5
  class Body
4
6
  attr_reader :body
5
7
 
6
- def initialize(client, response, host)
8
+ def initialize(client, host, response)
7
9
  @client = client
8
10
  @body = response.body
9
11
  @host = host
10
12
  end
11
13
 
12
- def to_json
14
+ def to_json(*_args)
13
15
  parse(@body)
14
16
  end
15
17
 
16
18
  private
17
19
 
18
20
  def parse(data = "")
19
- if data.class == Hash
20
- return data.keys.map do |attribute|
21
+ if data.instance_of?(Hash)
22
+ return data.keys.to_h do |attribute|
21
23
  key = snakecase(attribute)
22
24
  [key, parse(data[attribute])]
23
- end.to_h
24
- elsif data.class == Array
25
+ end
26
+ elsif data.instance_of?(Array)
25
27
  return data.map do |object|
26
- hash = object.keys.map do |attribute|
28
+ object.keys.to_h do |attribute|
27
29
  key = snakecase(attribute)
28
30
  [key, parse(object[attribute])]
29
- end.to_h
31
+ end
30
32
  end
31
33
  end
32
- return data
34
+ data
33
35
  end
34
36
 
35
-
36
37
  def snakecase(data = "")
37
- data.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
38
- .gsub(/([a-z\d])([A-Z])/,'\1_\2')
39
- .tr('-', '_')
40
- .gsub(/\s/, '_')
41
- .gsub(/__+/, '_')
38
+ data.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
39
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
40
+ .tr("-", "_")
41
+ .gsub(/\s/, "_")
42
+ .gsub(/__+/, "_")
42
43
  .downcase
43
44
  end
44
45
  end
@@ -1,9 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  module Response
3
5
  class Component < Body
4
- def initialize(client, data, host)
5
- super
6
- end
7
6
  end
8
7
  end
9
8
  end
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  module Response
3
5
  class Error < StandardError
4
6
  attr_reader :status
5
7
 
6
- def initialize response
8
+ def initialize(response)
9
+ super
7
10
  return unless response
8
- unless response.respond_to? :body
9
- response = add_body_to_error(response)
10
- end
11
+
12
+ response = add_body_to_error(response) unless response.respond_to? :body
11
13
 
12
14
  response.body.each do |key, value|
13
15
  instance_variable_set("@#{key}", value)
@@ -15,17 +17,17 @@ module OMCMS
15
17
  end
16
18
  end
17
19
 
18
- def to_json
19
- self.instance_variables.map do |attribute|
20
- key = attribute.to_s.gsub('@','')
21
- [snakecase(key), self.instance_variable_get(attribute)]
22
- end.to_h
20
+ def to_json(*_args)
21
+ instance_variables.to_h do |attribute|
22
+ key = attribute.to_s.gsub("@", "")
23
+ [snakecase(key), instance_variable_get(attribute)]
24
+ end
23
25
  end
24
26
 
25
27
  private
26
28
 
27
29
  def add_body_to_error(response)
28
- OpenStruct.new(
30
+ Struct.new(
29
31
  body: {
30
32
  name: response.class,
31
33
  message: response.message,
@@ -35,11 +37,11 @@ module OMCMS
35
37
  end
36
38
 
37
39
  def snakecase(data = "")
38
- data.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
39
- .gsub(/([a-z\d])([A-Z])/,'\1_\2')
40
- .tr('-', '_')
41
- .gsub(/\s/, '_')
42
- .gsub(/__+/, '_')
40
+ data.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
41
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
42
+ .tr("-", "_")
43
+ .gsub(/\s/, "_")
44
+ .gsub(/__+/, "_")
43
45
  .downcase
44
46
  end
45
47
  end
@@ -1,16 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  module Response
3
5
  class Offering < Body
4
- def initialize(client, data, host)
5
- super
6
- end
7
-
8
6
  def components
9
- OMCMS::Component.new(@client, self.body, @host)
7
+ OMCMS::Component.new(@client, @host, body)
10
8
  end
11
9
 
12
10
  def data
13
- OMCMS::OfferingData.new(@client, self.body, @host)
11
+ OMCMS::OfferingData.new(@client, @host, body)
14
12
  end
15
13
  end
16
14
  end
@@ -1,9 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  module Response
3
5
  class OfferingData < Body
4
- def initialize(client, data, host)
5
- super
6
- end
7
6
  end
8
7
  end
9
8
  end
data/lib/omcms/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
- VERSION = "1.1.0"
4
+ VERSION = "1.3.0"
3
5
  end
data/lib/omcms.rb CHANGED
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "faraday"
4
+ require "faraday/httpclient"
2
5
 
3
6
  require "omcms/client"
4
7
  require "omcms/resource"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path("lib", __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require "omcms/version"
@@ -6,10 +8,11 @@ Gem::Specification.new do |spec|
6
8
  spec.name = "omcms-ruby-client"
7
9
  spec.version = OMCMS::VERSION
8
10
  spec.authors = ["Pradeep Rawat"]
9
- spec.email = ["pradeep@akaruilabs.com"]
11
+ spec.email = ["pradeep.rawat@equitymultiple.com"]
10
12
 
11
- spec.summary = %q{A Ruby SDK for OMCMS APIs}
12
- spec.description = %q{omcms-ruby-client make is simpler to use OMCMS connector APIs and integrate with existing Ruby application}
13
+ spec.summary = "A Ruby SDK for OMCMS APIs"
14
+ spec.description = "omcms-ruby-client make is simpler to use OMCMS connector APIs
15
+ and integrate with existing Ruby application"
13
16
  spec.homepage = "https://github.com/equitymultiple/omcms-ruby-client"
14
17
 
15
18
  spec.metadata["homepage_uri"] = spec.homepage
@@ -17,16 +20,16 @@ Gem::Specification.new do |spec|
17
20
 
18
21
  # Specify which files should be added to the gem when it is released.
19
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
25
  end
23
26
  spec.bindir = "exe"
24
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
28
  spec.require_paths = ["lib"]
29
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
26
30
 
27
- spec.add_dependency "faraday", "~> 1.0"
31
+ spec.add_dependency "faraday", ">= 2.0", "< 3"
32
+ spec.add_dependency "faraday-httpclient", "~> 2.0"
28
33
 
29
- spec.add_development_dependency "bundler", "~> 2.0"
30
- spec.add_development_dependency "rake", "~> 10.0"
31
- spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.metadata["rubygems_mfa_required"] = "true"
32
35
  end
metadata CHANGED
@@ -1,75 +1,54 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omcms-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pradeep Rawat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2024-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
19
  version: '2.0'
34
- type: :development
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
23
+ type: :runtime
35
24
  prerelease: false
36
25
  version_requirements: !ruby/object:Gem::Requirement
37
26
  requirements:
38
- - - "~>"
27
+ - - ">="
39
28
  - !ruby/object:Gem::Version
40
29
  version: '2.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '10.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
30
+ - - "<"
53
31
  - !ruby/object:Gem::Version
54
- version: '10.0'
32
+ version: '3'
55
33
  - !ruby/object:Gem::Dependency
56
- name: rspec
34
+ name: faraday-httpclient
57
35
  requirement: !ruby/object:Gem::Requirement
58
36
  requirements:
59
37
  - - "~>"
60
38
  - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :development
39
+ version: '2.0'
40
+ type: :runtime
63
41
  prerelease: false
64
42
  version_requirements: !ruby/object:Gem::Requirement
65
43
  requirements:
66
44
  - - "~>"
67
45
  - !ruby/object:Gem::Version
68
- version: '3.0'
69
- description: omcms-ruby-client make is simpler to use OMCMS connector APIs and integrate
70
- with existing Ruby application
46
+ version: '2.0'
47
+ description: |-
48
+ omcms-ruby-client make is simpler to use OMCMS connector APIs
49
+ and integrate with existing Ruby application
71
50
  email:
72
- - pradeep@akaruilabs.com
51
+ - pradeep.rawat@equitymultiple.com
73
52
  executables: []
74
53
  extensions: []
75
54
  extra_rdoc_files: []
@@ -102,6 +81,7 @@ licenses: []
102
81
  metadata:
103
82
  homepage_uri: https://github.com/equitymultiple/omcms-ruby-client
104
83
  source_code_uri: https://github.com/equitymultiple/omcms-ruby-client
84
+ rubygems_mfa_required: 'true'
105
85
  post_install_message:
106
86
  rdoc_options: []
107
87
  require_paths:
@@ -110,14 +90,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
90
  requirements:
111
91
  - - ">="
112
92
  - !ruby/object:Gem::Version
113
- version: '0'
93
+ version: 2.7.0
114
94
  required_rubygems_version: !ruby/object:Gem::Requirement
115
95
  requirements:
116
96
  - - ">="
117
97
  - !ruby/object:Gem::Version
118
98
  version: '0'
119
99
  requirements: []
120
- rubygems_version: 3.2.3
100
+ rubygems_version: 3.4.22
121
101
  signing_key:
122
102
  specification_version: 4
123
103
  summary: A Ruby SDK for OMCMS APIs