one_signal 0.0.8 → 0.0.9

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: f71bd3eedf66b5c71a541f39bd3ad8a174516b9c
4
- data.tar.gz: 3c732a489790f92c17f18f615b78cf8c21257c1e
3
+ metadata.gz: 29c2c8a73c7d2fadc0fb84243656b143038f0ec9
4
+ data.tar.gz: 82ccfe3bd9f6b78a272552bd8d67623360ba9a83
5
5
  SHA512:
6
- metadata.gz: f9ecaed3d48b162d43a36377240abef1a9ef124f8d443c5aa4bf7bb9dc66eac29b39f26b8248654beb0fff94434bb64a451312da5d25c3d396dad746289017a0
7
- data.tar.gz: 389c5837037151b6af49f430dd95b9836c2648bad515ef09c329883c9f4630586db2c8d3cae1264073342bf473c0c6a0d8a2e9da526987a710950db4fb6b389b
6
+ metadata.gz: 3da04a064ffdb12ac4b960b384c56474df854ccd9acee9a85c10acb80f84d1ee7b0e38495df940f1e092f8ef403454216a566345a98d37a5535ae61935a50be5
7
+ data.tar.gz: 59ac4fdcc9424520f9362b157e5998708423ed0c3cf286efa90c8ef40afaa72c96b65cf78bb3083b1170c5449bd812d36a8f9e42b69685cbff7eb56232bfa304
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.9 2016-01-11
2
+
3
+ * Add Player#all method
4
+
1
5
  === 0.0.8 2015-12-17
2
6
 
3
7
  * Add Player#csv_export method
data/example.rb CHANGED
@@ -103,7 +103,13 @@ def csv_export
103
103
  puts response.body
104
104
  end
105
105
 
106
+ def all_players
107
+ response = OneSignal::Player.all(params: {app_id: @app_id, limit: 3})
108
+ puts response.body
109
+ end
110
+
106
111
  # player_id = create_player
107
112
  # update_player(id: player_id)
108
113
  # notify
109
- csv_export
114
+ # csv_export
115
+ all_players
@@ -66,6 +66,18 @@ module OneSignal
66
66
  response = http.request(request)
67
67
  end
68
68
 
69
+ def self.send_get_request(uri:, params: {})
70
+ ensure_api_key
71
+
72
+ uri.query = URI.encode_www_form(params)
73
+ request = Net::HTTP::Get.new(uri.request_uri)
74
+ request = request_with_headers(request: request)
75
+
76
+ http = http_object(uri: uri)
77
+
78
+ response = http.request(request)
79
+ end
80
+
69
81
  private
70
82
 
71
83
  def self.ensure_api_key
@@ -18,6 +18,22 @@ module OneSignal
18
18
  return response
19
19
  end
20
20
 
21
+ def self.all(params: {})
22
+ uri_string = @@base_uri
23
+ uri_string += "/players"
24
+ uri = URI.parse(uri_string)
25
+
26
+ response = send_get_request(uri: uri, params: params)
27
+
28
+ ensure_http_status(response: response,
29
+ status: '200',
30
+ method_name: 'All',
31
+ uri: uri,
32
+ params: params)
33
+
34
+ return response
35
+ end
36
+
21
37
  def self.create(params: {})
22
38
  uri_string = @@base_uri
23
39
  uri_string += "/players"
@@ -1,3 +1,3 @@
1
1
  module OneSignal
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/one_signal.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.add_development_dependency 'rake', '~> 10.4'
7
7
  s.add_development_dependency 'mocha', '~> 1.1'
8
8
  s.add_development_dependency 'dotenv', '~> 2.0'
9
- s.add_development_dependency 'minitest'
9
+ s.add_development_dependency 'minitest', '~> 5.8'
10
10
  s.name = 'one_signal'
11
11
  s.version = OneSignal::VERSION
12
12
  s.summary = "A library which implements the OneSignal API"
@@ -5,6 +5,7 @@ class OneSignalTest < MiniTest::Test
5
5
  def setup
6
6
  @api_key = "fake_api_123"
