emay_soap 0.0.1
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/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +4 -0
- data/emay_soap.gemspec +26 -0
- data/lib/emay_soap/client.rb +89 -0
- data/lib/emay_soap/configurable.rb +30 -0
- data/lib/emay_soap/version.rb +3 -0
- data/lib/emay_soap.rb +14 -0
- data/spec/emay_soap/client_spec.rb +17 -0
- data/spec/emay_soap/configurable_spec.rb +17 -0
- data/spec/emay_soap_spec.rb +18 -0
- data/spec/spec_helper.rb +12 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adaa820fd874c6b80d160e11ee8e7ea901afa00e
|
4
|
+
data.tar.gz: 89e3d736557bfb08ba5aa9695c1d7b8da538691f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef672da2267802781afabf215f8fb6d417562eb466d231f911c49cee233cb01abf2dd92208a16578f2bcc49f6f255bc75ae1a9d9888f3710616025e29e89d28b
|
7
|
+
data.tar.gz: 4a86710eb5f230913e5af26ef2b3ae9325750f4b37f98f03962bb6040ca53e867e03611b083a5630c0a7cc9e7c2a98458dfe4cc9cb684fed63c7f2cfcaa3a280
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Yuan He
|
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,72 @@
|
|
1
|
+
# EmaySoap
|
2
|
+
|
3
|
+
Made easy to use Emay(http://www.emay.cn/) to send sms in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'emay_soap'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install emay_soap
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
#### Setup
|
24
|
+
```ruby
|
25
|
+
# Provide authentication credentials
|
26
|
+
EmaySoap.setup do |c|
|
27
|
+
c.cdkey = 'yourcdkey'
|
28
|
+
c.key = 'yourkeywant to use' # max length 15
|
29
|
+
c.password = 'yourpassword'
|
30
|
+
end
|
31
|
+
|
32
|
+
client = EmaySoap.client
|
33
|
+
```
|
34
|
+
|
35
|
+
or
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# Provide authentication credentials
|
39
|
+
client = EmaySoap::Client.new(cdkey: 'yourcdkey, key: 'yoursessionkey', password: 'yourpassword')
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Play with API
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# Emay requires you register your CD_KEY before send SMS
|
46
|
+
client.regist_ex
|
47
|
+
|
48
|
+
# List all APIs
|
49
|
+
client.operations
|
50
|
+
|
51
|
+
# Query Balance
|
52
|
+
client.get_balance
|
53
|
+
|
54
|
+
# Query each fee of SMS
|
55
|
+
client.get_balance
|
56
|
+
|
57
|
+
# Send SMS
|
58
|
+
client.send_sms
|
59
|
+
|
60
|
+
# change your session key
|
61
|
+
client.logout
|
62
|
+
client.key = 'yournewkey'
|
63
|
+
client.regist_ex
|
64
|
+
```
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it ( https://github.com/lenage/emay_soap/fork )
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/emay_soap.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'emay_soap/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "emay_soap"
|
8
|
+
spec.version = EmaySoap::VERSION
|
9
|
+
spec.authors = ["Yuan He"]
|
10
|
+
spec.email = ["lendage@gmail.com"]
|
11
|
+
spec.summary = %q{Emay SOAP API wrapper in Ruby.}
|
12
|
+
spec.description = %q{Made easy to use Emay(http://www.emay.cn/) to send sms in Ruby.}
|
13
|
+
spec.homepage = "https://github.com/lenage/emay_soap"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.add_runtime_dependency 'savon', '~> 2.8'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
26
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "savon"
|
2
|
+
require "emay_soap/configurable"
|
3
|
+
|
4
|
+
module EmaySoap
|
5
|
+
class Client
|
6
|
+
include EmaySoap::Configurable
|
7
|
+
|
8
|
+
ENDPOINT = 'http://sdk4report.eucp.b2m.cn:8080/sdk/SDKService?wsdl'.freeze
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
EmaySoap::Configurable.setup_keys.each do |k|
|
12
|
+
instance_variable_set(:"@#{k}", options[k] || EmaySoap::Configurable.default_options[k])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def operations
|
17
|
+
savon.operations
|
18
|
+
end
|
19
|
+
|
20
|
+
def operation(action)
|
21
|
+
savon.operation(action)
|
22
|
+
end
|
23
|
+
|
24
|
+
# register cdkey
|
25
|
+
def regist_ex
|
26
|
+
call(:regist_ex, arg2: @password)
|
27
|
+
end
|
28
|
+
|
29
|
+
def regist_detail_info(options)
|
30
|
+
raise 'Detail info required' if options.blank?
|
31
|
+
msg = { arg1: options[:e_name], arg2: options[:link_man],
|
32
|
+
arg4: options[:phone_num], arg5: options[:mobile],
|
33
|
+
arg6: options[:email], arg7: options[:fax],
|
34
|
+
arg8: options[:address], arg9: options[:postcode] }
|
35
|
+
call(:regist_detail_info, msg)
|
36
|
+
end
|
37
|
+
|
38
|
+
def charge_up(cardno, cardpass)
|
39
|
+
call(:charge_up, arg2: cardno, arg3: cardpass)
|
40
|
+
end
|
41
|
+
|
42
|
+
# send SMS out
|
43
|
+
# @params mobiles [String/Array] List of mobiles which send sms, max to 200
|
44
|
+
# content [String], content of sms
|
45
|
+
# options [Hash]
|
46
|
+
# :send_at [Time] set a time to send sms, send immediately if nil
|
47
|
+
# :kind [String] custom SMS content kind
|
48
|
+
# :priority [Integer] SMS priority, from 1 to 5
|
49
|
+
# :id SMS ID, [Integer] you can set a SMS ID for your content
|
50
|
+
def send_sms(mobiles, content, options = {})
|
51
|
+
send_at = format_sent_at(options[:send_at]) unless options[:send_at].blank?
|
52
|
+
mobiles = mobiles.is_a?(String) ? [mobiles] : mobiles
|
53
|
+
msg = { arg2: send_at, arg3: mobiles, arg4: content, arg5: options[:kind], arg6: nil, arg7: options[:priority], arg8: options[:id] }
|
54
|
+
call(:send_sms, msg)
|
55
|
+
end
|
56
|
+
|
57
|
+
def serial_pwd_upd(new_password)
|
58
|
+
call(:serial_pwd_upd, arg2: @password, arg3: new_password)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Create all methods via method_missing,
|
62
|
+
def method_missing(method, *args)
|
63
|
+
ary = args.each_with_index.inject([]) do |r, (e, i)|
|
64
|
+
r << ["arg#{i+2}".to_sym, e]
|
65
|
+
end
|
66
|
+
message = Hash[ary]
|
67
|
+
if operations.include?(method)
|
68
|
+
call(method, message)
|
69
|
+
else
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def savon
|
77
|
+
@client ||= Savon.client(wsdl: ENDPOINT)
|
78
|
+
end
|
79
|
+
|
80
|
+
def call(action, message)
|
81
|
+
msg = { arg0: @cdkey, arg1: @key }.merge message
|
82
|
+
savon.call(action, message: msg).body
|
83
|
+
end
|
84
|
+
|
85
|
+
def format_sent_at send_at
|
86
|
+
send_at.strftime('%Y%m%d%H%M%S')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module EmaySoap
|
2
|
+
module Configurable
|
3
|
+
attr_accessor :cdkey, :key, :password
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def default_options
|
7
|
+
{
|
8
|
+
cdkey: ENV['EMAY_CDKEY'],
|
9
|
+
key: ENV['EMAY_KEY'], # session key, max length is 15
|
10
|
+
password: ENV['EMAY_PASSWORD']
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup_keys
|
15
|
+
@setup_keys ||= [:cdkey, :key, :password]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def options
|
20
|
+
ary = EmaySoap::Configurable.setup_keys.map do |key|
|
21
|
+
[key, send(key)]
|
22
|
+
end
|
23
|
+
Hash[ary]
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup
|
27
|
+
yield self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/emay_soap.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EmaySoap::Client do
|
4
|
+
it '#operations' do
|
5
|
+
expect(EmaySoap::Client.new.operations).to be_kind_of Array
|
6
|
+
end
|
7
|
+
|
8
|
+
it '#operation' do
|
9
|
+
expect(EmaySoap::Client.new.operation(:get_balance)).to be_kind_of Savon::Operation
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'method_missing' do
|
13
|
+
client = EmaySoap.client
|
14
|
+
expect(client.get_balance).to be_kind_of Hash
|
15
|
+
expect(client.get_balance[:get_balance_response]).to be_truthy
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EmaySoap::Configurable do
|
4
|
+
it '.setup_keys' do
|
5
|
+
expect(EmaySoap::Configurable.setup_keys).to include(:cdkey)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'EmaySoap.setup' do
|
9
|
+
EmaySoap.setup do |c|
|
10
|
+
c.cdkey = 'cdkey'
|
11
|
+
c.key = 'key'
|
12
|
+
c.password = 'password'
|
13
|
+
end
|
14
|
+
expect(EmaySoap.options).to be_kind_of Hash
|
15
|
+
expect(EmaySoap.options[:cdkey]).to eq 'cdkey'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EmaySoap do
|
4
|
+
context '.client' do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
EmaySoap.setup do |c|
|
8
|
+
c.cdkey = 'some-cd-key'
|
9
|
+
c.key = 'hello'
|
10
|
+
c.password = 'world'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'create an EmaySoap::Client' do
|
15
|
+
expect(EmaySoap.client).to be_kind_of EmaySoap::Client
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
require 'emay_soap'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
+
end
|
9
|
+
config.mock_with :rspec do |mocks|
|
10
|
+
mocks.verify_partial_doubles = true
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: emay_soap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuan He
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: savon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.1'
|
69
|
+
description: Made easy to use Emay(http://www.emay.cn/) to send sms in Ruby.
|
70
|
+
email:
|
71
|
+
- lendage@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- emay_soap.gemspec
|
83
|
+
- lib/emay_soap.rb
|
84
|
+
- lib/emay_soap/client.rb
|
85
|
+
- lib/emay_soap/configurable.rb
|
86
|
+
- lib/emay_soap/version.rb
|
87
|
+
- spec/emay_soap/client_spec.rb
|
88
|
+
- spec/emay_soap/configurable_spec.rb
|
89
|
+
- spec/emay_soap_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: https://github.com/lenage/emay_soap
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Emay SOAP API wrapper in Ruby.
|
115
|
+
test_files:
|
116
|
+
- spec/emay_soap/client_spec.rb
|
117
|
+
- spec/emay_soap/configurable_spec.rb
|
118
|
+
- spec/emay_soap_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
has_rdoc:
|