yunpian 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16054e8fc18e02867b7e651b2ec446bae36e9f91
4
- data.tar.gz: aa9361231742a6ba2adfd7171aa23b25bb3fb890
3
+ metadata.gz: b3f755e6dbb2d9fd42d398bcf0ecec6a1322329b
4
+ data.tar.gz: 699cfd0139bc34c7e4b04c2b68f6c98ca624cd0a
5
5
  SHA512:
6
- metadata.gz: 9bd63f6485835b055d5e33acf377524f992ac20f7e8224d247d8f350c3b90320d33ef48b403d228fba15062da0279b6a5874cfc6f55dd6c32aedbbd8763c3fad
7
- data.tar.gz: f324a18ee5e0eaee04421c8efc3a08f7646680474c051593c281330323b7a730b2da626b7567488841487b1dabcd821ad06b8c530747757efa8ad755150fcb32
6
+ metadata.gz: a2b4e51a143f2dee2fbeff5bd91dc0b58d3ce9d480ce15b4adaece5cc4381366e366c5712c6e8697e9e7dbc4d297f6d540698ef36b0550848b3556b048a2570d
7
+ data.tar.gz: b9e0449f262a48c579a4ee2cf95c21238a0bef64fb9ce65727b2f3a1200b32552b387cbd55029f1cd4985fcfa931273c050b22a39c7be02588bfb174ddf09739
data/README.md CHANGED
@@ -34,6 +34,11 @@ Yunpian.send_to('10086', '流量唔够用啊') # => { code: 0, msg: "OK", result
34
34
  Yunpian.send_to!('10086', '流量唔够用啊') # => will raise Yunpian::RequestException
35
35
  ```
36
36
 
37
+ ### Get account info
38
+ ```ruby
39
+ Yunpian.account_info # => {"code"=>0, "msg"=>"OK", "user"=>{...}}
40
+ ```
41
+
37
42
 
38
43
  ## Development
39
44
 
@@ -3,24 +3,17 @@ require 'json'
3
3
 
4
4
  module Yunpian
5
5
  class Request
6
- GATEWAY = 'http://yunpian.com/v1/sms/send.json'
7
-
8
- def initialize(recipients, content)
9
- @recipients = Array(recipients)
10
- @content = Yunpian.signature + content
6
+ def initialize(gateway, params)
7
+ @gateway = gateway
8
+ @params = params
11
9
  end
12
10
 
13
11
  def perform
14
- uri = URI(GATEWAY)
12
+ uri = URI(@gateway)
15
13
  req = Net::HTTP::Post.new(uri)
16
-
17
- req.set_form_data(
18
- apikey: Yunpian.apikey,
19
- mobile: @recipients.join(','),
20
- text: @content
21
- )
22
-
14
+ req.set_form_data(@params)
23
15
  timeout = Yunpian.timeout
16
+
24
17
  res = Net::HTTP.start(uri.hostname,
25
18
  uri.port,
26
19
  read_timeout: timeout,
@@ -33,7 +26,7 @@ module Yunpian
33
26
 
34
27
  def perform!
35
28
  json = perform
36
- json['code'] == 0 || raise(RequestException.new(json))
29
+ json['code'] == 0 ? json : raise(RequestException.new(json))
37
30
  end
38
31
  end
39
32
  end
@@ -1,3 +1,3 @@
1
1
  module Yunpian
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/yunpian.rb CHANGED
@@ -2,17 +2,34 @@ require 'yunpian/version'
2
2
  require 'yunpian/request'
3
3
 
4
4
  module Yunpian
5
+ SEND_GATEWAY = 'http://yunpian.com/v1/sms/send.json'
6
+ ACCOUNT_GATEWAY = 'http://yunpian.com/v1/user/get.json'
7
+
5
8
  @timeout = 5
6
9
 
7
10
  class << self
8
11
  attr_accessor :apikey, :signature, :timeout
9
12
 
10
13
  def send_to(recipients, content)
11
- Request.new(recipients, content).perform
14
+ params = {
15
+ apikey: Yunpian.apikey,
16
+ mobile: Array(recipients).join(','),
17
+ text: content
18
+ }
19
+ Request.new(SEND_GATEWAY, params).perform
12
20
  end
13
21
 
14
22
  def send_to!(recipients, content)
15
- Request.new(recipients, content).perform!
23
+ params = {
24
+ apikey: Yunpian.apikey,
25
+ mobile: Array(recipients).join(','),
26
+ text: content
27
+ }
28
+ Request.new(SEND_GATEWAY, params).perform!
29
+ end
30
+
31
+ def account_info
32
+ Request.new(ACCOUNT_GATEWAY, apikey: Yunpian.apikey).perform
16
33
  end
17
34
  end
18
35
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yunpian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HungYuHei
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-08 00:00:00.000000000 Z
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler