repro-api-client 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 +4 -4
- data/lib/repro/api/client/version.rb +2 -2
- data/lib/repro/api/client.rb +62 -76
- data/repro-api-client.gemspec +1 -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: 2df819152eca29047156efb357b852b32e741e19
|
4
|
+
data.tar.gz: b3c53d91ba66c7ac864a5b13f2ef0a0d47cd6f59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8219c7927015cc86186d22e35f6efa077cea6d727ebd8698bba0f370b0eab4c395f4c9fee63365a5d66ca02a3027b84d26802e8a1b2e8a165b86a93e838e1de2
|
7
|
+
data.tar.gz: 20c934762f17d3a67d1c1c6a4a2c82acc2ef8fce8a3d041a7099572c2b8e0a863e92df3067650fdcbc45ff3842cfacaba3a047ed38aa2aa42cced1b06aa81f79
|
data/lib/repro/api/client.rb
CHANGED
@@ -7,26 +7,15 @@ require 'repro/api/response'
|
|
7
7
|
module Repro
|
8
8
|
module Api
|
9
9
|
|
10
|
-
|
10
|
+
class Client
|
11
11
|
|
12
12
|
API_VERSION = 'v1'.freeze
|
13
13
|
API_ENDPOINT = "https://marketing.repro.io/#{API_VERSION}".freeze
|
14
14
|
|
15
|
-
|
16
|
-
method: 'post'
|
17
|
-
}
|
15
|
+
attr_reader :options
|
18
16
|
|
19
|
-
def
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.options=(opts)
|
24
|
-
@@options = opts
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.configure
|
28
|
-
raise ArgumentError, 'Block is required.' unless block_given?
|
29
|
-
yield @@options
|
17
|
+
def initialize(token, opts = {})
|
18
|
+
@options = opts.merge(token: token, method: 'post')
|
30
19
|
end
|
31
20
|
|
32
21
|
# /push/:push_id/deliver
|
@@ -38,7 +27,7 @@ module Repro
|
|
38
27
|
# @option opts [String] :sound Sound file name for notification
|
39
28
|
# @option opts [String] :url Custom url or Deep Link
|
40
29
|
# @option opts [Hash] :attachment Attachment for rich push. Hash must have keys :type and :url.
|
41
|
-
def
|
30
|
+
def push_deliver(push_id, user_ids, opts = {})
|
42
31
|
raise ArgumentError, ':body is required.' unless opts[:body]
|
43
32
|
opts[:path] = "/push/#{push_id}/deliver"
|
44
33
|
body = { audience: { user_ids: user_ids } }
|
@@ -47,79 +36,76 @@ module Repro
|
|
47
36
|
send_request(opts)
|
48
37
|
end
|
49
38
|
|
50
|
-
|
39
|
+
def token
|
40
|
+
@options[:token]
|
41
|
+
end
|
51
42
|
|
52
|
-
|
53
|
-
|
54
|
-
|
43
|
+
def user_agent
|
44
|
+
@options[:user_agent] || "Repro Ruby Client/#{VERSION}"
|
45
|
+
end
|
55
46
|
|
56
|
-
|
57
|
-
|
58
|
-
|
47
|
+
def endpoint
|
48
|
+
@options[:endpoint] || API_ENDPOINT
|
49
|
+
end
|
59
50
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
payload[:aps][
|
71
|
-
payload[:
|
72
|
-
payload[:rpr_url] = opts.delete(:url) if opts[:url]
|
73
|
-
if opts[:attachment]
|
74
|
-
payload[:aps]['mutable-content'] = 1
|
75
|
-
payload[:rpr_attachment] = opts.delete(:attachment)
|
76
|
-
end
|
77
|
-
JSON.generate(payload)
|
51
|
+
private
|
52
|
+
|
53
|
+
def build_payload(opts)
|
54
|
+
payload = {aps: {alert: {}}}
|
55
|
+
payload[:aps][:alert][:body] = opts.delete(:body)
|
56
|
+
payload[:aps][:alert][:title] = opts.delete(:title)
|
57
|
+
payload[:aps][:badge] = opts.delete(:badge) if opts[:badge]
|
58
|
+
payload[:aps][:sound] = opts.key?(:sound) ? opts.delete(:sound) : 'default'
|
59
|
+
payload[:rpr_url] = opts.delete(:url) if opts[:url]
|
60
|
+
if opts[:attachment]
|
61
|
+
payload[:aps]['mutable-content'] = 1
|
62
|
+
payload[:rpr_attachment] = opts.delete(:attachment)
|
78
63
|
end
|
64
|
+
JSON.generate(payload)
|
65
|
+
end
|
79
66
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
res
|
67
|
+
def send_request(opts)
|
68
|
+
opts = options.merge(opts) if options
|
69
|
+
http_response = call_api(opts)
|
70
|
+
res = Response.new(http_response)
|
71
|
+
unless http_response.is_a? Net::HTTPSuccess
|
72
|
+
err_msg = "HTTP Response: #{res.code} #{res.message}"
|
73
|
+
err_msg += " - #{res.error}" if res.error
|
74
|
+
raise Repro::Api::RequestError, err_msg
|
90
75
|
end
|
76
|
+
res
|
77
|
+
end
|
91
78
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
99
|
-
else
|
100
|
-
request_url = prepare_url(opts)
|
101
|
-
Net::HTTP.get_response(request_url)
|
79
|
+
def call_api(opts)
|
80
|
+
if opts.delete(:method) == 'post'
|
81
|
+
request_url = prepare_url(path: opts.delete(:path))
|
82
|
+
request = prepare_request(request_url, body: opts.delete(:body))
|
83
|
+
Net::HTTP.start(request_url.host, request_url.port, use_ssl: true) do |http|
|
84
|
+
http.request(request)
|
102
85
|
end
|
86
|
+
else
|
87
|
+
request_url = prepare_url(opts)
|
88
|
+
Net::HTTP.get_response(request_url)
|
103
89
|
end
|
90
|
+
end
|
104
91
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
def prepare_url(opts)
|
116
|
-
path = opts.delete(:path)
|
117
|
-
query_string = opts.empty? ? '' : '?' + URI.encode_www_form(opts)
|
118
|
-
URI.parse(endpoint + path + query_string)
|
119
|
-
end
|
92
|
+
def prepare_request(uri, opts)
|
93
|
+
request = Net::HTTP::Post.new(uri.path)
|
94
|
+
request['Accept'] = 'application/json'
|
95
|
+
request['Content-Type'] = 'application/json'
|
96
|
+
request['X-Repro-Token'] = token
|
97
|
+
request['User-Agent'] = user_agent
|
98
|
+
request.body = JSON.generate(opts[:body])
|
99
|
+
request
|
100
|
+
end
|
120
101
|
|
102
|
+
def prepare_url(opts)
|
103
|
+
path = opts.delete(:path)
|
104
|
+
query_string = opts.empty? ? '' : '?' + URI.encode_www_form(opts)
|
105
|
+
URI.parse(endpoint + path + query_string)
|
121
106
|
end
|
122
107
|
|
123
108
|
end
|
109
|
+
|
124
110
|
end
|
125
111
|
end
|
data/repro-api-client.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = 'Repro API client'
|
13
13
|
spec.description = 'Repro API client'
|
14
|
+
spec.post_install_message = '!!! v0.2.0 has BREAKING CHANGE. Repro::Api::Client is not a module anymore. !!!'
|
14
15
|
spec.homepage = 'https://github.com/totem3/repro-api-client'
|
15
16
|
spec.license = 'MIT'
|
16
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repro-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takafumi Hirata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,7 +93,8 @@ homepage: https://github.com/totem3/repro-api-client
|
|
93
93
|
licenses:
|
94
94
|
- MIT
|
95
95
|
metadata: {}
|
96
|
-
post_install_message:
|
96
|
+
post_install_message: "!!! v0.2.0 has BREAKING CHANGE. Repro::Api::Client is not a
|
97
|
+
module anymore. !!!"
|
97
98
|
rdoc_options: []
|
98
99
|
require_paths:
|
99
100
|
- lib
|