mitake 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.overcommit.yml +34 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +62 -0
- data/LICENSE +21 -0
- data/README.md +101 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/mitake.rb +48 -0
- data/lib/mitake/api.rb +110 -0
- data/lib/mitake/api/base.rb +69 -0
- data/lib/mitake/api/get.rb +33 -0
- data/lib/mitake/api/post.rb +25 -0
- data/lib/mitake/balance.rb +35 -0
- data/lib/mitake/boolean.rb +24 -0
- data/lib/mitake/credential.rb +29 -0
- data/lib/mitake/message.rb +119 -0
- data/lib/mitake/model.rb +38 -0
- data/lib/mitake/model/accessor.rb +72 -0
- data/lib/mitake/model/attributes.rb +30 -0
- data/lib/mitake/parser.rb +60 -0
- data/lib/mitake/recipient.rb +16 -0
- data/lib/mitake/response.rb +21 -0
- data/lib/mitake/status.rb +21 -0
- data/lib/mitake/status_code.rb +9 -0
- data/lib/mitake/version.rb +5 -0
- data/mitake.gemspec +41 -0
- metadata +159 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mitake
|
4
|
+
module Model
|
5
|
+
# @since 0.1.0
|
6
|
+
# @api private
|
7
|
+
module Attributes
|
8
|
+
# @since 0.1.0
|
9
|
+
# @api private
|
10
|
+
def initialize(attributes = {})
|
11
|
+
assign_attributes(attributes)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Assign attribute by hash
|
15
|
+
#
|
16
|
+
# @param attributes [Hash] the attributes to assignment
|
17
|
+
#
|
18
|
+
# @since 0.1.0
|
19
|
+
def assign_attributes(attributes = {})
|
20
|
+
attributes.each do |key, value|
|
21
|
+
next unless self.class.attribute_names.include?(key.to_s)
|
22
|
+
next send("#{key}=", value) if respond_to?("#{key}=")
|
23
|
+
|
24
|
+
type = self.class.attributes[key.to_s]
|
25
|
+
instance_variable_set("@#{key}", self.class.cast(value, type))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mitake
|
4
|
+
# Parse API response
|
5
|
+
#
|
6
|
+
# @since 0.1.0
|
7
|
+
# @api private
|
8
|
+
class Parser
|
9
|
+
# @since 0.1.0
|
10
|
+
ID_MATCHER = /\[(\d+)\]/.freeze
|
11
|
+
|
12
|
+
# @since 0.1.0
|
13
|
+
attr_reader :items
|
14
|
+
|
15
|
+
# @since 0.1.0
|
16
|
+
# @api private
|
17
|
+
def initialize(response)
|
18
|
+
@response = response
|
19
|
+
@body = response.body
|
20
|
+
@items = []
|
21
|
+
end
|
22
|
+
|
23
|
+
# TODO: Improve response parser
|
24
|
+
#
|
25
|
+
# @since 0.1.0
|
26
|
+
# @api private
|
27
|
+
def parse
|
28
|
+
@body.each_line do |line|
|
29
|
+
next new_item(Regexp.last_match(1)) if line =~ ID_MATCHER
|
30
|
+
|
31
|
+
key, value = line.strip.split('=')
|
32
|
+
next if key.nil?
|
33
|
+
|
34
|
+
current[key] = value
|
35
|
+
end
|
36
|
+
@items << current
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# The current response object
|
42
|
+
#
|
43
|
+
# @since 0.1.0
|
44
|
+
# @api private
|
45
|
+
def current
|
46
|
+
@current ||= {}
|
47
|
+
end
|
48
|
+
|
49
|
+
# Create new response object
|
50
|
+
#
|
51
|
+
# @param id [String] the clientID
|
52
|
+
#
|
53
|
+
# @since 0.1.0
|
54
|
+
# @api private
|
55
|
+
def new_item(id = nil)
|
56
|
+
@items << @current unless @current.nil?
|
57
|
+
@current = id ? { 'source_id': id } : {}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mitake/api'
|
4
|
+
|
5
|
+
module Mitake
|
6
|
+
# The API response
|
7
|
+
#
|
8
|
+
# @since 0.1.0
|
9
|
+
class Response
|
10
|
+
include API
|
11
|
+
|
12
|
+
method 'Post'
|
13
|
+
path '/api/mtk/SmSend?CharsetURL=UTF8'
|
14
|
+
|
15
|
+
# @since 0.1.0
|
16
|
+
# @api private
|
17
|
+
def initialize(_response)
|
18
|
+
# TODO: Process API response
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mitake
|
4
|
+
# The message status
|
5
|
+
#
|
6
|
+
# @since 0.1.0
|
7
|
+
module Status
|
8
|
+
# @since 0.1.0
|
9
|
+
CODES = {
|
10
|
+
0 => '預約傳送中',
|
11
|
+
1 => '已送達業者',
|
12
|
+
2 => '已送達業者',
|
13
|
+
4 => '已送達手機',
|
14
|
+
5 => '內容有錯誤',
|
15
|
+
6 => '門號有錯誤',
|
16
|
+
7 => '簡訊已停用',
|
17
|
+
8 => '逾時無送達',
|
18
|
+
9 => '預約已取消'
|
19
|
+
}.freeze
|
20
|
+
end
|
21
|
+
end
|
data/mitake.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
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 'mitake/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'mitake'
|
9
|
+
spec.version = Mitake::VERSION
|
10
|
+
spec.authors = ['蒼時弦也']
|
11
|
+
spec.email = ['contact@frost.tw']
|
12
|
+
|
13
|
+
spec.summary = 'The Mitake SMS API Client'
|
14
|
+
spec.description = 'The Mitake SMS API Client'
|
15
|
+
spec.homepage = 'https://github.com/elct9620/mitake'
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/elct9620/mitake'
|
21
|
+
# spec.metadata["changelog_uri"] = "TODO"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in
|
25
|
+
# the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`
|
28
|
+
.split("\x0")
|
29
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = 'exe'
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
|
35
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
36
|
+
spec.add_development_dependency 'bundler-audit', '~> 0.6.1'
|
37
|
+
spec.add_development_dependency 'overcommit', '~> 0.51.0'
|
38
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
|
+
spec.add_development_dependency 'rubocop', '~> 0.76.0'
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mitake
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 蒼時弦也
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler-audit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.6.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: overcommit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.51.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.51.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.76.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.76.0
|
97
|
+
description: The Mitake SMS API Client
|
98
|
+
email:
|
99
|
+
- contact@frost.tw
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".overcommit.yml"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- lib/mitake.rb
|
117
|
+
- lib/mitake/api.rb
|
118
|
+
- lib/mitake/api/base.rb
|
119
|
+
- lib/mitake/api/get.rb
|
120
|
+
- lib/mitake/api/post.rb
|
121
|
+
- lib/mitake/balance.rb
|
122
|
+
- lib/mitake/boolean.rb
|
123
|
+
- lib/mitake/credential.rb
|
124
|
+
- lib/mitake/message.rb
|
125
|
+
- lib/mitake/model.rb
|
126
|
+
- lib/mitake/model/accessor.rb
|
127
|
+
- lib/mitake/model/attributes.rb
|
128
|
+
- lib/mitake/parser.rb
|
129
|
+
- lib/mitake/recipient.rb
|
130
|
+
- lib/mitake/response.rb
|
131
|
+
- lib/mitake/status.rb
|
132
|
+
- lib/mitake/status_code.rb
|
133
|
+
- lib/mitake/version.rb
|
134
|
+
- mitake.gemspec
|
135
|
+
homepage: https://github.com/elct9620/mitake
|
136
|
+
licenses: []
|
137
|
+
metadata:
|
138
|
+
homepage_uri: https://github.com/elct9620/mitake
|
139
|
+
source_code_uri: https://github.com/elct9620/mitake
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubygems_version: 3.0.3
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: The Mitake SMS API Client
|
159
|
+
test_files: []
|