7
7
  @body = "fake body"
8
+ @params = {foo: 'bar', widget: 'acme'}
8
9
  @uri = URI.parse("https://www.example.com/foo/bar")
9
10
  @default_timeout = 30
10
11
  end
@@ -15,9 +16,9 @@ class OneSignalTest < MiniTest::Test
15
16
  OneSignal::OneSignal.read_timeout = @default_timeout
16
17
  end
17
18
 
18
- def build_mock_request
19
+ def build_mock_request(body: nil)
19
20
  request = mock()
20
- request.expects(:body=).with(@body.to_json)
21
+ request.expects(:body=).with(body.to_json) unless body.nil?
21
22
  request.expects(:add_field).with("Content-Type", "application/json")
22
23
  request.expects(:add_field).with("Authorization", "Basic #{@api_key}")
23
24
  return request
@@ -88,7 +89,7 @@ class OneSignalTest < MiniTest::Test
88
89
 
89
90
  def test_send_post_request
90
91
  # test request creation
91
- request = build_mock_request
92
+ request = build_mock_request(body: @body)
92
93
  Net::HTTP::Post.expects(:new).with(@uri.request_uri).returns(request)
93
94
 
94
95
  # test http object creation
@@ -105,7 +106,7 @@ class OneSignalTest < MiniTest::Test
105
106
 
106
107
  def test_send_put_request
107
108
  # test request creation
108
- request = build_mock_request
109
+ request = build_mock_request(body: @body)
109
110
  Net::HTTP::Put.expects(:new).with(@uri.request_uri).returns(request)
110
111
 
111
112
  # test http object creation
@@ -120,4 +121,25 @@ class OneSignalTest < MiniTest::Test
120
121
  assert_equal response, OneSignal::OneSignal.send_put_request(uri: @uri, body: @body)
121
122
  end
122
123
 
124
+ def test_send_get_request
125
+ expected_uri = @uri.clone
126
+ expected_uri.query = URI.encode_www_form(@params)
127
+
128
+ # test request creation
129
+ request = build_mock_request
130
+ Net::HTTP::Get.expects(:new).with(expected_uri.request_uri).returns(request)
131
+
132
+ # test http object creation
133
+ http = build_mock_http_object
134
+ Net::HTTP.expects(:new).with(expected_uri.host, expected_uri.port).returns(http)
135
+
136
+ # test send request
137
+ response = mock()
138
+ http.expects(:request).with(request).returns(response)
139
+
140
+ OneSignal::OneSignal.api_key = @api_key
141
+ assert_equal response, OneSignal::OneSignal.send_get_request(uri: @uri,
142
+ params: @params)
143
+ end
144
+
123
145
  end
data/test/player_test.rb CHANGED
@@ -6,6 +6,7 @@ class PlayerTest < MiniTest::Test
6
6
  base_url = "https://onesignal.com/api/v1/players"
7
7
  @create_uri = URI.parse(base_url)
8
8
  @csv_export_uri = URI.parse(base_url + "/csv_export")
9
+ @all_uri = URI.parse(base_url)
9
10
 
10
11
  @player_id = "fake-id-123"
11
12
  @update_uri = URI.parse(base_url + "/#{@player_id}")
@@ -37,6 +38,14 @@ class PlayerTest < MiniTest::Test
37
38
  assert_equal response, OneSignal::Player.csv_export(app_id: @app_id)
38
39
  end
39
40
 
41
+ def test_all
42
+ response = mock_response_ok
43
+ OneSignal::OneSignal.expects(:send_get_request)
44
+ .with(uri: @all_uri, params: @params)
45
+ .returns(response)
46
+ assert_equal response, OneSignal::Player.all(params: @params)
47
+ end
48
+
40
49
  def test_create
41
50
  response = mock_response_ok
42
51
  OneSignal::OneSignal.expects(:send_post_request)
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: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Balthazar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-17 00:00:00.000000000 Z
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '5.8'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '5.8'
83
83
  description: A library which implements the OneSignal API.
84
84
  email: thomas@balthazar.info
85
85
  executables: []