getui 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 224ec1a371629bee26aee6b16e15143bf4eab917
4
- data.tar.gz: 4584a04d3068c8fc015fca9022e402225fab3c3f
3
+ metadata.gz: b771a3047464032f2e4b67ef3fdd8635db29b438
4
+ data.tar.gz: 06f8d4f27d256a0c3052451971756d8c3bf2d2f4
5
5
  SHA512:
6
- metadata.gz: bc104185a193df6568b1637317d6e63feadafb6aaa5fa595800ae565f9426df7c840ba4560932c5ba8f4e745791705aa0f68ddaee58bfa9de60312c5764d69bd
7
- data.tar.gz: 6541da6b2b4d2daf9679d0f96b6ac0489954388e6b382d19ebf61063e6f350e7b2f80f1192a62a8dcd14e4eae3ee3f5102fffa4981f9d82dd2e94baad6203e50
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.request(url, params = {})
10
+ def self.post(url, params = {})
11
11
  uri = URI(url)
12
- req = Getui::Request.new(uri)
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
@@ -1,3 +1,3 @@
1
1
  module Getui
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.request("https://restapi.getui.com/v1/#{Getui.app_id}/push_single", json)
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.request("https://restapi.getui.com/v1/#{Getui.app_id}/save_list_body", json)
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.request("https://restapi.getui.com/v1/#{Getui.app_id}/push_list", json)
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.request("https://restapi.getui.com/v1/#{Getui.app_id}/push_app", json)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - xxy