neixin 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neixin.rb +46 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bff60bdc6ed66246e5a273e30d66412253ea65a
|
4
|
+
data.tar.gz: 397466dbde0268472142af9c427e39202790ca40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f793f61589135b40ce1652e35573670ca233789af0a082d0fff419ab02e7c33dff6d4aa16d7624c562827aac833a1f003bd4083d821e197e8431bdfe0e7b7ae
|
7
|
+
data.tar.gz: 80b7bf1b52590268a8c5ad974eff8653df77e94c702661964178815ceea7602d367193ae47e00cf48138b82585ceccf4ab01d7260e16719a20a248b6cb40b0f7
|
data/lib/neixin.rb
ADDED
@@ -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.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
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
|