mock-bandwidth 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8b94456bdd96b95f64866379b3c9a06326b225d2e2f3e6bbce188e526348c506
4
+ data.tar.gz: 8dcff047c29e53d2b2b79e93ac3fb7a930443549144e883f5b259aa3bf2ac04f
5
+ SHA512:
6
+ metadata.gz: 01e64367e88e041c8c213fb41b3ab73cd13fe8d5a5d41dcfb3a890ec236258355eee0726109d72c13d6d3da6b49d8ef634e201ed7ed3bfb559e4040ed6941eaa
7
+ data.tar.gz: f2846ce3140cbe36fdff50b602e025c558153a1e63326b09bdfcda5ff4f903ba5a4f028706d101612018f6c7996e99a56212704e110edf42e18c133c4d60af32
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [1.0.0] - 2025-01-25
2
+
3
+ - Add create message support
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Guillermo Quezada
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,69 @@
1
+ # Mock::Bandwidth
2
+
3
+ This is a SchoolStatus implementation to mock Bandwidth to perform requests to [bandwidth-oai](https://docs.stoplight.io/docs/prism/83dbbd75532cf-http-mocking)
4
+
5
+
6
+ # Installation
7
+
8
+ To install using bundler grab the latest stable version:
9
+
10
+ ```ruby
11
+ gem install mock-bandwidth
12
+ ```
13
+
14
+ ## Requirements
15
+ - [Bandwidth-oai](https://docs.stoplight.io/docs/prism/83dbbd75532cf-http-mocking)
16
+
17
+ ## Defaults Prism
18
+
19
+ - `proxy_address = bandwidth_mock_server`
20
+ - `proxy_port = 4010`
21
+ - `proxy_protocol = http`
22
+
23
+ ## Features Support
24
+
25
+ | Support | Mock::Bandwidth |
26
+ | ------------- | ------------- |
27
+ | :white_check_mark: | `Bandwidth::MessagesApi.new.create_message(account_id, body)` |
28
+
29
+
30
+ ## How to use
31
+ Initializer sample
32
+
33
+ ```ruby
34
+ Bandwidth.configure do |config| # Configure Basic Auth
35
+ config.username = "username"
36
+ config.password = "password"
37
+ config.configure_faraday_connection do |connection|
38
+ connection.proxy = "http://mock-server.test"
39
+ connection.use Mock::Bandwidth::Middleware::Proxy
40
+ end
41
+ end
42
+ ```
43
+
44
+ Example
45
+ ```ruby
46
+ from = "+18001234123123"
47
+ application_id = "12341234"
48
+ account_id = "123123"
49
+ text = "sms text"
50
+ to = "+17001234123123"
51
+
52
+ body = Bandwidth::MessageRequest.new(
53
+ {
54
+ from: from,
55
+ application_id: application_id,
56
+ to: [to],
57
+ text: text
58
+ }
59
+ )
60
+ messaging_api_instance = Bandwidth::MessagesApi.new
61
+ response = messaging_api_instance.create_message(account_id, body)
62
+
63
+ => #<Bandwidth::Message:0x00005f39e4efcae0 @application_id="12341234", @from="+18001234123123", @id="1737987840867jqaf7b3rad1a6fn", @owner="+18001234123123", @text="sms text", @to=["+17001234123123"]>
64
+ ```
65
+
66
+ ## Run tests
67
+ ```unix
68
+ rake test
69
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "schemas/messaging_v2"
4
+
5
+ module Mock
6
+ module Bandwidth
7
+ class Decorator
8
+ ENDPOINTS = {
9
+ messaging_v2: Mock::Bandwidth::Schemas::MessagingV2
10
+ }
11
+
12
+ class << self
13
+ def call(body, request)
14
+ body = JSON.parse(body)
15
+
16
+ case request.status
17
+ when 400..600
18
+ return body
19
+ end
20
+
21
+ schema = url_from(body, request)
22
+ # return body decorate if needed
23
+ return ENDPOINTS[schema].for(body, request) if schema
24
+
25
+ body
26
+ end
27
+
28
+ def url_from(body, request)
29
+ url = request.url.path
30
+
31
+ case url
32
+ when %r{\/api\/v2\/users\/\d+\/messages}
33
+ :messaging_v2
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Bandwidth
5
+ module Decorators
6
+ module MessagingV2
7
+ class MessageCreate
8
+ class << self
9
+ def decorate(body, request)
10
+ data = JSON.parse request.request_body
11
+
12
+ body["to"] = data["to"] if body["to"]
13
+ body["from"] = data["from"] if body["from"]
14
+ body["owner"] = data["from"] if body["owner"]
15
+ body["text"] = data["text"] if body["text"]
16
+ body["applicationId"] = data["applicationId"] if body["applicationId"]
17
+
18
+ body["id"] = message_id if body["id"]
19
+
20
+ body.to_json
21
+ end
22
+
23
+ def message_id
24
+ timestamp = (Time.now.to_f * 1000).to_i.to_s[0..12]
25
+ random_part = SecureRandom.alphanumeric(15).downcase
26
+ "#{timestamp}#{random_part}"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Mock
6
+ module Bandwidth
7
+ module Middleware
8
+ class Proxy < Faraday::Middleware
9
+ def initialize(app)
10
+ super(app)
11
+ end
12
+
13
+ def call(env)
14
+ env.url.host = env.request.proxy.host
15
+ env.url.port = env.request.proxy.port
16
+ env.url.scheme = env.request.proxy.scheme
17
+
18
+ @app.call(env).on_complete do |request|
19
+ if request.response_body
20
+ request.body = Mock::Bandwidth::Response.call(request.response.body, request)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ Faraday::Request.register_middleware(proxy: Mock::Bandwidth::Middleware::Proxy)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Bandwidth
5
+ class Response
6
+ attr_accessor :body
7
+
8
+ def self.call(body, request)
9
+ body = '{}' if !body || body.empty?
10
+ @body = Mock::Bandwidth::Decorator.call(body, request)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../decorators/messaging_v2/message_create"
4
+
5
+ module Mock
6
+ module Bandwidth
7
+ module Schemas
8
+ class MessagingV2
9
+ class << self
10
+ RESOURCES = {
11
+ create_message: Mock::Bandwidth::Decorators::MessagingV2::MessageCreate,
12
+ }
13
+ def for(body, request)
14
+ url = request.url.path
15
+
16
+ case url
17
+ when %r{\/api\/v2\/users\/\d+\/messages}
18
+ return RESOURCES[:create_message].decorate(body, request) if request.method == :post
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mock
4
+ module Bandwidth
5
+ VERSION = "1.0.0"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "bandwidth/version"
4
+ require_relative "bandwidth/middleware/proxy"
5
+ require_relative "bandwidth/response"
6
+ require_relative "bandwidth/decorator"
7
+
8
+ module Mock
9
+ module Bandwidth
10
+ class Error < StandardError; end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module Mock
2
+ module Bandwidth
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mock-bandwidth
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Guillermo Quezada
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bandwidth-sdk
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '14.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '14.0'
47
+ description: This repository contains Mock::Bandwidth for Bandwidth's API.
48
+ email:
49
+ - meemocol@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - CHANGELOG.md
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/mock/bandwidth.rb
59
+ - lib/mock/bandwidth/decorator.rb
60
+ - lib/mock/bandwidth/decorators/messaging_v2/message_create.rb
61
+ - lib/mock/bandwidth/middleware/proxy.rb
62
+ - lib/mock/bandwidth/response.rb
63
+ - lib/mock/bandwidth/schemas/messaging_v2.rb
64
+ - lib/mock/bandwidth/version.rb
65
+ - sig/mock/bandwidth.rbs
66
+ homepage: https://github.com/schoolstatus/mock-bandwidth
67
+ licenses:
68
+ - MIT
69
+ metadata:
70
+ homepage_uri: https://github.com/schoolstatus/mock-bandwidth
71
+ source_code_uri: https://github.com/schoolstatus/mock-bandwidth
72
+ changelog_uri: https://github.com/schoolstatus/mock-bandwidth/blob/main/CHANGELOG.md
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '2.7'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.1.4
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: This repository contains Mock::Bandwidth and Webhooks for Bandwidth's API.
92
+ test_files: []