yunpiansms 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e0e7056a94ec81d61a56ff8b38d77c41dfc0a2c3
4
+ data.tar.gz: 684f24fa0ba6159b85cfff2b57ac232fc9c49c2f
5
+ SHA512:
6
+ metadata.gz: 230125dde1c80c07f58cb3826004a4f8aa2bc942ee27d7f8807d050b944078f7a58aacc2bff3631d2d852ead13bdb5e2db36f51b005b8701fddfe8c6955cc8e6
7
+ data.tar.gz: 939b4fa74dc1c37f49a2439bde242b60473a49cae61f5e1cdafc50d39bcb53dd996905614babc95c45350debe1205736c8d0908196e09a87a53cb395eb248317
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yunpiansms.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Yunpiansms
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/yunpiansms`. 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 'yunpiansms'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yunpiansms
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yunpiansms.
36
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yunpiansms"
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
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,3 @@
1
+ module Yunpiansms
2
+ VERSION = "1.0.1"
3
+ end
data/lib/yunpiansms.rb ADDED
@@ -0,0 +1,67 @@
1
+ require "yunpiansms/version"
2
+ require "yunpiansms/sms_resources"
3
+ require "yunpiansms/http_base"
4
+
5
+
6
+ module Yunpiansms
7
+ class Service
8
+ attr_accessor :apikey, :signature, :connection_adapter,:debug_flg
9
+
10
+ def initialize(apikey: "", signature: "", connection_adapter: :net_http, debug_flg: false)
11
+ @apikey = apikey
12
+ @signature = signature
13
+ @connection_adapter = connection_adapter
14
+ @debug_flg = debug_flg
15
+ end
16
+
17
+ def self.config
18
+ yield service = new; service
19
+ end
20
+
21
+ def send_to(content, mobiles = nil, signature = nil)
22
+ http.post(Yunpiansms::SmsResources::SEND_URL,params_data(content, mobiles , signature))
23
+ end
24
+
25
+ def tpl_send_to(content, mobiles = nil, tpl_id = nil, tpl_value=nil, signature = nil)
26
+ http.post(Yunpiansms::SmsResources::TPL_SEND_URL,params_data_tpl(content, mobiles, tpl_id,tpl_value,signature))
27
+ end
28
+
29
+ private
30
+
31
+ def params_data(content, mobiles, signature = nil)
32
+ content = format_content(content,mobiles)
33
+ content[:text] = "#{signature || @signature}#{content[:text]}"
34
+ content
35
+ end
36
+
37
+ def params_data_tpl(content, mobiles = nil, tpl_id = nil, tpl_value=nil, signature = nil)
38
+ content = format_content(content,mobiles)
39
+ content[:tpl_id] = tpl_id || content.detele(:tpl_id)
40
+ content[:tpl_value] = "#{signature || @signature}#{content[:text]}"
41
+ content
42
+ end
43
+
44
+ def http
45
+ host = Yunpiansms::SmsResources::SEND_DOMAIN
46
+ Yunpiansms::HttpBase.new(host, @connection_adapter)
47
+ end
48
+
49
+ def mobile_format(mobiles = nil)
50
+ if mobiles.is_a?(Array)
51
+ mobiles = Array(mobiles).join(',')
52
+ else
53
+ mobiles = mobiles
54
+ end
55
+ end
56
+
57
+ def format_content(content = {},mobiles)
58
+ params = {}
59
+ content.map do |k,v|
60
+ params["#{k}".to_sym] = v
61
+ end
62
+ params[:apikey] = params.delete(:apikey) || @apikey
63
+ params[:mobile] = mobile_format(mobiles || params[:mobile])
64
+ params
65
+ end
66
+ end
67
+ end
@@ -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 'yunpiansms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yunpiansms"
8
+ spec.version = Yunpiansms::VERSION
9
+ spec.authors = ["trycatch"]
10
+ spec.email = ["guoyoujin123@gmail.com"]
11
+ spec.summary = ["trycatch"]
12
+ spec.summary = %q{yunpian send sms Ruby Server SDK.}
13
+ spec.description = %q{yunpian send sms Ruby Server SDK.}
14
+ spec.homepage = "https://github.com/guoyoujin/xiaomipush."
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+ spec.add_runtime_dependency 'faraday'
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yunpiansms
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - trycatch
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
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
+ description: yunpian send sms Ruby Server SDK.
56
+ email:
57
+ - guoyoujin123@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - lib/yunpiansms.rb
69
+ - lib/yunpiansms/version.rb
70
+ - yunpiansms.gemspec
71
+ homepage: https://github.com/guoyoujin/xiaomipush.
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.4
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: yunpian send sms Ruby Server SDK.
95
+ test_files: []