qismo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +9 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +81 -0
- data/LICENSE.txt +21 -0
- data/README.md +120 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/qismo/client.rb +131 -0
- data/lib/qismo/errors.rb +58 -0
- data/lib/qismo/helpers/base_helper.rb +50 -0
- data/lib/qismo/models/agent.rb +42 -0
- data/lib/qismo/models/base.rb +60 -0
- data/lib/qismo/models/bot.rb +12 -0
- data/lib/qismo/models/null_object.rb +109 -0
- data/lib/qismo/models/office_hour.rb +13 -0
- data/lib/qismo/models/office_setting.rb +19 -0
- data/lib/qismo/models/room.rb +31 -0
- data/lib/qismo/models/user.rb +19 -0
- data/lib/qismo/operations.rb +6 -0
- data/lib/qismo/resources/agent_resource.rb +39 -0
- data/lib/qismo/resources/bot_resource.rb +61 -0
- data/lib/qismo/resources/office_setting_resource.rb +67 -0
- data/lib/qismo/resources/room_resource.rb +182 -0
- data/lib/qismo/resources/user_resource.rb +45 -0
- data/lib/qismo/response.rb +136 -0
- data/lib/qismo/version.rb +6 -0
- data/lib/qismo.rb +72 -0
- data/qismo.gemspec +30 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3b17d0ba64fc0e678f76fdc720b1f6780efc9324e78a17a5b046a11ca2c20c63
|
4
|
+
data.tar.gz: 2168cf3d3fa3b04ad3fffbe18518fd093a11de22be1fbe6ae04939c3ad8d1ed5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 937249a7bc7751c3de6f3a1c5cdf735dbacc2a772a447ae0aba852c0a07aa53544cf1239dcd9bd516a450ffffeffe39214a3befc450b24323968ef7d4ecbea1e
|
7
|
+
data.tar.gz: 0bd51e327f166527a15a183441c83a39413ae23a560803643191796af3eab349a3ea32d20b43fb4fd852d3dd5e9a8a3cd2783dce1efe15038865c6d4fe285082
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.5
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
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, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
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
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at nurcholisart@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
qismo (0.1.0)
|
5
|
+
http (~> 4.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
ast (2.4.2)
|
13
|
+
diff-lcs (1.5.0)
|
14
|
+
domain_name (0.5.20190701)
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
16
|
+
ffi (1.15.4)
|
17
|
+
ffi-compiler (1.0.1)
|
18
|
+
ffi (>= 1.0.0)
|
19
|
+
rake
|
20
|
+
http (4.4.1)
|
21
|
+
addressable (~> 2.3)
|
22
|
+
http-cookie (~> 1.0)
|
23
|
+
http-form_data (~> 2.2)
|
24
|
+
http-parser (~> 1.2.0)
|
25
|
+
http-cookie (1.0.4)
|
26
|
+
domain_name (~> 0.5)
|
27
|
+
http-form_data (2.3.0)
|
28
|
+
http-parser (1.2.3)
|
29
|
+
ffi-compiler (>= 1.0, < 2.0)
|
30
|
+
parallel (1.21.0)
|
31
|
+
parser (3.0.3.2)
|
32
|
+
ast (~> 2.4.1)
|
33
|
+
public_suffix (4.0.6)
|
34
|
+
rainbow (3.0.0)
|
35
|
+
rake (12.3.3)
|
36
|
+
regexp_parser (2.2.0)
|
37
|
+
rexml (3.2.5)
|
38
|
+
rspec (3.10.0)
|
39
|
+
rspec-core (~> 3.10.0)
|
40
|
+
rspec-expectations (~> 3.10.0)
|
41
|
+
rspec-mocks (~> 3.10.0)
|
42
|
+
rspec-core (3.10.1)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-expectations (3.10.1)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.10.0)
|
47
|
+
rspec-mocks (3.10.2)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.10.0)
|
50
|
+
rspec-support (3.10.3)
|
51
|
+
rubocop (1.24.0)
|
52
|
+
parallel (~> 1.10)
|
53
|
+
parser (>= 3.0.0.0)
|
54
|
+
rainbow (>= 2.2.2, < 4.0)
|
55
|
+
regexp_parser (>= 1.8, < 3.0)
|
56
|
+
rexml
|
57
|
+
rubocop-ast (>= 1.15.0, < 2.0)
|
58
|
+
ruby-progressbar (~> 1.7)
|
59
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
60
|
+
rubocop-ast (1.15.0)
|
61
|
+
parser (>= 3.0.1.1)
|
62
|
+
rubocop-shopify (2.3.0)
|
63
|
+
rubocop (~> 1.22)
|
64
|
+
ruby-progressbar (1.11.0)
|
65
|
+
unf (0.1.4)
|
66
|
+
unf_ext
|
67
|
+
unf_ext (0.0.8)
|
68
|
+
unicode-display_width (2.1.0)
|
69
|
+
|
70
|
+
PLATFORMS
|
71
|
+
ruby
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
http (~> 4.4)
|
75
|
+
qismo!
|
76
|
+
rake (~> 12.0)
|
77
|
+
rspec (~> 3.0)
|
78
|
+
rubocop-shopify (~> 2.3)
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Nurcholis Art
|
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,120 @@
|
|
1
|
+
# Qismo Ruby
|
2
|
+
|
3
|
+
A Ruby API wrapper for Qiscus Multichannel API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "qismo"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
**Example for single app id**
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# config/initializers/qismo.rb
|
25
|
+
# Initialization
|
26
|
+
Qismo.init do |config|
|
27
|
+
config.app_id = ENV["QISCUS_APP_ID"]
|
28
|
+
config.secret_key = ENV["QISCUS_SECRET_KEY"]
|
29
|
+
config.base_url = ENV["QISCUS_MULTICHANNEL_BASE_URL"]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get all rooms that have been waiting for a week
|
33
|
+
rooms = Room.where(status: "waiting")
|
34
|
+
.where("created_at >= :a_week", a_week: 1.week.ago)
|
35
|
+
|
36
|
+
# Resolve the rooms
|
37
|
+
rooms.each(Qismo::Room.resolve(&:id))
|
38
|
+
```
|
39
|
+
|
40
|
+
**Example for multi app id**
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# Get all rooms that have been waiting for a week
|
44
|
+
rooms = Room.includes(:qiscus_app)
|
45
|
+
.where(status: "waiting")
|
46
|
+
.where("created_at >= :a_week", a_week: 1.week.ago)
|
47
|
+
|
48
|
+
# Resolve the rooms
|
49
|
+
rooms.each do |room|
|
50
|
+
Qismo.new(app_id: room.qiscus_app.app_id, secret_key: room.qiscus_app.secret_key)
|
51
|
+
Qismo::Room.resolve(room.id)
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
**Nested operations**
|
56
|
+
|
57
|
+
If you prefer to use nested operations, you can also use this package like below
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
client = Qismo.new(app_id: room.qiscus_app.app_id, secret_key: room.qiscus_app.secret_key)
|
61
|
+
client.room.resolve(id)
|
62
|
+
```
|
63
|
+
|
64
|
+
**Requesting to unhandled API**
|
65
|
+
|
66
|
+
Qiscus Multichannel is on fast development mode and at some condition, you might find this library is not handle the new API. If that happen, you can use the operations like below:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
Qismo.client.call("post", "/api/v2/api_endpoint", json: {}, params: {})
|
70
|
+
```
|
71
|
+
|
72
|
+
**Error handling**
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
begin
|
76
|
+
room = Qismo::Room.resolve(123456) # Not Found
|
77
|
+
rescue Qismo::HTTPError => e
|
78
|
+
e.message # return error message
|
79
|
+
e.http_code # return response code
|
80
|
+
e.http_headers # return response headers in hash
|
81
|
+
e.http_body # return response body in hash or string
|
82
|
+
e.http_raw_body # return raw response body in string
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
## Experience
|
87
|
+
|
88
|
+
This gem leverage YARD to improve text editor autocompletion
|
89
|
+
|
90
|
+
Install YARD
|
91
|
+
|
92
|
+
```shell
|
93
|
+
gem install yard
|
94
|
+
```
|
95
|
+
|
96
|
+
Change to project directory and expose gem YARD documentation
|
97
|
+
|
98
|
+
```shell
|
99
|
+
yard gems
|
100
|
+
```
|
101
|
+
|
102
|
+
For VSCode users, you can use Solargraph gem to improve the autocompletion
|
103
|
+
|
104
|
+
## Development
|
105
|
+
|
106
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
107
|
+
|
108
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
109
|
+
|
110
|
+
## Contributing
|
111
|
+
|
112
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/qismo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/qismo/blob/master/CODE_OF_CONDUCT.md).
|
113
|
+
|
114
|
+
## License
|
115
|
+
|
116
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
117
|
+
|
118
|
+
## Code of Conduct
|
119
|
+
|
120
|
+
Everyone interacting in the Qismo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/qismo/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "qismo"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/qismo/client.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "http"
|
4
|
+
require "qismo/operations"
|
5
|
+
|
6
|
+
module Qismo
|
7
|
+
#
|
8
|
+
# Qismo client object
|
9
|
+
#
|
10
|
+
# @!attribute app_id [String]
|
11
|
+
# @!attribute secret_key [String]
|
12
|
+
# @!attribute base_url [String]
|
13
|
+
# @!attribute admin_email [String]
|
14
|
+
class Client
|
15
|
+
# @!parse
|
16
|
+
# include Qismo::Helpers::BaseHelper
|
17
|
+
include Qismo::Helpers::BaseHelper
|
18
|
+
|
19
|
+
# @!parse
|
20
|
+
# include Qismo::Operations
|
21
|
+
include Qismo::Operations
|
22
|
+
|
23
|
+
# @return [String] default base url constant
|
24
|
+
DEFAULT_BASE_URL = "https://multichannel.qiscus.com"
|
25
|
+
|
26
|
+
attr_accessor :app_id, :secret_key, :base_url, :admin_email, :proxy
|
27
|
+
|
28
|
+
#
|
29
|
+
# Initialize Qismo client
|
30
|
+
#
|
31
|
+
# @param options [Hash]
|
32
|
+
# @option options [String] :app_id
|
33
|
+
# @option options [String] :secret_key
|
34
|
+
# @option options [String] :base_url
|
35
|
+
#
|
36
|
+
def initialize(options = {})
|
37
|
+
options = options.compact
|
38
|
+
options[:base_url] = DEFAULT_BASE_URL if options[:base_url].nil?
|
39
|
+
|
40
|
+
options.each do |key, value|
|
41
|
+
instance_variable_set("@#{key}", value)
|
42
|
+
end
|
43
|
+
|
44
|
+
if @admin_email.nil? && !@app_id.nil?
|
45
|
+
@admin_email = "#{app_id}_admin@qismo.com"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Call HTTP request raw
|
51
|
+
#
|
52
|
+
# @param method [String]
|
53
|
+
# @param url [String]
|
54
|
+
# @param options [Hash]
|
55
|
+
# @option options [Hash] :headers
|
56
|
+
# @option options [Hash] :params
|
57
|
+
# @option options [Hash] :json
|
58
|
+
#
|
59
|
+
# @return [Response]
|
60
|
+
#
|
61
|
+
def raw_request(method, url, options = {})
|
62
|
+
resp = if Qismo.client.proxy.nil?
|
63
|
+
HTTP.request(method, url, options)
|
64
|
+
else
|
65
|
+
proxy = Qismo.client.proxy
|
66
|
+
proxy_args = [proxy[:host], proxy[:port], proxy[:username], proxy[:password]]
|
67
|
+
|
68
|
+
HTTP.via(*proxy_args).request(method, url, options)
|
69
|
+
end
|
70
|
+
|
71
|
+
resp = Response.new(resp)
|
72
|
+
resp.raise_for_error
|
73
|
+
|
74
|
+
resp
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# Do HTTP request
|
79
|
+
#
|
80
|
+
# @param method [String]
|
81
|
+
# @param path [String]
|
82
|
+
# @param options [Hash]
|
83
|
+
# @option options [Hash] :params
|
84
|
+
# @option options [Hash] :json
|
85
|
+
# @options options [Hash] :headers
|
86
|
+
#
|
87
|
+
# @return [Response]
|
88
|
+
#
|
89
|
+
def request(method, path, options = {})
|
90
|
+
url = Qismo.client.base_url + path
|
91
|
+
|
92
|
+
if !options[:headers].nil? && options[:headers].is_a?(Hash) && !options[:headers][:authorization].nil?
|
93
|
+
options[:header].merge({
|
94
|
+
qiscus_app_id: Qismo.client.app_id,
|
95
|
+
qiscus_secret_key: Qismo.client.secret_key,
|
96
|
+
})
|
97
|
+
else
|
98
|
+
options[:headers] = {
|
99
|
+
qiscus_app_id: Qismo.client.app_id,
|
100
|
+
qiscus_secret_key: Qismo.client.secret_key,
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
raw_request(method, url, options)
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Do HTTP request using GET method
|
109
|
+
#
|
110
|
+
# @param path [String]
|
111
|
+
# @param params [Hash]
|
112
|
+
#
|
113
|
+
# @return [Response]
|
114
|
+
#
|
115
|
+
def get(path, params = {})
|
116
|
+
request(:get, path, params: params)
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# Do HTTP request using POST method
|
121
|
+
#
|
122
|
+
# @param path [String]
|
123
|
+
# @param body [Hash]
|
124
|
+
#
|
125
|
+
# @return [Response]
|
126
|
+
#
|
127
|
+
def post(path, body = {})
|
128
|
+
request(:post, path, json: body)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/lib/qismo/errors.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Qismo
|
4
|
+
#
|
5
|
+
# Qismo generic error
|
6
|
+
# @!attribute message [String]
|
7
|
+
#
|
8
|
+
class Error < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# Qismo HTTP error
|
13
|
+
#
|
14
|
+
# @attribute message [String]
|
15
|
+
# @attribute http_code [Integer]
|
16
|
+
# @attribute http_headers [Hash]
|
17
|
+
# @attribute http_body [Hash,String]
|
18
|
+
# @attribute http_raw_body [String]
|
19
|
+
#
|
20
|
+
class HTTPError < StandardError
|
21
|
+
attr_accessor :message, :http_code, :http_headers, :http_body, :http_raw_body
|
22
|
+
|
23
|
+
def initialize(message = nil, http_code: nil, http_headers: nil, http_body: nil, http_raw_body: nil)
|
24
|
+
@message = message
|
25
|
+
@http_code = http_code
|
26
|
+
@http_headers = http_headers
|
27
|
+
@http_body = http_body
|
28
|
+
@http_raw_body = http_raw_body
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Error for 5xx status code
|
33
|
+
ServerError = Class.new(HTTPError)
|
34
|
+
|
35
|
+
# Error for 500 status code
|
36
|
+
InternalServerError = Class.new(ServerError)
|
37
|
+
|
38
|
+
# Error for 4xx status code
|
39
|
+
ClientError = Class.new(HTTPError)
|
40
|
+
|
41
|
+
# Error for 400 status code
|
42
|
+
BadRequest = Class.new(ClientError)
|
43
|
+
|
44
|
+
# Error for 401 status code
|
45
|
+
Unauthorized = Class.new(ClientError)
|
46
|
+
|
47
|
+
# Error for 402 status code
|
48
|
+
PaymentRequired = Class.new(ClientError)
|
49
|
+
|
50
|
+
# Error for 403 status code
|
51
|
+
Forbidden = Class.new(ClientError)
|
52
|
+
|
53
|
+
# Error for 404 status code
|
54
|
+
NotFound = Class.new(ClientError)
|
55
|
+
|
56
|
+
# Error for 429 status code
|
57
|
+
RateLimitExceeded = Class.new(ClientError)
|
58
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Qismo
|
4
|
+
#
|
5
|
+
# Utilities for Qismo Ruby client
|
6
|
+
#
|
7
|
+
module Helpers
|
8
|
+
module BaseHelper
|
9
|
+
#
|
10
|
+
# Validate the existence of hash attributes
|
11
|
+
#
|
12
|
+
# @param args [Array<Symbol,String>]
|
13
|
+
# @param on [Hash]
|
14
|
+
#
|
15
|
+
#
|
16
|
+
def validate_existence_of!(*args, on:)
|
17
|
+
args.each do |arg|
|
18
|
+
falsy = (on[arg] == {} || on[arg] == [] || on[arg].nil? || on[arg] == "" || on[arg] == 0)
|
19
|
+
raise BadRequest, "#{arg} is required" if falsy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Check the argument is false or not
|
25
|
+
#
|
26
|
+
# @param arg [String, Integer, Hash, Array, NilClass]
|
27
|
+
#
|
28
|
+
# @return [TrueClass, FalseClass]
|
29
|
+
#
|
30
|
+
def falsy?(arg)
|
31
|
+
(arg == {} || arg == [] || arg.nil? || arg == "" || arg == 0)
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Safely parse json string
|
36
|
+
#
|
37
|
+
# @param str [String]
|
38
|
+
#
|
39
|
+
# @return [Hash,String]
|
40
|
+
#
|
41
|
+
def safe_parse_json(str, symbolize_names: false)
|
42
|
+
str = str.to_json if str.is_a?(Hash)
|
43
|
+
|
44
|
+
JSON.parse(str, symbolize_names: symbolize_names)
|
45
|
+
rescue JSON::ParserError
|
46
|
+
str
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Qismo
|
4
|
+
#
|
5
|
+
# Agent model
|
6
|
+
#
|
7
|
+
# @!attribute id [Integer]
|
8
|
+
# @!attribute email [String]
|
9
|
+
# @!attribute name [String]
|
10
|
+
# @!attribute authentication_token [String]
|
11
|
+
# @!attribute created_at [String]
|
12
|
+
# @!attribute updated_at [String]
|
13
|
+
# @!attribute sdk_email [String]
|
14
|
+
# @!attribute sdk_key [String]
|
15
|
+
# @!attribute is_available [TrueClass, FalseClass]
|
16
|
+
# @!attribute type [Integer]
|
17
|
+
# @!attribute avatar_url [String]
|
18
|
+
# @!attribute app_id [Integer]
|
19
|
+
# @!attribute is_verified [TrueClass, FalseClass]
|
20
|
+
# @!attribute notifications_room_id [String]
|
21
|
+
# @!attribute bubble_color [String, nil]
|
22
|
+
# @!attribute qismo_key [String]
|
23
|
+
# @!attribute direct_login_token [String]
|
24
|
+
# @!attribute last_login [String]
|
25
|
+
# @!attribute force_offline [TrueClass, FalseClass]
|
26
|
+
# @!attribute deleted_at [String, nil]
|
27
|
+
# @!attribute type_as_string [String]
|
28
|
+
# @!attribute assigned_rules [Array<String>]
|
29
|
+
#
|
30
|
+
class Agent < Base
|
31
|
+
# @!parse
|
32
|
+
# extend Resources::AgentResource
|
33
|
+
extend Resources::AgentResource
|
34
|
+
end
|
35
|
+
|
36
|
+
module Operations
|
37
|
+
# @return [Qismo::Agent::Class]
|
38
|
+
def agent
|
39
|
+
Qismo::Agent
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|