repro-api-client 0.1.0 → 0.2.0

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: f93516229f022a4a3074c01bb9d405902d09e500
4
- data.tar.gz: 0a8bd27ad22f64f2ba0f299b7cabd08d208a89d0
3
+ metadata.gz: 2df819152eca29047156efb357b852b32e741e19
4
+ data.tar.gz: b3c53d91ba66c7ac864a5b13f2ef0a0d47cd6f59
5
5
  SHA512:
6
- metadata.gz: '014969b8fbc9feb499814b5319cd9caf3631754f958e838e14f03f4da8ccb39a969716edd549b45c06623ea7030c79f8f213e93b196c576ca44e535622ec74d3'
7
- data.tar.gz: 4b0f02d32ac468b1b87b7eadd1e6fff110ee45415e7b41e5a9e2fbb3c5e7baecbe1f042124586258bd074d2b5becee442bc76134438f77ddd042e53cb832e1cc
6
+ metadata.gz: 8219c7927015cc86186d22e35f6efa077cea6d727ebd8698bba0f370b0eab4c395f4c9fee63365a5d66ca02a3027b84d26802e8a1b2e8a165b86a93e838e1de2
7
+ data.tar.gz: 20c934762f17d3a67d1c1c6a4a2c82acc2ef8fce8a3d041a7099572c2b8e0a863e92df3067650fdcbc45ff3842cfacaba3a047ed38aa2aa42cced1b06aa81f79
@@ -1,7 +1,7 @@
1
1
  module Repro
2
2
  module Api
3
- module Client
4
- VERSION = "0.1.0"
3
+ class Client
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -7,26 +7,15 @@ require 'repro/api/response'
7
7
  module Repro
8
8
  module Api
9
9
 
10
- module Client
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
- @@options = {
16
- method: 'post'
17
- }
15
+ attr_reader :options
18
16
 
19
- def self.options
20
- @@options
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 self.push_deliver(push_id, user_ids, opts = {})
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
- class << self
39
+ def token
40
+ @options[:token]
41
+ end
51
42
 
52
- def token
53
- @@options[:token]
54
- end
43
+ def user_agent
44
+ @options[:user_agent] || "Repro Ruby Client/#{VERSION}"
45
+ end
55
46
 
56
- def user_agent
57
- @@options[:user_agent] || "Repro Ruby Client/#{VERSION}"
58
- end
47
+ def endpoint
48
+ @options[:endpoint] || API_ENDPOINT
49
+ end
59
50
 
60
- def endpoint
61
- @@options[:endpoint] || API_ENDPOINT
62
- end
63
-
64
- private
65
-
66
- def build_payload(opts)
67
- payload = {aps: {alert: {}}}
68
- payload[:aps][:alert][:body] = opts.delete(:body)
69
- payload[:aps][:alert][:title] = opts.delete(:title)
70
- payload[:aps][:badge] = opts.delete(:badge) if opts[:badge]
71
- payload[:aps][:sound] = opts.key?(:sound) ? opts.delete(:sound) : 'default'
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
- def send_request(opts)
81
- opts = options.merge(opts) if options
82
- http_response = call_api(opts)
83
- res = Response.new(http_response)
84
- unless http_response.is_a? Net::HTTPSuccess
85
- err_msg = "HTTP Response: #{res.code} #{res.message}"
86
- err_msg += " - #{res.error}" if res.error
87
- raise Repro::Api::RequestError, err_msg
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
- def call_api(opts)
93
- if opts.delete(:method) == 'post'
94
- request_url = prepare_url(path: opts.delete(:path))
95
- request = prepare_request(request_url, body: opts.delete(:body))
96
- Net::HTTP.start(request_url.host, request_url.port, use_ssl: true) do |http|
97
- http.request(request)
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
- def prepare_request(uri, opts)
106
- request = Net::HTTP::Post.new(uri.path)
107
- request['Accept'] = 'application/json'
108
- request['Content-Type'] = 'application/json'
109
- request['X-Repro-Token'] = token
110
- request['User-Agent'] = user_agent
111
- request.body = JSON.generate(opts[:body])
112
- request
113
- end
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
@@ -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.1.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-06-02 00:00:00.000000000 Z
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