gupshup-rb 0.1.7.1 → 0.1.8
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 +4 -4
- data/.gitignore +17 -0
- data/.rubocop.yml +59 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +62 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +1 -1
- data/Rakefile +10 -0
- data/bin/console +9 -0
- data/bin/setup +5 -0
- data/gupshup-rb-0.1.0.gem +0 -0
- data/gupshup-rb-0.1.1.gem +0 -0
- data/gupshup-rb-0.1.2.gem +0 -0
- data/gupshup-rb-0.1.3.gem +0 -0
- data/gupshup-rb-0.1.4.gem +0 -0
- data/gupshup-rb-0.1.5.gem +0 -0
- data/gupshup-rb-0.1.6.gem +0 -0
- data/gupshup-rb.gemspec +39 -0
- data/lib/gupshup-rb/framework/gupshup_response.rb +19 -0
- data/lib/gupshup-rb/framework/request.rb +41 -0
- data/lib/gupshup-rb/framework/response.rb +18 -0
- data/lib/gupshup-rb/framework/rest/domain.rb +36 -0
- data/lib/gupshup-rb/framework/rest/error.rb +51 -0
- data/lib/gupshup-rb/framework/rest/helper.rb +11 -0
- data/lib/gupshup-rb/framework/rest/obsolete_client.rb +12 -0
- data/lib/gupshup-rb/framework/rest/page.rb +103 -0
- data/lib/gupshup-rb/framework/rest/resource.rb +23 -0
- data/lib/gupshup-rb/framework/rest/version.rb +153 -0
- data/lib/gupshup-rb/framework/serialize.rb +81 -0
- data/lib/gupshup-rb/framework/values.rb +9 -0
- data/lib/gupshup-rb/http/http_client.rb +53 -0
- data/lib/gupshup-rb/http.rb +5 -0
- data/lib/gupshup-rb/rest/api/v1/message.rb +59 -0
- data/lib/gupshup-rb/rest/api/v1.rb +29 -0
- data/lib/gupshup-rb/rest/api.rb +245 -0
- data/lib/gupshup-rb/rest/client.rb +581 -0
- data/lib/gupshup-rb/rest.rb +13 -0
- data/lib/gupshup-rb/util/configuration.rb +33 -0
- data/lib/gupshup-rb/version.rb +3 -0
- data/lib/gupshup-rb.rb +47 -0
- metadata +50 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28476dad0e6c5d22419bb1506c488c34f65f5caf73b69cf423f084128f65c9ee
|
4
|
+
data.tar.gz: 8a3e629dc4fe625cdcfbb828deaedaa1d06659533073497a7ec19347c6dfcb12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 882a50f9da161b1c59265b03be1b0bdc4663cc797eaff097f752f52e55dea151f11c62a59e165e6d387935c95e117b8fe5d684681c8065c2f3e949ad561e47d5
|
7
|
+
data.tar.gz: be20db4668983c8d2d944b7c56edf6d79223d86784b6ae4a7d05742dce37a8f343e0726ed426873d61268fd23646b0833398f0ff5f8f111289d84763fe797637
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.5
|
5
|
+
Exclude:
|
6
|
+
- 'lib/gupshup-rb/rest/**/*'
|
7
|
+
- 'spec/integration/**/*'
|
8
|
+
- 'lib/gupshup-rb/version.rb'
|
9
|
+
- 'lib/gupshup-rb/twiml/**/*'
|
10
|
+
- 'lib/gupshup-rb/util/configuration.rb'
|
11
|
+
- 'vendor/**/*'
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 120
|
15
|
+
Exclude:
|
16
|
+
- 'spec/**/*'
|
17
|
+
|
18
|
+
Style/BlockDelimiters:
|
19
|
+
Exclude:
|
20
|
+
- 'spec/**/*'
|
21
|
+
|
22
|
+
Lint/AmbiguousBlockAssociation:
|
23
|
+
Exclude:
|
24
|
+
- 'spec/**/*'
|
25
|
+
|
26
|
+
Metrics/BlockLength:
|
27
|
+
Exclude:
|
28
|
+
- 'spec/**/*'
|
29
|
+
- gupshup-rb.gemspec
|
30
|
+
|
31
|
+
Layout/HeredocIndentation:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Metrics/ClassLength:
|
35
|
+
Max: 175
|
36
|
+
|
37
|
+
Metrics/MethodLength:
|
38
|
+
Max: 25
|
39
|
+
|
40
|
+
Metrics/ParameterLists:
|
41
|
+
Max: 20
|
42
|
+
|
43
|
+
Metrics/AbcSize:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Metrics/PerceivedComplexity:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Metrics/CyclomaticComplexity:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Style/HashEachMethods:
|
53
|
+
Enabled: true
|
54
|
+
|
55
|
+
Style/HashTransformKeys:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/HashTransformValues:
|
59
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
- Using welcoming and inclusive language
|
18
|
+
- Being respectful of differing viewpoints and experiences
|
19
|
+
- Gracefully accepting constructive criticism
|
20
|
+
- Focusing on what is best for the community
|
21
|
+
- Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
- The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
- Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
- Public or private harassment
|
29
|
+
- Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
## Attribution
|
58
|
+
|
59
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
60
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
61
|
+
|
62
|
+
[homepage]: https://www.contributor-covenant.org
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (C) 2023
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
9
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
10
|
+
so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 TODO: Write your name
|
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
CHANGED
@@ -35,4 +35,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
35
35
|
|
36
36
|
## Code of Conduct
|
37
37
|
|
38
|
-
Everyone interacting in the Gupshup::Rb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/raimartinsb/gupshup-rb/blob/master/CODE_OF_CONDUCT.md).
|
38
|
+
Everyone interacting in the Gupshup::Rb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/raimartinsb/gupshup-rb/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "gupshup-rb"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
Gupshup::Console.new.start
|
data/bin/setup
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/gupshup-rb.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'gupshup-rb/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'gupshup-rb'
|
9
|
+
spec.version = Gupshup::VERSION
|
10
|
+
spec.authors = ['Raimundo Martins']
|
11
|
+
spec.summary = 'Communication with Chatwoot - Not Completed! Still does not work!'
|
12
|
+
spec.description = 'Communication with Chatwoot - Not Completed! Still does not work!'
|
13
|
+
spec.homepage = 'https://github.com/raimartinsb/gupshup-rb'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.metadata = { 'yard.run' => 'yri' } # use "yard" to build full HTML docs
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match?(%r{^(spec)/}) }
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.required_ruby_version = '>= 2.0.0'
|
22
|
+
spec.extra_rdoc_files = ['README.md', 'LICENSE']
|
23
|
+
spec.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'gupshup-rb', '--main', 'README.md']
|
24
|
+
|
25
|
+
spec.add_dependency('jwt', '>= 1.5', '< 3.0')
|
26
|
+
spec.add_dependency('nokogiri', '>= 1.6', '< 2.0')
|
27
|
+
spec.add_dependency('faraday', '>= 0.9', '< 3.0')
|
28
|
+
# Workaround for RBX <= 2.2.1, should be fixed in next version
|
29
|
+
spec.add_dependency('rubysl') if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '>= 1.5', '< 3.0'
|
32
|
+
spec.add_development_dependency 'equivalent-xml', '~> 0.6'
|
33
|
+
spec.add_development_dependency 'fakeweb', '~> 1.3'
|
34
|
+
spec.add_development_dependency 'rack', '~> 2.0'
|
35
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'yard', '~> 0.9.9'
|
38
|
+
spec.add_development_dependency 'logger', '~> 1.4.2'
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gupshup
|
4
|
+
class GupshupResponse
|
5
|
+
attr_accessor :status_code, :body
|
6
|
+
|
7
|
+
# @deprecated Use 'Gupshup::Response' instead.
|
8
|
+
def initialize(status_code, body)
|
9
|
+
warn "'Gupshup::GupshupResponse' has been deprecated. Use 'Gupshup::Response' instead."
|
10
|
+
response = Gupshup::Response.new(status_code, body)
|
11
|
+
@status_code = response.status_code
|
12
|
+
@body = response.body
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"[#{@status_code}] #{@body}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gupshup
|
4
|
+
class Request
|
5
|
+
attr_reader :host, :port, :method, :url, :params, :data, :headers, :auth, :timeout
|
6
|
+
|
7
|
+
def initialize(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
8
|
+
@host = host
|
9
|
+
@port = port
|
10
|
+
@url = url
|
11
|
+
@method = method
|
12
|
+
@params = params
|
13
|
+
@data = data
|
14
|
+
@headers = headers
|
15
|
+
@auth = auth
|
16
|
+
@timeout = timeout
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
auth = @auth.nil? ? '' : '(' + @auth.join(',') + ')'
|
21
|
+
|
22
|
+
params = ''
|
23
|
+
unless @params.nil? || @params.empty?
|
24
|
+
params = '?' + @params.each.map { |key, value| "#{CGI.escape(key)}=#{CGI.escape(value)}" }.join('&')
|
25
|
+
end
|
26
|
+
|
27
|
+
headers = ''
|
28
|
+
unless @headers.nil? || @headers.empty?
|
29
|
+
headers = "\n" + @headers.each.map { |key, value| "-H \"#{key}\": \"#{value}\"" }.join("\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
data = ''
|
33
|
+
unless @data.nil? || @data.empty?
|
34
|
+
data = @method.equal?('GET') ? "\n -G" : "\n"
|
35
|
+
data += @data.each.map { |key, value| "-d \"#{key}\"=\"#{value}\"" }.join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
"#{auth} #{@method} #{@url}#{params}#{data}#{headers}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gupshup
|
4
|
+
class Response
|
5
|
+
attr_accessor :status_code, :body, :headers
|
6
|
+
|
7
|
+
def initialize(status_code, body, headers: nil)
|
8
|
+
@status_code = status_code
|
9
|
+
body = '{}' if !body || body.empty?
|
10
|
+
@body = JSON.parse(body)
|
11
|
+
@headers = !headers ? {} : headers.to_hash
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"[#{status_code}] #{body}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gupshup
|
4
|
+
module REST
|
5
|
+
class Domain
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
@host = nil
|
11
|
+
@base_url = nil
|
12
|
+
@port = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def absolute_url(uri)
|
16
|
+
"#{@base_url.chomp('/')}/#{uri.chomp('/').gsub(/^\//, '')}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def request(method, uri, params = {}, data = {}, headers = {}, auth = nil, timeout = nil)
|
20
|
+
url = uri.match(/^http/) ? uri : absolute_url(uri)
|
21
|
+
|
22
|
+
@client.request(
|
23
|
+
@base_url,
|
24
|
+
@port,
|
25
|
+
method,
|
26
|
+
url,
|
27
|
+
params,
|
28
|
+
data,
|
29
|
+
headers,
|
30
|
+
auth,
|
31
|
+
timeout
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gupshup
|
4
|
+
module REST
|
5
|
+
class GupshupError < StandardError
|
6
|
+
# @deprecated all errors that have a body are now 'Gupshup::RestError's
|
7
|
+
def body
|
8
|
+
warn "'Gupshup::REST::GupshupError#body' has been deprecated. No 'GupshupError' objects are raised with a body."
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class RestError < GupshupError
|
14
|
+
attr_reader :message, :response, :code, :status_code, :details, :more_info, :error_message
|
15
|
+
|
16
|
+
def initialize(message, response)
|
17
|
+
@status_code = response.status_code
|
18
|
+
@code = response.body.fetch('code', @status_code)
|
19
|
+
@details = response.body.fetch('details', nil)
|
20
|
+
@error_message = response.body.fetch('message', nil)
|
21
|
+
@more_info = response.body.fetch('more_info', nil)
|
22
|
+
@message = format_message(message)
|
23
|
+
@response = response
|
24
|
+
end
|
25
|
+
|
26
|
+
# @deprecated use #response instead
|
27
|
+
def body
|
28
|
+
warn 'This error used to be a "Gupshup::REST::GupshupError" but is now a "Gupshup::REST::RestError". ' \
|
29
|
+
'Please use #response instead of #body.'
|
30
|
+
@response
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
message
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def format_message(initial_message)
|
40
|
+
message = "[HTTP #{status_code}] #{code} : #{initial_message}"
|
41
|
+
message += "\n#{error_message}" if error_message
|
42
|
+
message += "\n#{details}" if details
|
43
|
+
message += "\n#{more_info}" if more_info
|
44
|
+
message + "\n\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class ObsoleteError < StandardError
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gupshup
|
4
|
+
module REST
|
5
|
+
class ObsoleteClient
|
6
|
+
def initialize(*)
|
7
|
+
raise ObsoleteError, "#{self.class} has been removed from this version of the library. "\
|
8
|
+
'Please refer to current documentation for guidance.'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gupshup
|
4
|
+
module REST
|
5
|
+
# Page Base Class
|
6
|
+
class Page
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
META_KEYS = [
|
10
|
+
'end',
|
11
|
+
'first_page_uri',
|
12
|
+
'next_page_uri',
|
13
|
+
'last_page_uri',
|
14
|
+
'page',
|
15
|
+
'page_size',
|
16
|
+
'previous_page_uri',
|
17
|
+
'total',
|
18
|
+
'num_pages',
|
19
|
+
'start',
|
20
|
+
'uri'
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
def initialize(version, response)
|
24
|
+
payload = process_response(response)
|
25
|
+
|
26
|
+
@version = version
|
27
|
+
@payload = payload
|
28
|
+
@solution = {}
|
29
|
+
@records = load_page(payload)
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_response(response)
|
33
|
+
if response.status_code != 200
|
34
|
+
raise Gupshup::REST::RestError.new('Unable to fetch page', response)
|
35
|
+
end
|
36
|
+
|
37
|
+
response.body
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_page(payload)
|
41
|
+
if payload['meta'] && payload['meta']['key']
|
42
|
+
return payload[payload['meta']['key']]
|
43
|
+
else
|
44
|
+
keys = payload.keys
|
45
|
+
key = keys - META_KEYS
|
46
|
+
return payload[key.first] if key.size == 1
|
47
|
+
end
|
48
|
+
|
49
|
+
raise Gupshup::REST::GupshupError, 'Page Records can not be deserialized'
|
50
|
+
end
|
51
|
+
|
52
|
+
def previous_page_url
|
53
|
+
if @payload['meta'] && @payload['meta']['previous_page_url']
|
54
|
+
return @version.domain.absolute_url(URI.parse(@payload['meta']['previous_page_url']).request_uri)
|
55
|
+
elsif @payload['previous_page_uri']
|
56
|
+
return @version.domain.absolute_url(@payload['previous_page_uri'])
|
57
|
+
end
|
58
|
+
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def next_page_url
|
63
|
+
if @payload['meta'] && @payload['meta']['next_page_url']
|
64
|
+
return @version.domain.absolute_url(URI.parse(@payload['meta']['next_page_url']).request_uri)
|
65
|
+
elsif @payload['next_page_uri']
|
66
|
+
return @version.domain.absolute_url(@payload['next_page_uri'])
|
67
|
+
end
|
68
|
+
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_instance(payload)
|
73
|
+
raise Gupshup::REST::GupshupError, 'Page.get_instance() must be implemented in the derived class'
|
74
|
+
end
|
75
|
+
|
76
|
+
def previous_page
|
77
|
+
return nil unless previous_page_url
|
78
|
+
|
79
|
+
response = @version.domain.request('GET', previous_page_url)
|
80
|
+
|
81
|
+
self.class.new(@version, response, @solution)
|
82
|
+
end
|
83
|
+
|
84
|
+
def next_page
|
85
|
+
return nil unless next_page_url
|
86
|
+
|
87
|
+
response = @version.domain.request('GET', next_page_url)
|
88
|
+
|
89
|
+
self.class.new(@version, response, @solution)
|
90
|
+
end
|
91
|
+
|
92
|
+
def each
|
93
|
+
@records.each do |record|
|
94
|
+
yield get_instance(record)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_s
|
99
|
+
'#<Page>'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gupshup
|
4
|
+
module REST
|
5
|
+
class ListResource
|
6
|
+
def initialize(version)
|
7
|
+
@version = version
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class InstanceContext
|
12
|
+
def initialize(version)
|
13
|
+
@version = version
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class InstanceResource
|
18
|
+
def initialize(version)
|
19
|
+
@version = version
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|