neixin 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/neixin.rb +46 -0
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69c2a59a8ac3d0c9ee11865436b60fa5599f8d3c
4
- data.tar.gz: 819200e9aac62f87b26326727569b443c7c8de72
3
+ metadata.gz: 3bff60bdc6ed66246e5a273e30d66412253ea65a
4
+ data.tar.gz: 397466dbde0268472142af9c427e39202790ca40
5
5
  SHA512:
6
- metadata.gz: cf5698dc31f3cf7c3bb840e03a255a7b48b999a54e4eb4716fafcf4f284a452f4c4a279ca3163016cb704b5e8ae1c0ff24d6016f33528ba432429ef1686ef8b7
7
- data.tar.gz: ec59be46f773db0cd862f159cd429fb510f8efc1dfbdb914ab6f76d50c03cfaf2b8dc4349c9fd8c419cef592cda4e0598c9c914ab7db44a420b6dfcff0346900
6
+ metadata.gz: 1f793f61589135b40ce1652e35573670ca233789af0a082d0fff419ab02e7c33dff6d4aa16d7624c562827aac833a1f003bd4083d821e197e8431bdfe0e7b7ae
7
+ data.tar.gz: 80b7bf1b52590268a8c5ad974eff8653df77e94c702661964178815ceea7602d367193ae47e00cf48138b82585ceccf4ab01d7260e16719a20a248b6cb40b0f7
@@ -0,0 +1,46 @@
1
+ require 'uri'
2
+ require 'json'
3
+ require 'base64'
4
+ require 'openssl'
5
+ require 'net/http'
6
+
7
+ class HTTPClient
8
+ def initialize(params)
9
+ @appkey = params[:appkey]
10
+ @secret = params[:secret]
11
+ end
12
+ def request(path, body)
13
+ headers = self.sign(path)
14
+ http = Net::HTTP.new("dxw-in.sankuai.com")
15
+ http.request_put(path, body.to_json, headers)
16
+ end
17
+ def sign(path)
18
+ timestamp = Time.now.gmtime.strftime('%a, %d %b %Y %H:%M:%S GMT')
19
+ req = "PUT #{path}\n#{timestamp}"
20
+ hash = OpenSSL::HMAC.digest('sha1', @secret, req)
21
+ auth = Base64.encode64 hash
22
+ {
23
+ "Date": timestamp,
24
+ "Authorization": "MWS #{@appkey}:#{auth}",
25
+ "Content-Type": "application/json"
26
+ }
27
+ end
28
+ end
29
+
30
+ class Neixin < HTTPClient
31
+ def initialize(params)
32
+ @id = params[:id]
33
+ super params
34
+ end
35
+ def send(message, receivers)
36
+ receivers = receivers.split(",") unless receivers.kind_of?(Array)
37
+ body = { text: message }
38
+ data = {
39
+ "fromUid" => @id,
40
+ "messageType" => 'text',
41
+ "receivers" => receivers,
42
+ "body" => body
43
+ }
44
+ self.request('/api/pub/push', data)
45
+ end
46
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neixin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
- - lsong
7
+ - Lsong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -15,7 +15,8 @@ email: hi@lsong.org
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
- files: []
18
+ files:
19
+ - lib/neixin.rb
19
20
  homepage: https://github.com/song940/ruby-neixin
20
21
  licenses:
21
22
  - MIT