mitake_api 0.0.1
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +3 -0
- data/lib/mitake_api/client.rb +40 -0
- data/lib/mitake_api/message.rb +34 -0
- data/lib/mitake_api/railtie.rb +4 -0
- data/lib/mitake_api/sms_provider.rb +19 -0
- data/lib/mitake_api/version.rb +3 -0
- data/lib/mitake_api.rb +9 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 59245d035e3e7e91a3560a783d101e60d0088517f9326ccc31410cd93baa31a9
|
4
|
+
data.tar.gz: ff8dcd022e3396b484e5b4953c71d0808c5768583c4f9a7d997dad48b0f1345b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 015dd07a804076ab67f3fcf3807d0267d14245d416b8e4dee082902ec1429d3810495209ebd5306f04caf124c7e95875e746cc0870a9561c526d7374de56d086
|
7
|
+
data.tar.gz: 254e5c5858e1c77e1f26c64df13b8b35d4a88c791a48de03a3f2283360e381dbdc2e90eb0e087bfd09a1d1d01db1a246972b68c256d50c971b3ce855ba799038
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2022 z01241
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# MitakeApi
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "mitake_api"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install mitake_api
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
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,40 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
# require 'faraday_middleware'
|
3
|
+
Faraday.default_adapter = :net_http
|
4
|
+
module Mitake
|
5
|
+
class Client
|
6
|
+
attr_reader :url, :charset, :mitake_msg, :response
|
7
|
+
|
8
|
+
def initialize(settings)
|
9
|
+
@username = settings[:username]
|
10
|
+
@password = settings[:password]
|
11
|
+
@charset = settings[:charset] || 'UTF8'
|
12
|
+
@url = "https://#{settings[:url]&.gsub(%r{https?://}, '')}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def send_message(message)
|
16
|
+
@mitake_msg = Message.new(message)
|
17
|
+
mitake_msg.response = connection.post('api/mtk/SmSend') do |req|
|
18
|
+
req.params = { CharsetURL: charset }
|
19
|
+
req.headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
20
|
+
req.body = URI.encode_www_form(credentials.merge(mitake_msg.to_h))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def connection
|
27
|
+
@connection ||= Faraday.new(url: url) do |faraday|
|
28
|
+
faraday.response :logger
|
29
|
+
faraday.response :raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def credentials
|
34
|
+
{
|
35
|
+
username: @username,
|
36
|
+
password: @password
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Mitake
|
2
|
+
class Message
|
3
|
+
attr_reader :message
|
4
|
+
|
5
|
+
def initialize(message)
|
6
|
+
@message = message
|
7
|
+
end
|
8
|
+
|
9
|
+
def response=(response)
|
10
|
+
@response = response
|
11
|
+
message.response = self.response
|
12
|
+
end
|
13
|
+
|
14
|
+
def response
|
15
|
+
response_arr = @response.body.split(/[\r\n]+/)
|
16
|
+
hash = {}
|
17
|
+
hash[:uuid] = response_arr.shift.gsub(/\[|\]/, '')
|
18
|
+
response_arr.each do |value|
|
19
|
+
keyValue = value.split('=')
|
20
|
+
hash[keyValue[0].underscore.to_sym] = value[1]
|
21
|
+
end
|
22
|
+
hash
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_h
|
26
|
+
{
|
27
|
+
dstaddr: message.to,
|
28
|
+
dlvtime: message.deliver_at || '',
|
29
|
+
smbody: message.content,
|
30
|
+
clientid: message.uuid
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mitake
|
2
|
+
class Api < SMSProvider::Base
|
3
|
+
attr_reader :message, :settings
|
4
|
+
|
5
|
+
def initialize(settings)
|
6
|
+
@settings = settings
|
7
|
+
@url = settings[:url]
|
8
|
+
@username = settings[:username]
|
9
|
+
@password = settings[:password]
|
10
|
+
@callback_url = settings[:callback_url]
|
11
|
+
end
|
12
|
+
|
13
|
+
def deliver!(message)
|
14
|
+
@message = message
|
15
|
+
client = Client.new(url: @url, username: @username, password: @password)
|
16
|
+
client.send_message(message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/mitake_api.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mitake_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arthur Li
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: action_message_texter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.0.0
|
55
|
+
description: Mitake Api SMS for Ruby on Rails
|
56
|
+
email:
|
57
|
+
- z22919456@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/mitake_api.rb
|
66
|
+
- lib/mitake_api/client.rb
|
67
|
+
- lib/mitake_api/message.rb
|
68
|
+
- lib/mitake_api/railtie.rb
|
69
|
+
- lib/mitake_api/sms_provider.rb
|
70
|
+
- lib/mitake_api/version.rb
|
71
|
+
homepage: http://github.com/z22919456/mitake_api
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata:
|
75
|
+
homepage_uri: http://github.com/z22919456/mitake_api
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubygems_version: 3.1.6
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Mitake Api SMS for Ruby on Rails
|
95
|
+
test_files: []
|