justcall_ruby 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/.rubocop.yml +128 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +16 -0
- data/justcall_ruby.gemspec +31 -0
- data/lib/justcall_ruby/api.rb +71 -0
- data/lib/justcall_ruby/base.rb +27 -0
- data/lib/justcall_ruby/call.rb +70 -0
- data/lib/justcall_ruby/client.rb +24 -0
- data/lib/justcall_ruby/error.rb +9 -0
- data/lib/justcall_ruby/response.rb +47 -0
- data/lib/justcall_ruby/sms.rb +66 -0
- data/lib/justcall_ruby/version.rb +5 -0
- data/lib/justcall_ruby.rb +29 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3b8e75e621a9a8163f6267682f4982b3304d49d9db86dcfbc8e9485c7a8dbe75
|
4
|
+
data.tar.gz: 8ecac85c5fc52ce069671013cf83c43d90e9b99cbce783d65f68a094be2fd5b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f8b5677142ae235b3533ad4c9ff5ae60b7e2d4ad1e34d12f8d99fdea0005569ce1b62ab4517093d773fbfb9a2c0719d8f36ee1bbe5541c3cab866018fd7c01d
|
7
|
+
data.tar.gz: 9b3dc176f846d070390f0e92170cf2c28e1fb2d432bd3ad030b18abd54a83ff8aa90dd95373d2532e32802e10720a93f53dcd0f6ae5d1bd9aa32f95ee7b53f57
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
# Layout cops
|
6
|
+
Layout/FirstArrayElementIndentation:
|
7
|
+
EnforcedStyle: consistent
|
8
|
+
|
9
|
+
Layout/HashAlignment:
|
10
|
+
EnforcedLastArgumentHashStyle: ignore_implicit
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
AutoCorrect: true
|
15
|
+
|
16
|
+
Layout/MultilineMethodCallIndentation:
|
17
|
+
EnforcedStyle: indented
|
18
|
+
|
19
|
+
Layout/MultilineOperationIndentation:
|
20
|
+
Enabled: true
|
21
|
+
EnforcedStyle: indented
|
22
|
+
|
23
|
+
Layout/ArgumentAlignment:
|
24
|
+
Enabled: true
|
25
|
+
EnforcedStyle: with_fixed_indentation
|
26
|
+
|
27
|
+
# Lint cops
|
28
|
+
Lint/AmbiguousBlockAssociation:
|
29
|
+
AllowedMethods: [proc, map]
|
30
|
+
|
31
|
+
Lint/MissingSuper:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Lint/UriRegexp:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
# Metrics cops
|
38
|
+
Metrics/BlockLength:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Metrics/ClassLength:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Metrics/MethodLength:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Metrics/CyclomaticComplexity:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Metrics/AbcSize:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
Metrics/PerceivedComplexity:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
Metrics/ModuleLength:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
# Naming
|
60
|
+
Naming/AccessorMethodName:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Naming/MemoizedInstanceVariableName:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Naming/VariableNumber:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
# Style cops
|
70
|
+
Style/FetchEnvVar:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Style/AccessorGrouping:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
Style/AsciiComments:
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
Style/ClassAndModuleChildren:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
Style/Documentation:
|
83
|
+
Enabled: false
|
84
|
+
|
85
|
+
Style/DoubleNegation:
|
86
|
+
Enabled: false
|
87
|
+
|
88
|
+
Style/FormatStringToken:
|
89
|
+
EnforcedStyle: template
|
90
|
+
|
91
|
+
Style/FrozenStringLiteralComment:
|
92
|
+
Enabled: false
|
93
|
+
|
94
|
+
Style/GlobalVars:
|
95
|
+
AllowedVariables: [$redis]
|
96
|
+
|
97
|
+
Style/Lambda:
|
98
|
+
EnforcedStyle: literal
|
99
|
+
|
100
|
+
Style/MissingRespondToMissing:
|
101
|
+
Enabled: false
|
102
|
+
|
103
|
+
Style/NumericPredicate:
|
104
|
+
AllowedMethods: ["=="]
|
105
|
+
|
106
|
+
Style/Proc:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
Style/RegexpLiteral:
|
110
|
+
AllowInnerSlashes: true
|
111
|
+
|
112
|
+
Style/ReturnNil:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
Style/StringLiterals:
|
116
|
+
Enabled: false
|
117
|
+
|
118
|
+
Style/SelectByRegexp:
|
119
|
+
Enabled: false
|
120
|
+
|
121
|
+
Style/TrailingCommaInHashLiteral:
|
122
|
+
EnforcedStyleForMultiline: comma
|
123
|
+
|
124
|
+
Style/TrailingCommaInArrayLiteral:
|
125
|
+
EnforcedStyleForMultiline: comma
|
126
|
+
|
127
|
+
Style/TrailingCommaInArguments:
|
128
|
+
EnforcedStyleForMultiline: no_comma
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
## [0.1.0] - 2024-07-10
|
2
|
+
|
3
|
+
The initial release. Provides all basic Ruby wrapper functionality for JustCall's V2 API.
|
4
|
+
|
5
|
+
The V2 API currently includes the following endpoints:
|
6
|
+
- Calls
|
7
|
+
- [List all calls](https://developer.justcall.io/reference/call_list)
|
8
|
+
- [Get a call](https://developer.justcall.io/reference/call_get)
|
9
|
+
- [Update a call](https://developer.justcall.io/reference/call_update)
|
10
|
+
- [Download a recording](https://developer.justcall.io/reference/call_recording_download)
|
11
|
+
- SMS
|
12
|
+
- [List all texts](https://developer.justcall.io/reference/texts_list)
|
13
|
+
- [Get a text](https://developer.justcall.io/reference/texts_get)
|
14
|
+
- [Check reply](https://developer.justcall.io/reference/texts_checkreply)
|
15
|
+
- [Send SMS/MMS](https://developer.justcall.io/reference/texts_new)
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
justcall_ruby (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
json (2.7.2)
|
11
|
+
language_server-protocol (3.17.0.3)
|
12
|
+
minitest (5.24.1)
|
13
|
+
parallel (1.25.1)
|
14
|
+
parser (3.3.3.0)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
racc
|
17
|
+
racc (1.8.0)
|
18
|
+
rainbow (3.1.1)
|
19
|
+
rake (13.2.1)
|
20
|
+
regexp_parser (2.9.2)
|
21
|
+
rexml (3.3.1)
|
22
|
+
strscan
|
23
|
+
rubocop (1.64.1)
|
24
|
+
json (~> 2.3)
|
25
|
+
language_server-protocol (>= 3.17.0)
|
26
|
+
parallel (~> 1.10)
|
27
|
+
parser (>= 3.3.0.2)
|
28
|
+
rainbow (>= 2.2.2, < 4.0)
|
29
|
+
regexp_parser (>= 1.8, < 3.0)
|
30
|
+
rexml (>= 3.2.5, < 4.0)
|
31
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
32
|
+
ruby-progressbar (~> 1.7)
|
33
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
34
|
+
rubocop-ast (1.31.3)
|
35
|
+
parser (>= 3.3.1.0)
|
36
|
+
ruby-progressbar (1.13.0)
|
37
|
+
strscan (3.1.0)
|
38
|
+
unicode-display_width (2.5.0)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
arm64-darwin-22
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
justcall_ruby!
|
45
|
+
minitest (~> 5.0)
|
46
|
+
rake (~> 13.0)
|
47
|
+
rubocop (~> 1.21)
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
2.4.10
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Jeffrey Dill
|
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,37 @@
|
|
1
|
+
# JustCall API - Ruby Wrapper
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
Add this line to your application's Gemfile:
|
5
|
+
```
|
6
|
+
gem 'justcall_ruby'
|
7
|
+
```
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
```
|
11
|
+
$ bundle
|
12
|
+
```
|
13
|
+
|
14
|
+
Or install it locally using:
|
15
|
+
```
|
16
|
+
$ gem install justcall_ruby
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Documentation
|
22
|
+
The full documentation is located here: http://www.rubydoc.info/gems/justcall_ruby
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/leadsimple/justcall_ruby.
|
27
|
+
|
28
|
+
To contribute code changes:
|
29
|
+
1. Fork it ( https://github.com/leadsimple/justcall_ruby/fork )
|
30
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
1. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
1. Create a new Pull Request
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "justcall_ruby/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "justcall_ruby"
|
9
|
+
spec.version = JustCall::VERSION
|
10
|
+
spec.authors = ["Jeffrey Dill"]
|
11
|
+
spec.email = ["jeffdill2@gmail.com"]
|
12
|
+
spec.summary = "A simple Ruby wrapper for the JustCall REST API"
|
13
|
+
spec.homepage = "https://github.com/leadsimple/justcall_ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
20
|
+
spec.metadata["rubygems_mfa_required"] = 'true'
|
21
|
+
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ .git .circleci])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module JustCall
|
4
|
+
module API
|
5
|
+
ROOT_URL = 'https://api.justcall.io/v2'.freeze
|
6
|
+
USER_AGENT = "JustCallRubyGem/#{JustCall::VERSION}".freeze
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def get_request(client:, endpoint:)
|
11
|
+
request = Net::HTTP::Get.new(request_url(endpoint))
|
12
|
+
|
13
|
+
submit_request(client: client, request: request)
|
14
|
+
end
|
15
|
+
|
16
|
+
def post_request(client:, endpoint:, data: {})
|
17
|
+
request = Net::HTTP::Post.new(request_url(endpoint))
|
18
|
+
|
19
|
+
submit_request(client: client, request: request, data: data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def put_request(client:, endpoint:, data: {})
|
23
|
+
request = Net::HTTP::Put.new(request_url(endpoint))
|
24
|
+
|
25
|
+
submit_request(client: client, request: request, data: data)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_request(client:, endpoint:)
|
29
|
+
request = Net::HTTP::Delete.new(request_url(endpoint))
|
30
|
+
|
31
|
+
submit_request(client: client, request: request)
|
32
|
+
end
|
33
|
+
|
34
|
+
def submit_request(client:, request:, data: {})
|
35
|
+
set_request_headers(client: client, request: request)
|
36
|
+
|
37
|
+
uri = URI(request.path)
|
38
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
39
|
+
|
40
|
+
request.body = data.is_a?(Hash) ? data.to_json : data if data.any?
|
41
|
+
http.use_ssl = true
|
42
|
+
http.set_debug_output($stdout) if JustCall.config.full_debug?
|
43
|
+
|
44
|
+
response = http.start { |h| h.request(request) }
|
45
|
+
|
46
|
+
JustCall::Response.new(response)
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_request_headers(client:, request:)
|
50
|
+
request['Accept'] = 'application/json'
|
51
|
+
request['Authorization'] = [client.api_key, client.api_secret].join(':')
|
52
|
+
request['Content-Type'] = 'application/json'
|
53
|
+
request['User-Agent'] = USER_AGENT
|
54
|
+
end
|
55
|
+
|
56
|
+
def request_url(endpoint)
|
57
|
+
[ROOT_URL, endpoint].join('/')
|
58
|
+
end
|
59
|
+
|
60
|
+
def standardize_body_data(submitted_attrs:, permitted_attrs:)
|
61
|
+
submitted_attrs = submitted_attrs.deep_transform_keys(&:to_sym)
|
62
|
+
permitted_attrs = submitted_attrs.select! { |k, _| permitted_attrs.include?(k) } || submitted_attrs
|
63
|
+
|
64
|
+
permitted_attrs.deep_transform_keys { |k| k.to_s.camelize(:lower) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def convert_params_to_request_query(params)
|
68
|
+
params&.map { |k, v| [k.to_s.camelize(:lower), v].join('=') }&.join('&')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module JustCall
|
2
|
+
class Base
|
3
|
+
protected
|
4
|
+
|
5
|
+
def requires!(*args)
|
6
|
+
self.class.requires!(*args)
|
7
|
+
end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def requires!(hash, *params)
|
11
|
+
params.each do |param|
|
12
|
+
if param.is_a?(Array)
|
13
|
+
raise ArgumentError, "Missing required parameter: #{param.first}" unless hash.key?(param.first)
|
14
|
+
|
15
|
+
valid_options = param[1..]
|
16
|
+
|
17
|
+
unless valid_options.include?(hash[param.first])
|
18
|
+
raise ArgumentError, "Parameter: #{param.first} must be one of: #{valid_options.join(', ')}"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
raise ArgumentError, "Missing required parameter: #{param}" unless hash.key?(param)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'justcall_ruby/api'
|
2
|
+
|
3
|
+
module JustCall
|
4
|
+
class Call < Base
|
5
|
+
include JustCall::API
|
6
|
+
|
7
|
+
LIST_ATTRS = {
|
8
|
+
permitted: %i[
|
9
|
+
fetch_queue_data fetch_iq_data page per_page sort order from_datetime to_datetime
|
10
|
+
contact_number justcall_number agent_id ivr_digit call_direction call_type
|
11
|
+
].freeze,
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
FETCH_ATTRS = {
|
15
|
+
permitted: %i[fetch_queue_data fetch_iq_data].freeze,
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
UPDATE_ATTRS = {
|
19
|
+
permitted: %i[notes disposition_code rating].freeze,
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
CHECK_REPLY_ATTRS = {
|
23
|
+
permitted: %i[contact_number justcall_number].freeze,
|
24
|
+
required: %i[contact_number].freeze,
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
SEND_ATTRS = {
|
28
|
+
permitted: %i[justcall_number body contact_number media_url restrict_once].freeze,
|
29
|
+
required: %i[justcall_number body contact_number].freeze,
|
30
|
+
}.freeze
|
31
|
+
|
32
|
+
ENDPOINTS = {
|
33
|
+
list: "calls?%s".freeze,
|
34
|
+
fetch: "calls/%s?%s".freeze,
|
35
|
+
update: "calls/%s".freeze,
|
36
|
+
download_recording: "calls/%s/recording/download".freeze,
|
37
|
+
}.freeze
|
38
|
+
|
39
|
+
def initialize(client:)
|
40
|
+
@client = client
|
41
|
+
end
|
42
|
+
|
43
|
+
def list(params = {})
|
44
|
+
params = standardize_body_data(submitted_attrs: params, permitted_attrs: LIST_ATTRS[:permitted])
|
45
|
+
endpoint = ENDPOINTS[:list] % convert_params_to_request_query(params)
|
46
|
+
|
47
|
+
get_request(client: @client, endpoint: endpoint)
|
48
|
+
end
|
49
|
+
|
50
|
+
def fetch(call_id, params = {})
|
51
|
+
params = standardize_body_data(submitted_attrs: params, permitted_attrs: FETCH_ATTRS[:permitted])
|
52
|
+
endpoint = ENDPOINTS[:fetch] % [call_id, convert_params_to_request_query(params)] # rubocop:disable Style/FormatString
|
53
|
+
|
54
|
+
get_request(client: @client, endpoint: endpoint)
|
55
|
+
end
|
56
|
+
|
57
|
+
def update(call_id, params)
|
58
|
+
endpoint = ENDPOINTS[:update] % call_id
|
59
|
+
params = standardize_body_data(submitted_attrs: params, permitted_attrs: UPDATE_ATTRS[:permitted])
|
60
|
+
|
61
|
+
put_request(client: @client, endpoint: endpoint, data: params)
|
62
|
+
end
|
63
|
+
|
64
|
+
def download_recording(call_id)
|
65
|
+
endpoint = ENDPOINTS[:download_recording] % call_id
|
66
|
+
|
67
|
+
get_request(client: @client, endpoint: endpoint)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'justcall_ruby/api'
|
2
|
+
require 'justcall_ruby/call'
|
3
|
+
require 'justcall_ruby/sms'
|
4
|
+
|
5
|
+
module JustCall
|
6
|
+
class Client
|
7
|
+
include JustCall::API
|
8
|
+
|
9
|
+
attr_reader :api_key, :api_secret
|
10
|
+
|
11
|
+
def initialize(api_key:, api_secret:)
|
12
|
+
@api_key = api_key
|
13
|
+
@api_secret = api_secret
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
@call ||= JustCall::Call.new(client: self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def sms
|
21
|
+
@sms ||= JustCall::SMS.new(client: self)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module JustCall
|
2
|
+
class Error < StandardError
|
3
|
+
class NoContent < JustCall::Error; end
|
4
|
+
class NotAuthorized < JustCall::Error; end
|
5
|
+
class NotFound < JustCall::Error; end
|
6
|
+
class RequestError < JustCall::Error; end
|
7
|
+
class TimeoutError < JustCall::Error; end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module JustCall
|
2
|
+
class Response
|
3
|
+
attr_reader :body, :response, :sucess
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
|
8
|
+
case @response
|
9
|
+
when Net::HTTPUnauthorized
|
10
|
+
raise JustCall::Error::NotAuthorized, @response.body
|
11
|
+
when Net::HTTPNotFound
|
12
|
+
raise JustCall::Error::NotFound, @response.body
|
13
|
+
when Net::HTTPOK, Net::HTTPSuccess, Net::HTTPNoContent, Net::HTTPCreated
|
14
|
+
@success = true
|
15
|
+
body = (JSON.parse(@response.body) if @response.body.present?)
|
16
|
+
@body =
|
17
|
+
if body.is_a?(Hash)
|
18
|
+
body.deep_symbolize_keys
|
19
|
+
elsif body.is_a?(Array)
|
20
|
+
body.map(&:deep_symbolize_keys)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
puts "-- DEBUG: #{self}: RequestError: #{@response.inspect}" if JustCall.config.full_debug?
|
24
|
+
|
25
|
+
error_message = begin
|
26
|
+
JSON.parse(@response.body)['errors'].map { |error| error['message'].chomp('.') }.join('. ')
|
27
|
+
rescue StandardError
|
28
|
+
[@response.message, @response.body].reject(&:blank?).join(" | ")
|
29
|
+
end
|
30
|
+
|
31
|
+
raise JustCall::Error::RequestError, error_message
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def [](key)
|
36
|
+
body[key]
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch(key)
|
40
|
+
body.fetch(key)
|
41
|
+
end
|
42
|
+
|
43
|
+
def success?
|
44
|
+
!!success
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'justcall_ruby/api'
|
2
|
+
|
3
|
+
module JustCall
|
4
|
+
class SMS < Base
|
5
|
+
include JustCall::API
|
6
|
+
|
7
|
+
LIST_ATTRS = {
|
8
|
+
permitted: %i[
|
9
|
+
page per_page sort order from_datetime to_datetime contact_number
|
10
|
+
justcall_number sms_direction sms_content last_sms_id_fetched
|
11
|
+
].freeze,
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
CHECK_REPLY_ATTRS = {
|
15
|
+
permitted: %i[contact_number justcall_number].freeze,
|
16
|
+
required: %i[contact_number].freeze,
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
SEND_ATTRS = {
|
20
|
+
permitted: %i[justcall_number body contact_number media_url restrict_once].freeze,
|
21
|
+
required: %i[justcall_number body contact_number].freeze,
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
ENDPOINTS = {
|
25
|
+
list: "texts?%s".freeze,
|
26
|
+
fetch: "texts/%s".freeze,
|
27
|
+
check_reply: "texts/checkreply".freeze,
|
28
|
+
send: "texts/new".freeze,
|
29
|
+
}.freeze
|
30
|
+
|
31
|
+
def initialize(client:)
|
32
|
+
@client = client
|
33
|
+
end
|
34
|
+
|
35
|
+
def list(params = {})
|
36
|
+
params = standardize_body_data(submitted_attrs: params, permitted_attrs: LIST_ATTRS[:permitted])
|
37
|
+
endpoint = ENDPOINTS[:list] % convert_params_to_request_query(params)
|
38
|
+
|
39
|
+
get_request(client: @client, endpoint: endpoint)
|
40
|
+
end
|
41
|
+
|
42
|
+
def fetch(sms_id)
|
43
|
+
endpoint = ENDPOINTS[:fetch] % sms_id
|
44
|
+
|
45
|
+
get_request(client: @client, endpoint: endpoint)
|
46
|
+
end
|
47
|
+
|
48
|
+
def check_reply(params)
|
49
|
+
requires!(params, *CHECK_REPLY_ATTRS[:required])
|
50
|
+
|
51
|
+
endpoint = ENDPOINTS[:check_reply]
|
52
|
+
params = standardize_body_data(submitted_attrs: params, permitted_attrs: CHECK_REPLY_ATTRS[:permitted])
|
53
|
+
|
54
|
+
post_request(client: @client, endpoint: endpoint, data: params)
|
55
|
+
end
|
56
|
+
|
57
|
+
def send(params)
|
58
|
+
requires!(params, *SEND_ATTRS[:required])
|
59
|
+
|
60
|
+
endpoint = ENDPOINTS[:send]
|
61
|
+
params = standardize_body_data(submitted_attrs: params, permitted_attrs: SEND_ATTRS[:permitted])
|
62
|
+
|
63
|
+
post_request(client: @client, endpoint: endpoint, data: params)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'justcall_ruby/base'
|
2
|
+
require 'justcall_ruby/version'
|
3
|
+
|
4
|
+
require 'justcall_ruby/api'
|
5
|
+
require 'justcall_ruby/call'
|
6
|
+
require 'justcall_ruby/client'
|
7
|
+
require 'justcall_ruby/error'
|
8
|
+
require 'justcall_ruby/response'
|
9
|
+
require 'justcall_ruby/sms'
|
10
|
+
|
11
|
+
module JustCall
|
12
|
+
def self.config
|
13
|
+
@config ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
yield(config)
|
18
|
+
end
|
19
|
+
|
20
|
+
class Configuration
|
21
|
+
attr_accessor :full_debug
|
22
|
+
|
23
|
+
alias full_debug? full_debug
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@full_debug = false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: justcall_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeffrey Dill
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- jeffdill2@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rubocop.yml"
|
21
|
+
- CHANGELOG.md
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- justcall_ruby.gemspec
|
28
|
+
- lib/justcall_ruby.rb
|
29
|
+
- lib/justcall_ruby/api.rb
|
30
|
+
- lib/justcall_ruby/base.rb
|
31
|
+
- lib/justcall_ruby/call.rb
|
32
|
+
- lib/justcall_ruby/client.rb
|
33
|
+
- lib/justcall_ruby/error.rb
|
34
|
+
- lib/justcall_ruby/response.rb
|
35
|
+
- lib/justcall_ruby/sms.rb
|
36
|
+
- lib/justcall_ruby/version.rb
|
37
|
+
homepage: https://github.com/leadsimple/justcall_ruby
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata:
|
41
|
+
homepage_uri: https://github.com/leadsimple/justcall_ruby
|
42
|
+
source_code_uri: https://github.com/leadsimple/justcall_ruby
|
43
|
+
changelog_uri: https://github.com/leadsimple/justcall_ruby/blob/master/CHANGELOG.md
|
44
|
+
rubygems_mfa_required: 'true'
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.6.0
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.4.10
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: A simple Ruby wrapper for the JustCall REST API
|
64
|
+
test_files: []
|