five_mobile_push 0.4.5 → 0.4.6
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.
- data/Gemfile +1 -0
- data/lib/five_mobile_push/client.rb +10 -25
- data/lib/five_mobile_push/version.rb +1 -1
- data/spec/five_mobile_push/client_spec.rb +19 -33
- data/spec/five_mobile_push/device_spec.rb +2 -2
- data/spec/five_mobile_push/notifier_spec.rb +1 -1
- data/spec/five_mobile_push/tags_spec.rb +1 -1
- data/spec/integration/client_spec.rb +29 -0
- data/spec/spec_helper.rb +3 -1
- metadata +3 -1
data/Gemfile
CHANGED
@@ -1,25 +1,16 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require 'faraday
|
2
|
+
require 'faraday'
|
3
3
|
|
4
4
|
module FiveMobilePush
|
5
5
|
class Client
|
6
6
|
|
7
7
|
DEFAULT_ENDPOINT = 'https://push.fivemobile.com/rest'
|
8
8
|
|
9
|
-
attr_accessor :application_uid, :api_token
|
9
|
+
attr_accessor :application_uid, :api_token
|
10
10
|
|
11
11
|
def initialize(options={})
|
12
12
|
self.application_uid = options[:application_uid] || FiveMobilePush.application_uid
|
13
13
|
self.api_token = options[:api_token] || FiveMobilePush.api_token
|
14
|
-
self.adapter = options[:adapter] || FiveMobilePush.adapter
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
def connection
|
19
|
-
@connection ||= Faraday.new(:url => DEFAULT_ENDPOINT, :user_agent => 'FiveMobilePush Ruby gem') do |builder|
|
20
|
-
builder.adapter self.adapter
|
21
|
-
builder.use Faraday::Response::Errors
|
22
|
-
end
|
23
14
|
end
|
24
15
|
|
25
16
|
def get(path, options={})
|
@@ -42,25 +33,19 @@ module FiveMobilePush
|
|
42
33
|
FiveMobilePush::Tag.new(self, device_uid)
|
43
34
|
end
|
44
35
|
|
45
|
-
# @return [URI] a URI object for the {DEFAULT_ENDPOINT}
|
46
|
-
def self.default_endpoint
|
47
|
-
URI.parse(DEFAULT_ENDPOINT)
|
48
|
-
end
|
49
|
-
|
50
36
|
private
|
51
37
|
|
52
38
|
def perform_request(method, path, options={})
|
53
39
|
options.merge!({:api_token => self.api_token, :application_id => self.application_uid })
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
40
|
+
|
41
|
+
uri = [DEFAULT_ENDPOINT, path].join('/')
|
42
|
+
|
43
|
+
case method
|
44
|
+
when :get
|
45
|
+
Faraday.get(uri, options)
|
46
|
+
when :post
|
47
|
+
Faraday.post(uri, options)
|
62
48
|
end
|
63
49
|
end
|
64
|
-
|
65
50
|
end
|
66
51
|
end
|
@@ -7,21 +7,16 @@ describe FiveMobilePush::Client do
|
|
7
7
|
|
8
8
|
subject { FiveMobilePush::Client.new :api_token => api_token, :application_uid => application_uid }
|
9
9
|
|
10
|
-
it "connects using the fivemobile endpoint" do
|
11
|
-
connection = subject.send(:connection).build_url(nil).to_s
|
12
|
-
connection.should == described_class.default_endpoint.to_s
|
13
|
-
end
|
14
|
-
|
15
10
|
describe "#device" do
|
16
|
-
|
11
|
+
|
17
12
|
it "initializes a Device" do
|
18
13
|
subject.device('abc').should be_kind_of(FiveMobilePush::Device)
|
19
14
|
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
15
|
+
|
16
|
+
end
|
17
|
+
|
23
18
|
describe "#notifier" do
|
24
|
-
|
19
|
+
|
25
20
|
it "initializes a Notifier" do
|
26
21
|
subject.notifier.should be_kind_of(FiveMobilePush::Notifier)
|
27
22
|
end
|
@@ -35,46 +30,37 @@ describe FiveMobilePush::Client do
|
|
35
30
|
end
|
36
31
|
|
37
32
|
end
|
38
|
-
|
33
|
+
|
39
34
|
context "response code is 400" do
|
40
|
-
|
41
|
-
let(:path) { (described_class
|
42
|
-
|
35
|
+
|
36
|
+
let(:path) { (described_class::DEFAULT_ENDPOINT + "/some_endpoint?api_token=#{api_token}&application_id=#{application_uid}").to_s }
|
37
|
+
|
43
38
|
it "raises a GeneralError" do
|
44
39
|
stub_request(:any, path).to_return(:body => "something broken", :status => 400)
|
45
40
|
expect { subject.get(path) }.to raise_error(FiveMobilePush::GeneralError)
|
46
41
|
end
|
47
|
-
|
42
|
+
|
48
43
|
end
|
49
|
-
|
44
|
+
|
50
45
|
context "response code is 401" do
|
51
|
-
|
52
|
-
let(:path) { (described_class
|
53
|
-
|
46
|
+
|
47
|
+
let(:path) { (described_class::DEFAULT_ENDPOINT + "/some_endpoint?api_token=#{api_token}&application_id=#{application_uid}").to_s }
|
48
|
+
|
54
49
|
it "raises a GeneralError" do
|
55
50
|
stub_request(:any, path).to_return(:body => "something broken", :status => 401)
|
56
51
|
expect { subject.get(path) }.to raise_error(FiveMobilePush::UnauthorizedError)
|
57
52
|
end
|
58
|
-
|
53
|
+
|
59
54
|
end
|
60
|
-
|
55
|
+
|
61
56
|
context "response code is 500" do
|
62
|
-
|
63
|
-
let(:path) { (described_class
|
64
|
-
|
57
|
+
|
58
|
+
let(:path) { (described_class::DEFAULT_ENDPOINT + "/some_endpoint?api_token=#{api_token}&application_id=#{application_uid}").to_s }
|
59
|
+
|
65
60
|
it "raises a GeneralError" do
|
66
61
|
stub_request(:any, path).to_return(:body => "something broken", :status => 500)
|
67
62
|
expect { subject.get(path) }.to raise_error(FiveMobilePush::ServerError)
|
68
63
|
end
|
69
|
-
|
70
|
-
end
|
71
64
|
|
72
|
-
describe '.default_endpoint' do
|
73
|
-
it { described_class.default_endpoint.should be_a(URI) }
|
74
|
-
|
75
|
-
it 'acts as a URI object' do
|
76
|
-
uri = described_class.default_endpoint + 'foo'
|
77
|
-
uri.to_s.should =~ /foo\z/
|
78
|
-
end
|
79
65
|
end
|
80
66
|
end
|
@@ -16,7 +16,7 @@ describe FiveMobilePush::Device do
|
|
16
16
|
{
|
17
17
|
:manufacturer => 'Apple',
|
18
18
|
:model => 'iPhone 4',
|
19
|
-
:platform => '
|
19
|
+
:platform => 'iPhone OS',
|
20
20
|
:platform_ver => 'iOS 4.3'
|
21
21
|
}
|
22
22
|
}
|
@@ -98,7 +98,7 @@ describe FiveMobilePush::Device do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def device_endpoint(name)
|
101
|
-
(FiveMobilePush::Client
|
101
|
+
(FiveMobilePush::Client::DEFAULT_ENDPOINT + "/device/#{name}").to_s
|
102
102
|
end
|
103
103
|
|
104
104
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
FiveMobilePush.configure do |config|
|
4
|
+
config.api_token = ''
|
5
|
+
config.application_uid = ''
|
6
|
+
end
|
7
|
+
|
8
|
+
describe FiveMobilePush::Client do
|
9
|
+
let(:device) { double('Device', id: 12345, uid: 'abcdef') }
|
10
|
+
|
11
|
+
let(:device_info) {
|
12
|
+
{
|
13
|
+
'manufacturer' => 'Apple',
|
14
|
+
'model' => 'iPhone 4',
|
15
|
+
'platform' => 'iPhone OS',
|
16
|
+
'platform_ver' => '4.3.2'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
let(:reg_data) { 'cafebabe' }
|
21
|
+
|
22
|
+
subject { described_class.new }
|
23
|
+
|
24
|
+
it "register device" do
|
25
|
+
expect {
|
26
|
+
subject.device(device.uid).register(device_info, reg_data)
|
27
|
+
}.to_not raise_error
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: five_mobile_push
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kevin Faustino
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- spec/five_mobile_push/tags_spec.rb
|
144
144
|
- spec/five_mobile_push_spec.rb
|
145
145
|
- spec/fixtures/register.json
|
146
|
+
- spec/integration/client_spec.rb
|
146
147
|
- spec/spec_helper.rb
|
147
148
|
homepage: ""
|
148
149
|
licenses: []
|
@@ -184,4 +185,5 @@ test_files:
|
|
184
185
|
- spec/five_mobile_push/tags_spec.rb
|
185
186
|
- spec/five_mobile_push_spec.rb
|
186
187
|
- spec/fixtures/register.json
|
188
|
+
- spec/integration/client_spec.rb
|
187
189
|
- spec/spec_helper.rb
|