gm-luosimao 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +10 -0
- data/lib/luosimao.rb +20 -0
- data/lib/luosimao/message.rb +43 -0
- data/lib/luosimao/version.rb +3 -0
- data/lib/test/test_luosimao.rb +45 -0
- data/luosimao.gemspec +23 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a78947c2ba20261b182d553223f975a3d64c128
|
4
|
+
data.tar.gz: b38841956125fc39fe3a091abbcfdaceeea0429e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 520fdbf29fc41f14aaad2b8c37652e561da05666cdce36b498fc466be9bfd08bdb3e2fab37bf5146846887374644ba98da7638f614edc9a0296d78a422310044
|
7
|
+
data.tar.gz: e9285deceaac361431c722bca7ca6550f13ea4bc0ee2bb94378f6872e806d8811b84ff348f88cde1ce9ff1904bb25656764b02abe133b59d9c227f46f00eef69
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Villins
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Luosimao
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gm-luosimao'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gm-luosimao
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
### Config
|
23
|
+
```ruby
|
24
|
+
Luosimao.username = "yyc"
|
25
|
+
Luosimao.key = "api-key"
|
26
|
+
Luosimao.brand = "【有演出】"
|
27
|
+
```
|
28
|
+
### Send message
|
29
|
+
```ruby
|
30
|
+
Luosimao::Message.to "10086", "hello world!"
|
31
|
+
```
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/[my-github-username]/luosimao/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/luosimao.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "luosimao/version"
|
2
|
+
require "luosimao/message"
|
3
|
+
|
4
|
+
module Luosimao
|
5
|
+
class << self
|
6
|
+
attr_accessor :username, :key, :brand
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.send_to(phone, content)
|
10
|
+
Message.to(phone, content)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.send_to!(phone, content)
|
14
|
+
Message.to!(phone, content)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.deposit_check
|
18
|
+
Message.deposit_check
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module Luosimao
|
6
|
+
module Message
|
7
|
+
SEND_URL = "https://sms-api.luosimao.com/v1/send.json"
|
8
|
+
DEPOSIT_URL = "https://sms-api.luosimao.com/v1/status.json"
|
9
|
+
|
10
|
+
class RequestException < StandardError; end
|
11
|
+
|
12
|
+
def self.to(phone, content)
|
13
|
+
url = URI.parse SEND_URL
|
14
|
+
post = Net::HTTP::Post.new(url.path)
|
15
|
+
post.basic_auth(Luosimao.username, "key-#{Luosimao.key}")
|
16
|
+
post.set_form_data(mobile: phone, message: "#{content} #{Luosimao.brand}")
|
17
|
+
|
18
|
+
https = Net::HTTP.new(url.host, url.port)
|
19
|
+
https.use_ssl = true
|
20
|
+
https.read_timeout = 5
|
21
|
+
https.open_timeout = 5
|
22
|
+
response = https.start {|socket| socket.request(post)}
|
23
|
+
JSON.parse response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.to!(phone, content)
|
27
|
+
json = to(phone, content)
|
28
|
+
json['error'] == 0 || raise(RequestException.new(json))
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.deposit_check
|
32
|
+
uri = URI.parse DEPOSIT_URL
|
33
|
+
req = Net::HTTP::Get.new uri
|
34
|
+
req.basic_auth(Luosimao.username, Luosimao.key)
|
35
|
+
|
36
|
+
res = Net::HTTP.start(uri.host, uri.port,
|
37
|
+
:use_ssl => uri.scheme == 'https') do |http|
|
38
|
+
http.request req
|
39
|
+
end
|
40
|
+
JSON.parse res.body
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require 'luosimao'
|
4
|
+
|
5
|
+
class LuosimaoTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Luosimao.username = "your_username"
|
8
|
+
Luosimao.key = "your_key"
|
9
|
+
Luosimao.brand = "your_brand"
|
10
|
+
@right_phone = "10086"
|
11
|
+
@wrong_phone = "020"
|
12
|
+
@right_msg = "hello world"
|
13
|
+
@empty_msg = ""
|
14
|
+
@sensitive_msg = "共产党"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_send_to_wrong_phone
|
18
|
+
assert_equal Luosimao::Message.to(@wrong_phone, @right_msg)["error"], -40
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_send_right_message
|
22
|
+
assert_equal Luosimao::Message.to(@right_phone, @right_msg),
|
23
|
+
{"error" => 0, "msg" => "ok"}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_send_empty_message
|
27
|
+
temp = Luosimao.brand
|
28
|
+
Luosimao.brand = ''
|
29
|
+
assert_equal Luosimao::Message.to(@right_phone, @empty_msg)["error"], -30
|
30
|
+
Luosimao.brand = temp
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_send_sensitive_message
|
34
|
+
assert_equal Luosimao::Message.to(@right_phone, @sensitive_msg)["error"], -31
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_check_deposit
|
38
|
+
assert_equal Luosimao::Message.deposit_check["error"], 0
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_fail_check_deposit
|
42
|
+
Luosimao.key = "testkey"
|
43
|
+
assert_equal Luosimao::Message.deposit_check["error"], -10
|
44
|
+
end
|
45
|
+
end
|
data/luosimao.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'luosimao/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gm-luosimao"
|
8
|
+
spec.version = Luosimao::VERSION
|
9
|
+
spec.authors = ["HungYuHei"]
|
10
|
+
spec.email = ["kongruxi@gmail.com"]
|
11
|
+
spec.summary = %q{ a warpper of luosimao send message }
|
12
|
+
spec.description = %q{ a warpper of luosimao send message }
|
13
|
+
spec.homepage = "https://github.com/GaiaMagic/luosimao"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gm-luosimao
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- HungYuHei
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-04 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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
|
+
description: " a warpper of luosimao send message "
|
42
|
+
email:
|
43
|
+
- kongruxi@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/luosimao.rb
|
54
|
+
- lib/luosimao/message.rb
|
55
|
+
- lib/luosimao/version.rb
|
56
|
+
- lib/test/test_luosimao.rb
|
57
|
+
- luosimao.gemspec
|
58
|
+
homepage: https://github.com/GaiaMagic/luosimao
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: a warpper of luosimao send message
|
82
|
+
test_files: []
|