aliyun-cloud_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
+ SHA1:
3
+ metadata.gz: c00c0863180ad681f861b6213c60d4a3ea5540d1
4
+ data.tar.gz: b685fc773e38d4448e55e5ab8beee4124cce22f4
5
+ SHA512:
6
+ metadata.gz: 514416b3e09278b240a063416beb3550195ad0af7c0290dc6850491a98163f633d7ba69eb4ecf9d36fc82559ccae1a1fd80fd197fe5d91354ba4f11c49557ce5
7
+ data.tar.gz: ade522bbe91d14bdce4e9eefa1626b491bd17eccc582dc3fd524516f62e8c2f4b1529aa584882cf79684afb07579c70e49938b10e9cb5c89ab709386247f9524
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tsuijy@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aliyun-cloud_sms.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jeremy Cui
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,64 @@
1
+ # Aliyun::CloudSms
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/aliyun/cloud_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
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'aliyun-cloud_sms'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install aliyun-cloud_sms
22
+
23
+ ## Usage
24
+
25
+ ### Global message client
26
+ Create file aliyun-cloud_sms.rb to your config/initializers.
27
+ ``` ruby
28
+ Aliyun::CloudSms.configure do |config|
29
+ config.access_key_secret = 'your key secret'
30
+ config.access_key_id = 'your key id'
31
+ config.sign_name = 'your sign name'
32
+ end
33
+
34
+ ```
35
+ If you want to send message, Aliyun::CloudSms.send_msg(mobile, template_code, template_param).
36
+ e.g.
37
+ ```ruby
38
+ Aliyun::CloudSms.send_msg('13800000000', 'SMS_80190090', {"customer": "jere"} )
39
+ ```
40
+ The param is not a string, is a hash instead.
41
+
42
+ ### Multiple account support
43
+ If you want to send message with multiple sign name, you can build your own message sender client.
44
+ ```ruby
45
+ client = Aliyun::CloudSms.new('your_access_key_id', 'your_access_key_secret', 'your_sign_name')
46
+
47
+ client.send_msg('13800000000', 'SMS_80190090', {"customer": "jere"} )
48
+ ```
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aliyun-cloud_sms. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
59
+
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
64
+
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
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aliyun/cloud_sms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aliyun-cloud_sms"
8
+ spec.version = Aliyun::CloudSms::VERSION
9
+ spec.authors = ["Jeremy Cui"]
10
+ spec.email = ["tsuijy@gmail.com"]
11
+
12
+ spec.summary = %q{Aliyun SMS service gem.}
13
+ spec.description = %q{Send short message via aliyun cloud service.}
14
+ spec.homepage = "https://github.com/jerecui/aliyun-cloud_sms"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "uuid", ">=2.0", "<6.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aliyun/cloud_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,78 @@
1
+ require 'uuid'
2
+ require 'json'
3
+ require 'cgi'
4
+ require 'openssl'
5
+ require 'base64'
6
+
7
+ module Aliyun::CloudSms
8
+ class Client
9
+ attr_accessor :access_key_id, :access_key_secret, :sign_name
10
+
11
+ def initialize(access_key_id, access_key_secret, sign_name)
12
+ self.access_key_id = access_key_id
13
+ self.access_key_secret = access_key_secret
14
+ self.sign_name = sign_name
15
+ end
16
+
17
+ SERVICE_URL = "http://dysmsapi.aliyuncs.com/"
18
+
19
+ def send_msg(mobile, template_code, template_param)
20
+ params = dynamic_params(mobile, template_code, template_param).merge(intrinsic_params)
21
+ q_without_sig = build_url(params)
22
+ q_full= "Signature=#{sign(q_without_sig)}&#{q_without_sig}"
23
+
24
+ begin
25
+ response = RestClient.get url
26
+ rescue RestClient::ExceptionWithResponse => e
27
+ Rails.logger.error(e.response) if defined? Rails
28
+ end
29
+ end
30
+
31
+ private
32
+ def dynamic_params(mobile, template_code, template_param)
33
+ {
34
+ :PhoneNumbers => mobile,
35
+ :TemplateCode => template_code,
36
+ :TemplateParam => template_param.to_json.to_s,
37
+ :Timestamp => timestamp,
38
+ :SignatureNonce => nonce,
39
+ }
40
+ end
41
+
42
+ def intrinsic_params
43
+ {
44
+ :AccessKeyId => self.access_key_id,
45
+ :SignName => self.sign_name,
46
+ :Action => Aliyun::CloudSms.action,
47
+ :Format => Aliyun::CloudSms.format,
48
+ :RegionId => Aliyun::CloudSms.region_id,
49
+ :SignatureMethod => Aliyun::CloudSms.signature_method,
50
+ :SignatureVersion => Aliyun::CloudSms.signature_version,
51
+ :Version => Aliyun::CloudSms.sms_version
52
+ }
53
+ end
54
+
55
+ def timestamp
56
+ Time.now.utc.strftime("%FT%TZ")
57
+ end
58
+
59
+ def nonce
60
+ UUID.generate
61
+ end
62
+
63
+ def build_url(hash)
64
+ hash.map{|k,v|"#{encode(k.to_s)}=#{encode(v.to_s)}"}.sort.join('&')
65
+ end
66
+
67
+ def encode(str)
68
+ CGI.escape(str)
69
+ end
70
+
71
+ def sign(str)
72
+ str = "GET&#{encode('/')}&#{encode(str)}"
73
+ ret = OpenSSL::HMAC.digest('sha1', "#{self.access_key_secret}&", str)
74
+ ret = Base64.encode64(ret)
75
+ encode(ret.chomp)
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,70 @@
1
+ module Aliyun::CloudSms
2
+ module Configure
3
+ @@action = "SendSms"
4
+ @@format = "JSON"
5
+ @@region_id = "cn-hangzhou"
6
+ @@signature_method = "HMAC-SHA1"
7
+ @@signature_version = "1.0"
8
+ @@sms_version = "2017-05-25"
9
+ @@access_key_id = ""
10
+ @@access_key_secret = ""
11
+ @@sign_name = ""
12
+
13
+
14
+ def configure
15
+ yield self if block_given?
16
+ end
17
+
18
+ def access_key_id=(id)
19
+ @@access_key_id = id
20
+ end
21
+
22
+ def access_key_secret=(secret)
23
+ @@access_key_secret = secret
24
+ end
25
+
26
+ def sign_name=(sign_name)
27
+ @@sign_name = sign_name
28
+ end
29
+
30
+ def action=(action)
31
+ @@action = action
32
+ end
33
+
34
+ def action
35
+ @@action
36
+ end
37
+
38
+ def format
39
+ @@format
40
+ end
41
+
42
+ def region_id
43
+ @@region_id
44
+ end
45
+
46
+ def signature_method
47
+ @@signature_method
48
+ end
49
+
50
+ def signature_version
51
+ @@signature_version
52
+ end
53
+
54
+ def sms_version
55
+ @@sms_version
56
+ end
57
+
58
+ def access_key_id
59
+ @@access_key_id
60
+ end
61
+
62
+ def access_key_secret
63
+ @@access_key_secret
64
+ end
65
+
66
+ def sign_name
67
+ @@sign_name
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module Aliyun
2
+ module CloudSms
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ require "aliyun/cloud_sms/version"
2
+ require 'aliyun/cloud_sms/configure'
3
+ require 'aliyun/cloud_sms/client'
4
+
5
+ module Aliyun
6
+ module CloudSms
7
+ extend Configure
8
+
9
+ def self.send_msg(mobile, template_code, template_param)
10
+ default_client.send_msg mobile, template_code, template_param
11
+ end
12
+
13
+ def self.client(access_key_id, access_key_secret, sign_name)
14
+ Aliyun::Client.new access_key_id, access_key_secret, sign_name
15
+ end
16
+
17
+ def self.default_client
18
+ Aliyun::CloudSms::Client.new Aliyun::CloudSms.access_key_id, Aliyun::CloudSms.access_key_secret, Aliyun::CloudSms.sign_name
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aliyun-cloud_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Cui
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: uuid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.14'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.14'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ description: Send short message via aliyun cloud service.
76
+ email:
77
+ - tsuijy@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".rspec"
84
+ - ".travis.yml"
85
+ - CODE_OF_CONDUCT.md
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - aliyun-cloud_sms.gemspec
91
+ - bin/console
92
+ - bin/setup
93
+ - lib/aliyun/cloud_sms.rb
94
+ - lib/aliyun/cloud_sms/client.rb
95
+ - lib/aliyun/cloud_sms/configure.rb
96
+ - lib/aliyun/cloud_sms/version.rb
97
+ homepage: https://github.com/jerecui/aliyun-cloud_sms
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.6.11
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Aliyun SMS service gem.
121
+ test_files: []