one_signal 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea70b55c5209ae2e1d55b7b24728dbe125031707
4
- data.tar.gz: e7c77d266e4ea20bc0cc7650925c0fc2a214bc47
3
+ metadata.gz: 4d0c9f33f989591f7d6ab3631d728a25468bd25e
4
+ data.tar.gz: eb95288dede0228e6ed8a625bc4a6a9048e2e221
5
5
  SHA512:
6
- metadata.gz: f20b6d9543e7c9dd390cd138475ee339ffb5d8eea96a7fd6a932990a80ab789589bbcd77c50bc01d76e15c5280b8725932ef4a22fbc511e375c92d4decc49886
7
- data.tar.gz: c1f3aef54be919fc7ec8216d5793c8cf1ee4538aa5888e85f340b5953a79a1d93b50dda07c20a4699b83883ded0ad07365258978526ab29686a987d791d1af16
6
+ metadata.gz: 8d3e910a05cb29cf3df627caa26ca3cd4262bb86241669105a3dcd4e1004b5d28f4a0834a18a5d4d4ea4e6797c0a745604204f8cb509973226d3f33be5174b61
7
+ data.tar.gz: eb4182003d2cd13fa8f25dbe3102d9279476fb9b2848c74a67d3d88b18f22b34538f19496ea48f2e97f1dd365de00194234f53c5c3ed23c47bcf35db10bc958f
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
+ - 2.0
4
5
  - 2.1
5
6
  - 2.2
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.1.0 2016-04-08
2
+
3
+ * Add compatibility with Ruby 2.0
4
+
1
5
  === 1.0.0 2016-02-23
2
6
 
3
7
  * Update Player#csv_export for API consistency
data/README.md CHANGED
@@ -56,7 +56,7 @@ The return value of each method is a `Net::HTTPResponse`.
56
56
 
