getui 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/getui/request.rb +25 -3
- data/lib/getui/version.rb +1 -1
- data/lib/getui.rb +9 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b771a3047464032f2e4b67ef3fdd8635db29b438
|
4
|
+
data.tar.gz: 06f8d4f27d256a0c3052451971756d8c3bf2d2f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f0ed0eec672b60bd3a079051c4a65194893859876d5e95185a7bb52061597f662af569354dc181a884181468d608778e091b3b8d337aa106ee97bc11f045fbd
|
7
|
+
data.tar.gz: eb099e9f1e806661f648620149a85ba579ef8352d4ffe3440f35d35469be79093eaa9d34f0440c7439c6afd677b56385be213e4759fbd5d6f8a5b05efddd8e49
|
data/lib/getui/request.rb
CHANGED
@@ -1,21 +1,29 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'net/http'
|
3
3
|
require 'securerandom'
|
4
|
+
|
4
5
|
module Getui
|
5
6
|
class Request < Net::HTTPRequest
|
6
|
-
METHOD = 'POST'
|
7
7
|
REQUEST_HAS_BODY = true
|
8
8
|
RESPONSE_HAS_BODY = true
|
9
9
|
|
10
|
-
def self.
|
10
|
+
def self.post(url, params = {})
|
11
11
|
uri = URI(url)
|
12
|
-
req = Getui::
|
12
|
+
req = Getui::PostRequest.new(uri)
|
13
13
|
req.body = JSON.dump(params)
|
14
14
|
http = Net::HTTP.new(uri.hostname, uri.port)
|
15
15
|
http.use_ssl = (uri.scheme == "https")
|
16
16
|
http.request(req)
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.get(url, params = {})
|
20
|
+
uri = URI(url)
|
21
|
+
req = Getui::GetRequest.new(uri)
|
22
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
23
|
+
http.use_ssl = (uri.scheme == "https")
|
24
|
+
http.request(req)
|
25
|
+
end
|
26
|
+
|
19
27
|
def initialize(path)
|
20
28
|
super(path, {'Content-Type' => 'application/json', 'authtoken' => Getui::Auth.auth_token})
|
21
29
|
end
|
@@ -27,3 +35,17 @@ module Getui
|
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
38
|
+
|
39
|
+
|
40
|
+
module Getui
|
41
|
+
class PostRequest < Getui::Request
|
42
|
+
METHOD = 'POST'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
module Getui
|
48
|
+
class GetRequest < Getui::Request
|
49
|
+
METHOD = 'GET'
|
50
|
+
end
|
51
|
+
end
|
data/lib/getui/version.rb
CHANGED
data/lib/getui.rb
CHANGED
@@ -17,7 +17,7 @@ module Getui
|
|
17
17
|
json = message.as_json
|
18
18
|
json[:cid] = cid
|
19
19
|
json[:requestid] = SecureRandom.uuid[0..29]
|
20
|
-
resp = Getui::Request.
|
20
|
+
resp = Getui::Request.post("https://restapi.getui.com/v1/#{Getui.app_id}/push_single", json)
|
21
21
|
res = JSON.parse(resp.body)
|
22
22
|
raise Getui::PushError.new("#{resp.body}") unless res["result"] == "ok"
|
23
23
|
return res
|
@@ -25,7 +25,7 @@ module Getui
|
|
25
25
|
|
26
26
|
def save_list_body(message)
|
27
27
|
json = message.as_json
|
28
|
-
resp = Getui::Request.
|
28
|
+
resp = Getui::Request.post("https://restapi.getui.com/v1/#{Getui.app_id}/save_list_body", json)
|
29
29
|
res = JSON.parse(resp.body)
|
30
30
|
raise Getui::PushError.new("#{resp.body}") unless res["result"] == "ok"
|
31
31
|
return res["taskid"]
|
@@ -33,7 +33,7 @@ module Getui
|
|
33
33
|
|
34
34
|
def push_list(cids, taskid, need_detail = true)
|
35
35
|
json = {cid: cids, taskid: taskid, need_detail: need_detail}
|
36
|
-
resp = Getui::Request.
|
36
|
+
resp = Getui::Request.post("https://restapi.getui.com/v1/#{Getui.app_id}/push_list", json)
|
37
37
|
res = JSON.parse(resp.body)
|
38
38
|
raise Getui::PushError.new("#{resp.body}") unless res["result"] == "ok"
|
39
39
|
res
|
@@ -42,12 +42,17 @@ module Getui
|
|
42
42
|
def push_app(message)
|
43
43
|
json = message.as_json
|
44
44
|
json[:requestid] = SecureRandom.uuid[0..29]
|
45
|
-
resp = Getui::Request.
|
45
|
+
resp = Getui::Request.post("https://restapi.getui.com/v1/#{Getui.app_id}/push_app", json)
|
46
46
|
res = JSON.parse(resp.body)
|
47
47
|
raise Getui::PushError.new("#{resp.body}") unless res["result"] == "ok"
|
48
48
|
res
|
49
49
|
end
|
50
50
|
|
51
|
+
def user_status(cid)
|
52
|
+
resp = Getui::Request.get("https://restapi.getui.com/v1/#{Getui.app_id}/user_status/#{cid}")
|
53
|
+
JSON.parse(resp.body)
|
54
|
+
end
|
55
|
+
|
51
56
|
def cache_backend
|
52
57
|
if defined? Rails
|
53
58
|
@cache_backend ||= Rails.cache
|