omcms-ruby-client 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f65d5c22539416150d654ead0405f04ef72226d75460379e5ddd1e77a39934da
4
- data.tar.gz: 57cf48d1429d89c189fa61e46a943e1cf1a7b3e1cd326d663002dcf01dbd9a73
3
+ metadata.gz: b46ca753a8a873163b0932806bb79e938fc68458c8437c562853115c9548395b
4
+ data.tar.gz: ac3525d85b4d9b6dea51f70d96b2228cf79dda3ff3fe530c939010d03079dba3
5
5
  SHA512:
6
- metadata.gz: 6abc2cb278b925dac14f027b102c7c73a653a4ba04816015e757f601f6ec68d400c3371f7057665f3977c49db965ed6e372da7d4bd5bef7bdf647a3ff73da6ff
7
- data.tar.gz: e4c497b8f12a0b42ed5c701d72da2f8283c471e40024e183a66e6c0db8c5cdc939e0d1b5e1b51185c2aecaf14ebbaf208fef17c98598c87f6e223b7b60a56845
6
+ metadata.gz: 730fb31217a78bfe393d8dd69d893e9a177ecd5899eeecf5910f0dcd4ff79837a6b2169c87826add1affcddecabdc2eaf2055c8fb2a1779810061291ca19da22
7
+ data.tar.gz: d37727a2f6dd96c26383013c74d2a17b045a0de7ea15afd98a37ecd1b67e0db717d1bea1661fc383f073d2a3e9296032ace1eeba7fade66be9fcda821968b9e2
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
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
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|
13
+ @configure_client ||= Faraday.new do |f|
17
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]
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class ParseResponse < Faraday::Middleware
3
5
  def initialize(app)
4
- super app
6
+ super(app)
5
7
  @app = app
6
8
  end
7
9
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class SetHeader < Faraday::Middleware
3
5
  HEADERS = {
@@ -5,7 +7,7 @@ module OMCMS
5
7
  }.freeze
6
8
 
7
9
  def initialize(app)
8
- super app
10
+ super(app)
9
11
  @app = app
10
12
  end
11
13
 
@@ -1,6 +1,8 @@
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OMCMS
2
4
  class Offering < Resource
3
5
  def all
@@ -1,6 +1,8 @@
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
@@ -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
@@ -18,7 +20,7 @@ module OMCMS
18
20
 
19
21
  return response if response.instance_of?(OMCMS::Response::Error)
20
22
 
21
- response_class(class_name).new(@client, response, @host)
23
+ response_class(class_name).new(@client, @host, response)
22
24
  end
23
25
  end
24
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.2.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"
@@ -9,7 +11,8 @@ Gem::Specification.new do |spec|
9
11
  spec.email = ["pradeep.rawat@equitymultiple.com"]
10
12
 
11
13
  spec.summary = "A Ruby SDK for OMCMS APIs"
12
- spec.description = "omcms-ruby-client make is simpler to use OMCMS connector APIs and integrate with existing Ruby application"
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
@@ -23,8 +26,10 @@ Gem::Specification.new do |spec|
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
34
  spec.metadata["rubygems_mfa_required"] = "true"
30
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omcms-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.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-05-26 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
@@ -16,16 +16,37 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '2.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '1.0'
27
- description: omcms-ruby-client make is simpler to use OMCMS connector APIs and integrate
28
- with existing Ruby application
29
+ version: '2.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday-httpclient
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
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
29
50
  email:
30
51
  - pradeep.rawat@equitymultiple.com
31
52
  executables: []
@@ -69,14 +90,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
90
  requirements:
70
91
  - - ">="
71
92
  - !ruby/object:Gem::Version
72
- version: '0'
93
+ version: 2.7.0
73
94
  required_rubygems_version: !ruby/object:Gem::Requirement
74
95
  requirements:
75
96
  - - ">="
76
97
  - !ruby/object:Gem::Version
77
98
  version: '0'
78
99
  requirements: []
79
- rubygems_version: 3.4.10
100
+ rubygems_version: 3.4.22
80
101
  signing_key:
81
102
  specification_version: 4
82
103
  summary: A Ruby SDK for OMCMS APIs