57
57
  ```ruby
58
58
  - OneSignal::Player.all(params:)
59
- - OneSignal::Player.csv_export(app_id:)
59
+ - OneSignal::Player.csv_export(params:)
60
60
  - OneSignal::Player.get(id:)
61
61
  - OneSignal::Player.create(params:)
62
62
  - OneSignal::Player.create_session(id:, params:)
@@ -18,7 +18,7 @@ module OneSignal
18
18
  return response
19
19
  end
20
20
 
21
- def self.get(id:)
21
+ def self.get(id: "")
22
22
  uri_string = @@base_uri
23
23
  uri_string += "/apps"
24
24
  uri_string += "/#{id}"
@@ -51,7 +51,7 @@ module OneSignal
51
51
  return response
52
52
  end
53
53
 
54
- def self.update(id:, params: {})
54
+ def self.update(id: "", params: {})
55
55
  uri_string = @@base_uri
56
56
  uri_string += "/apps"
57
57
  uri_string += "/#{id}"
@@ -18,7 +18,7 @@ module OneSignal
18
18
  return response
19
19
  end
20
20
 
21
- def self.get(id:, params:)
21
+ def self.get(id: "", params: {})
22
22
  uri_string = @@base_uri
23
23
  uri_string += "/notifications"
24
24
  uri_string += "/#{id}"
@@ -49,7 +49,7 @@ module OneSignal
49
49
  return response
50
50
  end
51
51
 
52
- def self.update(id:, params: {})
52
+ def self.update(id: "", params: {})
53
53
  uri_string = @@base_uri
54
54
  uri_string += "/notifications"
55
55
  uri_string += "/#{id}"
@@ -66,7 +66,7 @@ module OneSignal
66
66
  return response
67
67
  end
68
68
 
69
- def self.delete(id:, params:)
69
+ def self.delete(id: "", params: {})
70
70
  uri_string = @@base_uri
71
71
  uri_string += "/notifications"
72
72
  uri_string += "/#{id}"
@@ -85,21 +85,26 @@ module OneSignal
85
85
 
86
86
  private
87
87
 
88
- def self.handle_error(uri:, params:, response:)
88
+ def self.handle_error(uri: nil, params: {}, response: nil)
89
89
  msg = "Create Notification error - uri: #{uri} params: #{params}"
90
+ unless response.nil?
91
+ code = response.code
92
+ body = response.body
93
+ end
90
94
  if is_no_recipients_error(response: response)
91
95
  raise NoRecipientsError.new(message: msg,
92
- http_status: response.code,
93
- http_body: response.body)
96
+ http_status: code,
97
+ http_body: body)
94
98
  else
95
99
  raise OneSignalError.new(message: msg,
96
- http_status: response.code,
97
- http_body: response.body)
100
+ http_status: code,
101
+ http_body: body)
98
102
  end
99
103
  end
100
104
 
101
- def self.is_no_recipients_error(response:)
102
- return false if response.code != '400' ||
105
+ def self.is_no_recipients_error(response: nil)
106
+ return false if response.nil? ||
107
+ response.code != '400' ||
103
108
  response.body.nil?
104
109
 
105
110
  body = JSON.parse(response.body)
@@ -43,7 +43,9 @@ module OneSignal
43
43
  @@read_timeout
44
44
  end
45
45
 
46
- def self.http_object(uri:)
46
+ def self.http_object(uri: nil)
47
+ return nil if uri.nil?
48
+
47
49
  http = Net::HTTP.new(uri.host, uri.port)
48
50
  http.use_ssl = uri.scheme == 'https'
49
51
  http.open_timeout = @@open_timeout
@@ -51,49 +53,61 @@ module OneSignal
51
53
  return http
52
54
  end
53
55
 
54
- def self.send_post_request(uri:, body:)
56
+ def self.send_post_request(uri: nil, body: nil)
57
+ return nil if uri.nil?
58
+
55
59
  request = Net::HTTP::Post.new(uri.request_uri)
56
60
  request.body = body.to_json
57
61
  request = request_with_headers(request: request)
58
62
 
59
63
  http = http_object(uri: uri)
60
64
 
61
- response = http.request(request)
65
+ return http.request(request)
62
66
  end
63
67
 
64
- def self.send_delete_request(uri:, params: {})
68
+ def self.send_delete_request(uri: nil, params: {})
69
+ return nil if uri.nil?
70
+
65
71
  uri.query = URI.encode_www_form(params) unless params.nil?
66
72
  request = Net::HTTP::Delete.new(uri.request_uri)
67
73
  request = request_with_headers(request: request)
68
74
 
69
75
  http = http_object(uri: uri)
70
76
 
71
- response = http.request(request)
77
+ return http.request(request)
72
78
  end
73
79
 
74
- def self.send_put_request(uri:, body:)
80
+ def self.send_put_request(uri: nil, body: nil)
81
+ return nil if uri.nil?
82
+
75
83
  request = Net::HTTP::Put.new(uri.request_uri)
76
84
  request.body = body.to_json
77
85
  request = request_with_headers(request: request)
78
86
 
79
87
  http = http_object(uri: uri)
80
88
 
81
- response = http.request(request)
89
+ return http.request(request)
82
90
  end
83
91
 
84
- def self.send_get_request(uri:, params: {})
92
+ def self.send_get_request(uri: nil, params: {})
93
+ return nil if uri.nil?
94
+
85
95
  uri.query = URI.encode_www_form(params) unless params.nil?
86
96
  request = Net::HTTP::Get.new(uri.request_uri)
87
97
  request = request_with_headers(request: request)
88
98
 
89
99
  http = http_object(uri: uri)
90
100
 
91
- response = http.request(request)
101
+ return http.request(request)
92
102
  end
93
103
 
94
104
  private
95
105
 
96
- def self.ensure_http_status(response:, status:, method_name:, uri:, params:)
106
+ def self.ensure_http_status(response: nil, status: nil, method_name: "", uri: "", params: {})
107
+ if response.nil? || status.nil?
108
+ raise OneSignalError.new(message: "Please provide a response (#{response}) and a status (#{status})")
109
+ end
110
+
97
111
  if response.code != status.to_s
98
112
  msg = "#{self.name}##{method_name} error - uri: #{uri} params: #{params}"
99
113
  raise OneSignalError.new(message: msg,
@@ -102,7 +116,9 @@ module OneSignal
102
116
  end
103
117
  end
104
118
 
105
- def self.request_with_headers(request:)
119
+ def self.request_with_headers(request: nil)
120
+ return nil if request.nil?
121
+
106
122
  request.add_field("Content-Type", "application/json")
107
123
  request.add_field("Authorization", "Basic #{self.auth_key}")
108
124
  return request
@@ -2,7 +2,7 @@ module OneSignal
2
2
 
3
3
  class Player < OneSignal
4
4
 
5
- def self.csv_export(params:)
5
+ def self.csv_export(params: {})
6
6
  uri_string = @@base_uri
7
7
  uri_string += "/players/csv_export"
8
8
  uri = URI.parse(uri_string)
@@ -34,7 +34,7 @@ module OneSignal
34
34
  return response
35
35
  end
36
36
 
37
- def self.get(id:)
37
+ def self.get(id: "")
38
38
  uri_string = @@base_uri
39
39
  uri_string += "/players"
40
40
  uri_string += "/#{id}"
@@ -67,7 +67,7 @@ module OneSignal
67
67
  return response
68
68
  end
69
69
 
70
- def self.create_session(id:, params: {})
70
+ def self.create_session(id: "", params: {})
71
71
  uri_string = @@base_uri
72
72
  uri_string += "/players"
73
73
  uri_string += "/#{id}"
@@ -85,7 +85,7 @@ module OneSignal
85
85
  return response
86
86
  end
87
87
 
88
- def self.create_purchase(id:, params: {})
88
+ def self.create_purchase(id: "", params: {})
89
89
  uri_string = @@base_uri
90
90
  uri_string += "/players"
91
91
  uri_string += "/#{id}"
@@ -103,7 +103,7 @@ module OneSignal
103
103
  return response
104
104
  end
105
105
 
106
- def self.create_focus(id:, params: {})
106
+ def self.create_focus(id: "", params: {})
107
107
  uri_string = @@base_uri
108
108
  uri_string += "/players"
109
109
  uri_string += "/#{id}"
@@ -121,7 +121,7 @@ module OneSignal
121
121
  return response
122
122
  end
123
123
 
124
- def self.update(id:, params: {})
124
+ def self.update(id: "", params: {})
125
125
  uri_string = @@base_uri
126
126
  uri_string += "/players"
127
127
  uri_string += "/#{id}"
@@ -1,3 +1,3 @@
1
1
  module OneSignal
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/one_signal.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('lib/one_signal/version')
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.required_ruby_version = '>= 2.1.0'
4
+ s.required_ruby_version = '>= 2.0.0'
5
5
  s.add_development_dependency 'rake', '~> 10.4'
6
6
  s.add_development_dependency 'mocha', '~> 1.1'
7
7
  s.add_development_dependency 'dotenv', '~> 2.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one_signal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Balthazar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 2.1.0
110
+ version: 2.0.0
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="