baidusms 0.0.1
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 +7 -0
- data/README.md +29 -0
- data/lib/baidusms/client.rb +45 -0
- data/lib/baidusms/version.rb +3 -0
- data/lib/baidusms.rb +8 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 610869d7af34278e968fe30e1eae60f27c02658c
|
|
4
|
+
data.tar.gz: eb0034e0887b3f278611e15a9e72b630e038491c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3841f73b72a90d3e34b0e7e960a2fa6270acf8483913a18e059f605c1c9b5ed0d42306bfac790a17f298f4966bae594ecd8d80c7739ce230acb0e06c3d3b5193
|
|
7
|
+
data.tar.gz: 727430c716f00c7d44cdd042161089c22339478e58c9dea0aaf4a9e9a3a1b782049aab0fe051fcada65bb41efe5b29c07f62102bb97a2817c16b9d9665810975
|
data/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Baidusms
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'baidusms'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install baidusms
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create new Pull Request
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'pp'
|
|
4
|
+
|
|
5
|
+
module Baidusms
|
|
6
|
+
class Client
|
|
7
|
+
def initialize(attrs={})
|
|
8
|
+
@username = attrs[:username]
|
|
9
|
+
@password = attrs[:password]
|
|
10
|
+
@token = attrs[:token]
|
|
11
|
+
@debug = attrs[:debug]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def call(service,method,body=nil,base_uri='https://api.baidu.com/json/sms/v3')
|
|
15
|
+
message = {
|
|
16
|
+
:header => {
|
|
17
|
+
:username => @username,
|
|
18
|
+
:token => @token,
|
|
19
|
+
:password => @password
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
message[:body] = body unless body.nil?
|
|
23
|
+
pp message if @debug
|
|
24
|
+
|
|
25
|
+
response = {}
|
|
26
|
+
loop do
|
|
27
|
+
response = HTTParty.post("#{base_uri}/#{service}/#{method}",:body => JSON(message), :headers => {'content-type' => 'application/json;charset=utf-8'})
|
|
28
|
+
pp response if @debug
|
|
29
|
+
|
|
30
|
+
break if response['header']['desc'] == 'success'
|
|
31
|
+
break unless [8904].include? response['header']['failures'][0]['code']
|
|
32
|
+
|
|
33
|
+
sleep(10)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
response
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def download(file_path,local_file=nil)
|
|
40
|
+
file = HTTParty.get(file_path).body.encode('UTF-8','GBK')
|
|
41
|
+
open(local_file,'w').puts file unless local_file.nil?
|
|
42
|
+
file
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/baidusms.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: baidusms
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- MingQian Zhang
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-06-03 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.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: httparty
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: Baidu SMS API Client.
|
|
56
|
+
email:
|
|
57
|
+
- zmingqian@qq.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- lib/baidusms/client.rb
|
|
63
|
+
- lib/baidusms/version.rb
|
|
64
|
+
- lib/baidusms.rb
|
|
65
|
+
- README.md
|
|
66
|
+
homepage: https://github.com/semseo/baidusms
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
metadata: {}
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - '>='
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - '>='
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
requirements: []
|
|
85
|
+
rubyforge_project:
|
|
86
|
+
rubygems_version: 2.0.0
|
|
87
|
+
signing_key:
|
|
88
|
+
specification_version: 4
|
|
89
|
+
summary: Call Baidu SMS JSON API.
|
|
90
|
+
test_files: []
|