txyun-sms 0.1.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: bfd220e0848b5365bb176c4ac7d7bc56993c012bc04bf3b4ba2eb091eb5b29e5
4
+ data.tar.gz: f86763638f34a4dcc0b06e9b6348d04bd8e0f2e9e7f9d63d85bbb87b8db46235
5
+ SHA512:
6
+ metadata.gz: 3cb37fd4fe938cb596b0f14c88baead3ee6f23141955f6c4639aaa9645dc753f137967d06720dad569368a5ab69655828464c48f48d332b54a6d91894792ccf7
7
+ data.tar.gz: 5dd94c56104af5de342fb34cc8fcf889169508306057f3453ab9c005bda6f7fe0a74e8ff73b4373e1439d671b68824e78c5f1177a0a7dcf23862fda1d451d555
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.4
7
+ before_install: gem install bundler -v 1.16.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in txyun-sms.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Txyun::Sms
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/txyun/sms`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ######warn: <font face="黑体" color=red>Only supported template send sms !</font>
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'txyun-sms'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install txyun-sms
24
+
25
+ # Usage
26
+
27
+ $ rails g txyun:sms:initializer
28
+
29
+ ## Configure
30
+
31
+ Txyun::Sms.configure do |config|
32
+ config.nationcode = ''
33
+ config.sign = ''
34
+ config.extend_code = ''
35
+ config.ext = ''
36
+ config.appkey = ''
37
+ config.sdkappid = ''
38
+ end
39
+
40
+ ## Example
41
+
42
+ Txyun::Sms.send('13133333333', tpl_id, '000000')
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/sunjirui/txyun-sms.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "txyun/sms"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ module Txyun::Sms
2
+ class InitializerGenerator < Rails::Generators::Base
3
+ desc "This generator creates an txyun-sms initializer file at config/initializers"
4
+ source_root File.expand_path('../../../../', __FILE__)
5
+ def create_initializer_file
6
+ path = "#{Rails.root}/config/initializers/txyun-sms.rb"
7
+ template 'templates/txyun-sms.rb', path
8
+
9
+ if File.exist?(path)
10
+ puts 'Skipping config/initializers/txyun-sms.rb creation, as file already exists!'
11
+ else
12
+ puts 'Adding txyun-sms default config file (config/initializers/txyun-sms.rb)...'
13
+ template 'templates/txyun-sms.rb', path
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ Txyun::Sms.configure do |config|
2
+ config.nationcode = ''
3
+ config.sign = ''
4
+ config.extend_code = ''
5
+ config.ext = ''
6
+ config.appkey = ''
7
+ config.sdkappid = ''
8
+ end
@@ -0,0 +1,5 @@
1
+ module Txyun
2
+ module Sms
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/txyun/sms.rb ADDED
@@ -0,0 +1,62 @@
1
+ require "txyun/sms/version"
2
+
3
+ module Txyun
4
+ module Sms
5
+ class Configuration
6
+ attr_accessor :nationcode, :sign, :time, :extend_code, :ext, :appkey, :sdkappid
7
+
8
+ def initialize
9
+ @nationcode = ''
10
+ @sign = ''
11
+ @time = ''
12
+ @extend_code = ''
13
+ @ext = ''
14
+ @appkey = ''
15
+ @sdkappid = ''
16
+ end
17
+ end
18
+
19
+ class << self
20
+ attr_writer :configuration
21
+
22
+ def configuration
23
+ @configuration ||= Configuration.new
24
+ end
25
+
26
+ def configure
27
+ yield(configuration)
28
+ end
29
+
30
+ def create_params(mobile_num, tpl_id, message_params, time_stamp, sig)
31
+ sms_params ={
32
+ 'tel' => {
33
+ 'nationcode' => configuration.nationcode,
34
+ 'mobile' => mobile_num
35
+ },
36
+ 'sign' => configuration.sign,
37
+ 'tpl_id' => tpl_id,
38
+ 'params' => [message_params],
39
+ 'sig' => "#{sig}",
40
+ 'time' => time_stamp,
41
+ 'extend' => configuration.extend_code,
42
+ 'ext' => configuration.ext
43
+ }
44
+ end
45
+
46
+ def send(mobile_num, template_code, message_params)
47
+ temp_string = rand(100000..999999)
48
+ current_url = "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=#{configuration.sdkappid}&random=#{temp_string}"
49
+
50
+ time_stamp = Time.now.to_i
51
+
52
+ wait_string = "appkey=#{configuration.appkey}&random=#{temp_string}&time=#{time_stamp}&mobile=#{mobile_num}"
53
+
54
+ sig = Digest::SHA256.hexdigest(wait_string)
55
+
56
+ sms_params = create_params(mobile_num, template_code, message_params, time_stamp, sig)
57
+
58
+ rpost = HTTParty.post(current_url, {body: sms_params.to_json})
59
+ end
60
+ end
61
+ end
62
+ end
data/txyun-sms.gemspec ADDED
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "txyun/sms/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "txyun-sms"
8
+ spec.version = Txyun::Sms::VERSION
9
+ spec.authors = ["sunjirui"]
10
+ spec.email = ["sunjirui1993@126.com"]
11
+
12
+ spec.summary = %q{A Ruby Gem for using tx-sms service.}
13
+ spec.description = %q{A Ruby Gem for using tx-sms service.}
14
+ spec.homepage = "https://gitlab.com/sunjirui/txyun-sms"
15
+ spec.license = "MIT"
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "https://gitlab.com/sunjirui/txyun-sms"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ # end
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.16"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "httparty", '~> 0.10', ">= 0.10.0"
38
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: txyun-sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sunjirui
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-14 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.10.0
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '0.10'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.10.0
75
+ description: A Ruby Gem for using tx-sms service.
76
+ email:
77
+ - sunjirui1993@126.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".rspec"
84
+ - ".travis.yml"
85
+ - Gemfile
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/generators/txyun/sms/initializer_generator.rb
91
+ - lib/templates/txyun-sms.rb
92
+ - lib/txyun/sms.rb
93
+ - lib/txyun/sms/version.rb
94
+ - txyun-sms.gemspec
95
+ homepage: https://gitlab.com/sunjirui/txyun-sms
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.7.7
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: A Ruby Gem for using tx-sms service.
119
+ test_files: []