five_mobile_push 0.1.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.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/five_mobile_push.gemspec +27 -0
- data/lib/faraday/errors.rb +29 -0
- data/lib/five_mobile_push/client.rb +60 -0
- data/lib/five_mobile_push/device.rb +60 -0
- data/lib/five_mobile_push/notifier.rb +36 -0
- data/lib/five_mobile_push/tag.rb +30 -0
- data/lib/five_mobile_push/version.rb +3 -0
- data/lib/five_mobile_push.rb +27 -0
- data/spec/five_mobile_push/client_spec.rb +73 -0
- data/spec/five_mobile_push/device_spec.rb +110 -0
- data/spec/five_mobile_push/notifier_spec.rb +61 -0
- data/spec/five_mobile_push/tags_spec.rb +61 -0
- data/spec/five_mobile_push_spec.rb +48 -0
- data/spec/fixtures/register.json +1 -0
- data/spec/spec_helper.rb +28 -0
- metadata +137 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "five_mobile_push/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "five_mobile_push"
|
7
|
+
s.version = FiveMobilePush::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Kevin Faustino", "James Herdman"]
|
10
|
+
s.email = ["kevin.faustino@gmail.com", "james.herdman@me.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{API wrapper for Five Mobile Push notification service}
|
13
|
+
s.description = %q{API wrapper for Five Mobile Push notification service}
|
14
|
+
|
15
|
+
s.rubyforge_project = "five_mobile_push"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "multi_json", ["~> 0.0.5"]
|
23
|
+
s.add_dependency "faraday", ["~> 0.5.7"]
|
24
|
+
s.add_development_dependency "rspec", ["~> 2.5.0"]
|
25
|
+
s.add_development_dependency "yajl-ruby"
|
26
|
+
s.add_development_dependency "webmock"
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response::Errors < Response::Middleware
|
5
|
+
|
6
|
+
begin
|
7
|
+
def self.register_on_complete(env)
|
8
|
+
env[:response].on_complete do |finished_env|
|
9
|
+
case finished_env[:status]
|
10
|
+
when 400
|
11
|
+
raise FiveMobilePush::GeneralError, finished_env[:body]
|
12
|
+
when 401
|
13
|
+
raise FiveMobilePush::UnauthorizedError, finished_env[:body]
|
14
|
+
when 500
|
15
|
+
raise FiveMobilePush::ServerError, 'push.fivemobile.com is currently down'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
rescue LoadError, NameError => e
|
20
|
+
self.load_error = e
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(app)
|
24
|
+
super
|
25
|
+
@parser = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'faraday/errors'
|
2
|
+
|
3
|
+
module FiveMobilePush
|
4
|
+
class Client
|
5
|
+
|
6
|
+
DEFAULT_ENDPOINT = 'https://push.fivemobile.com/rest/'
|
7
|
+
|
8
|
+
attr_accessor :application_uid, :api_token
|
9
|
+
|
10
|
+
def initialize(options={})
|
11
|
+
self.application_uid = options[:application_uid] || FiveMobilePush.application_uid
|
12
|
+
self.api_token = options[:api_token] || FiveMobilePush.api_token
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def connection
|
17
|
+
@connection ||= Faraday.new(:url => DEFAULT_ENDPOINT, :user_agent => 'FiveMobilePush Ruby gem') do |builder|
|
18
|
+
builder.adapter Faraday.default_adapter
|
19
|
+
|
20
|
+
builder.use Faraday::Response::Errors
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(path, options={})
|
25
|
+
perform_request(:get, path, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def post(path, options={})
|
29
|
+
perform_request(:post, path, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def device(device_uid)
|
33
|
+
FiveMobilePush::Device.new(self, device_uid)
|
34
|
+
end
|
35
|
+
|
36
|
+
def notifier
|
37
|
+
FiveMobilePush::Notifier.new(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
def tag(device_uid)
|
41
|
+
FiveMobilePush::Tag.new(self, device_uid)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def perform_request(method, path, options={})
|
47
|
+
options.merge!({:api_token => self.api_token, :application_id => self.application_uid })
|
48
|
+
connection.send(method) do |request|
|
49
|
+
case method
|
50
|
+
when :get, :delete
|
51
|
+
request.url(path, options)
|
52
|
+
when :post, :put
|
53
|
+
request.path = path
|
54
|
+
request.body = options
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module FiveMobilePush
|
2
|
+
class Device
|
3
|
+
|
4
|
+
VALID_OPTION_KEYS = [:alias, :email]
|
5
|
+
|
6
|
+
# @param [FiveMobilePush::Client] client The Client to use to send this request
|
7
|
+
#
|
8
|
+
# @param [String] device_uid The ID of the device being registered.
|
9
|
+
# Maximum of 64 characters.
|
10
|
+
def initialize(client, device_uid)
|
11
|
+
@client = client
|
12
|
+
@device_uid = device_uid
|
13
|
+
end
|
14
|
+
|
15
|
+
# Registers a device for receiving push notifications from an application.
|
16
|
+
# If the device is already registered, this call can update the existing
|
17
|
+
# registration details.
|
18
|
+
#
|
19
|
+
# @param [String] registration_data Platform specific device registration
|
20
|
+
# data, e.g. iOS device token. Optional for some platforms
|
21
|
+
#
|
22
|
+
# @param [Hash] device_info Information about the device being registered
|
23
|
+
#
|
24
|
+
# @option device_info [String] :manufacturer The device manufacturer.
|
25
|
+
# E.g. Apple, HTC, Motorola, RIM. Maximum 64 characters.
|
26
|
+
#
|
27
|
+
# @option device_info [String] :model The model of the device. E.g. iPhone 4,
|
28
|
+
# Nexus One
|
29
|
+
#
|
30
|
+
# @option device_info [String] :platform The software platform. E.g. iOS, Android
|
31
|
+
#
|
32
|
+
# @option device_info [String] :platform_ver Software platform version.
|
33
|
+
#
|
34
|
+
# @return [Hash] Has unique device API key. Required for many other calls.
|
35
|
+
def register(device_info, registration_data=nil)
|
36
|
+
options = {
|
37
|
+
:device_id => @device_uid,
|
38
|
+
:device_info => MultiJson.encode(device_info)
|
39
|
+
}
|
40
|
+
|
41
|
+
options[:reg_data] = registration_data unless registration_data.nil?
|
42
|
+
response = @client.post 'device/register', options
|
43
|
+
MultiJson.decode(response.body)
|
44
|
+
end
|
45
|
+
|
46
|
+
def resume
|
47
|
+
@client.post 'device/resume', :id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => @device_uid
|
48
|
+
end
|
49
|
+
|
50
|
+
def suspend
|
51
|
+
@client.post 'device/suspend', :id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => @device_uid
|
52
|
+
end
|
53
|
+
|
54
|
+
def unregister
|
55
|
+
@client.post 'device/unregister', :id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => @device_uid
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module FiveMobilePush
|
2
|
+
class Notifier
|
3
|
+
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def broadcast(platforms, payload)
|
9
|
+
@client.post 'notify/broadcast', :platforms => self.class.build_platforms_string(platforms), :payload => MultiJson.encode(payload)
|
10
|
+
end
|
11
|
+
|
12
|
+
def notify_devices(devices, payload)
|
13
|
+
@client.post 'notify/toDevices', :id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_values => devices.join(','), :payload => MultiJson.encode(payload)
|
14
|
+
end
|
15
|
+
|
16
|
+
def notify_by_tags(platforms, tags, payload)
|
17
|
+
@client.post 'notify/toTags',
|
18
|
+
:platforms => self.class.build_platforms_string(platforms),
|
19
|
+
:tags => tags.join(','),
|
20
|
+
:payload => MultiJson.encode(payload)
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
|
25
|
+
def build_platforms_string(platforms)
|
26
|
+
if platforms.kind_of?(Enumerable)
|
27
|
+
platforms.join(',')
|
28
|
+
else
|
29
|
+
platforms.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module FiveMobilePush
|
2
|
+
class Tag
|
3
|
+
|
4
|
+
attr_accessor :device_uid
|
5
|
+
|
6
|
+
def initialize(client, device_uid)
|
7
|
+
@client = client
|
8
|
+
self.device_uid = device_uid
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(*tags)
|
12
|
+
@client.post(end_point(:add), :id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => self.device_uid, :tags => normalize_tags(tags))
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete(*tags)
|
16
|
+
@client.post(end_point(:delete), :id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => self.device_uid, :tags => normalize_tags(tags))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def normalize_tags(tags)
|
22
|
+
tags.flatten.join(",")
|
23
|
+
end
|
24
|
+
|
25
|
+
def end_point(action)
|
26
|
+
"device/tags/#{action}"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
require 'five_mobile_push/client'
|
3
|
+
|
4
|
+
module FiveMobilePush
|
5
|
+
extend self
|
6
|
+
|
7
|
+
autoload :Device, 'five_mobile_push/device'
|
8
|
+
autoload :Notifier, 'five_mobile_push/notifier'
|
9
|
+
autoload :Tag, 'five_mobile_push/tag'
|
10
|
+
|
11
|
+
class UnauthorizedError < StandardError; end
|
12
|
+
class GeneralError < StandardError; end
|
13
|
+
class ServerError < StandardError; end
|
14
|
+
|
15
|
+
|
16
|
+
VALID_OPTION_KEYS = [:api_token, :application_uid]
|
17
|
+
SUPPORTED_PLATFORMS = %w(iphone blackberry android)
|
18
|
+
|
19
|
+
DEFAULT_ID_TYPE = 'native'
|
20
|
+
|
21
|
+
attr_accessor *VALID_OPTION_KEYS
|
22
|
+
|
23
|
+
def configure
|
24
|
+
yield self
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FiveMobilePush::Client do
|
4
|
+
|
5
|
+
let(:application_uid) { 'nulayer' }
|
6
|
+
let(:api_token) { 'token_123' }
|
7
|
+
|
8
|
+
subject { FiveMobilePush::Client.new :api_token => api_token, :application_uid => application_uid }
|
9
|
+
|
10
|
+
it "connects using the fivemobile endpoint" do
|
11
|
+
connection = subject.send(:connection).build_url(nil).to_s
|
12
|
+
endpoint = URI.parse(described_class::DEFAULT_ENDPOINT)
|
13
|
+
connection.should == endpoint.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#device" do
|
17
|
+
|
18
|
+
it "initializes a Device" do
|
19
|
+
subject.device('abc').should be_kind_of(FiveMobilePush::Device)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#notifier" do
|
25
|
+
|
26
|
+
it "initializes a Notifier" do
|
27
|
+
subject.notifier.should be_kind_of(FiveMobilePush::Notifier)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#tag" do
|
33
|
+
|
34
|
+
it "initializes a Tag" do
|
35
|
+
subject.tag('device-uid').should be_kind_of(FiveMobilePush::Tag)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "response code is 400" do
|
41
|
+
|
42
|
+
let(:path) { "https://push.fivemobile.com/rest/some_endpoint?api_token=#{api_token}&application_id=#{application_uid}" }
|
43
|
+
|
44
|
+
it "raises a GeneralError" do
|
45
|
+
stub_request(:any, path).to_return(:body => "something broken", :status => 400)
|
46
|
+
expect { subject.get(path) }.to raise_error(FiveMobilePush::GeneralError)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "response code is 401" do
|
52
|
+
|
53
|
+
let(:path) { "https://push.fivemobile.com/rest/some_endpoint?api_token=#{api_token}&application_id=#{application_uid}" }
|
54
|
+
|
55
|
+
it "raises a GeneralError" do
|
56
|
+
stub_request(:any, path).to_return(:body => "something broken", :status => 401)
|
57
|
+
expect { subject.get(path) }.to raise_error(FiveMobilePush::UnauthorizedError)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "response code is 500" do
|
63
|
+
|
64
|
+
let(:path) { "https://push.fivemobile.com/rest/some_endpoint?api_token=#{api_token}&application_id=#{application_uid}" }
|
65
|
+
|
66
|
+
it "raises a GeneralError" do
|
67
|
+
stub_request(:any, path).to_return(:body => "something broken", :status => 500)
|
68
|
+
expect { subject.get(path) }.to raise_error(FiveMobilePush::ServerError)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FiveMobilePush::Device do
|
4
|
+
|
5
|
+
let(:api_token) { 'token' }
|
6
|
+
|
7
|
+
let(:application_uid) { 'nulayer' }
|
8
|
+
|
9
|
+
let(:client) { FiveMobilePush::Client.new(:api_token => api_token, :application_uid => application_uid) }
|
10
|
+
|
11
|
+
let(:device_uid) { '2b6f0cc904d137be2e1730235f5664094b831186' }
|
12
|
+
|
13
|
+
let(:device_token) { 'ABCDEFG' }
|
14
|
+
|
15
|
+
subject { FiveMobilePush::Device.new(client, device_uid) }
|
16
|
+
|
17
|
+
describe '#register' do
|
18
|
+
|
19
|
+
let(:register_endpoint) { device_endpoint('register') }
|
20
|
+
|
21
|
+
let(:device_info) {
|
22
|
+
{
|
23
|
+
:manufacturer => 'Apple',
|
24
|
+
:model => 'iPhone 4',
|
25
|
+
:platform => 'iOS',
|
26
|
+
:platform_ver => 'iOS 4.3'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
context "registration data is provided" do
|
31
|
+
|
32
|
+
let(:body) { build_request_body(:device_id => device_uid, :reg_data => device_token, :device_info => MultiJson.encode(device_info)) }
|
33
|
+
|
34
|
+
before(:each) do
|
35
|
+
stub_request(:post, register_endpoint).to_return(:body => load_fixture('register.json'))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "registers a device" do
|
39
|
+
subject.register(device_info, device_token)
|
40
|
+
a_request(:post, register_endpoint).with(:body => /device_info=.*reg_data=#{device_token}/).should have_been_made
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns a token on success" do
|
44
|
+
response = subject.register(device_info, device_token)
|
45
|
+
response['data'].should == '52750B30FFBC7DE3B362'
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context "registration data is not provided" do
|
51
|
+
|
52
|
+
it "registers a device" do
|
53
|
+
body = build_request_body(:device_id => device_uid, :device_info => device_info)
|
54
|
+
stub_request(:post, register_endpoint)
|
55
|
+
subject.register(device_info)
|
56
|
+
|
57
|
+
a_request(:post, register_endpoint).with(:body => /reg_data/).should_not have_been_made
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
context "id_value and id_type passed to service" do
|
65
|
+
|
66
|
+
let(:body) { build_request_body(:id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => device_uid) }
|
67
|
+
|
68
|
+
describe '#resume' do
|
69
|
+
|
70
|
+
let(:resume_endpoint) { device_endpoint('resume') }
|
71
|
+
|
72
|
+
it "resumes a device to receive push notifications" do
|
73
|
+
stub_request(:post, resume_endpoint).with(:body => body)
|
74
|
+
subject.resume
|
75
|
+
a_request(:post, resume_endpoint).with(:body => body).should have_been_made
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#suspend' do
|
81
|
+
|
82
|
+
let(:suspend_endpoint) { device_endpoint('suspend') }
|
83
|
+
|
84
|
+
it "suspends a device to not receive any push notifications" do
|
85
|
+
stub_request(:post, suspend_endpoint).with(:body => body)
|
86
|
+
subject.suspend
|
87
|
+
a_request(:post, suspend_endpoint).with(:body => body).should have_been_made
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#unregister" do
|
93
|
+
|
94
|
+
let(:unregister_endpoint) { device_endpoint('unregister') }
|
95
|
+
|
96
|
+
it "unregisters a device from receiving push notifications" do
|
97
|
+
stub_request(:post, unregister_endpoint).with(:body => body)
|
98
|
+
subject.unregister
|
99
|
+
a_request(:post, unregister_endpoint).with(:body => body).should have_been_made
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
def device_endpoint(name)
|
107
|
+
"https://push.fivemobile.com/rest/device/#{name}"
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
describe FiveMobilePush::Notifier do
|
5
|
+
|
6
|
+
let(:api_token) { 'token' }
|
7
|
+
let(:application_uid) { 'nulayer' }
|
8
|
+
let(:client) { FiveMobilePush::Client.new :api_token => api_token, :application_uid => application_uid }
|
9
|
+
|
10
|
+
subject { FiveMobilePush::Notifier.new client }
|
11
|
+
|
12
|
+
let(:payload) do
|
13
|
+
{
|
14
|
+
:msg => {
|
15
|
+
:type => "string",
|
16
|
+
:value => "You sir are awesome"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#broadcast" do
|
22
|
+
|
23
|
+
let(:broadcast_endpoint) { notifier_endpoint('broadcast') }
|
24
|
+
|
25
|
+
it "broadcasts a notification to one or more platforms of the application" do
|
26
|
+
stub_request(:post, broadcast_endpoint)
|
27
|
+
subject.broadcast :iphone, payload
|
28
|
+
a_request(:post, broadcast_endpoint).should have_been_made
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#notify_devices' do
|
34
|
+
|
35
|
+
let(:notify_devices_endpoint) { notifier_endpoint('toDevices') }
|
36
|
+
|
37
|
+
it "notifies a list of devices" do
|
38
|
+
stub_request(:post, notify_devices_endpoint)
|
39
|
+
subject.notify_devices ['abc', 'def'], payload
|
40
|
+
a_request(:post, notify_devices_endpoint).should have_been_made
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#notify_by_tags" do
|
46
|
+
|
47
|
+
let(:notify_by_tags_endpoint) { notifier_endpoint('toTags') }
|
48
|
+
|
49
|
+
it "notifies devices by tags" do
|
50
|
+
stub_request(:post, notify_by_tags_endpoint)
|
51
|
+
subject.notify_by_tags [:iphone, :android], ['tag1', 'tag2'], payload
|
52
|
+
a_request(:post, notify_by_tags_endpoint).should have_been_made
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def notifier_endpoint(name)
|
58
|
+
"https://push.fivemobile.com/rest/notify/#{name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FiveMobilePush::Tag do
|
4
|
+
|
5
|
+
let(:api_token) { 'token' }
|
6
|
+
let(:application_uid) { 'nulayer' }
|
7
|
+
let(:client) { FiveMobilePush::Client.new :api_token => api_token, :application_uid => application_uid }
|
8
|
+
let(:device_uid) { 'ABCD123' }
|
9
|
+
|
10
|
+
subject { FiveMobilePush::Tag.new client, device_uid }
|
11
|
+
|
12
|
+
describe "#create" do
|
13
|
+
|
14
|
+
let(:add_tag_endpoint) { tag_endpoint('add') }
|
15
|
+
let(:tags) { %w(tag1 tag2) }
|
16
|
+
|
17
|
+
it "adds new tags to Five Mobile" do
|
18
|
+
body = build_request_body(:id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => device_uid, :tags => escape(tags.join(',')) )
|
19
|
+
stub_request(:post, add_tag_endpoint).with(:body => body)
|
20
|
+
subject.create tags
|
21
|
+
a_request(:post, add_tag_endpoint).with(:body => body).should have_been_made
|
22
|
+
end
|
23
|
+
|
24
|
+
it "adds a new tag to Five Mobile" do
|
25
|
+
body = build_request_body(:id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => device_uid, :tags => "cheese")
|
26
|
+
stub_request(:post, add_tag_endpoint).with(:body => body)
|
27
|
+
subject.create("cheese")
|
28
|
+
a_request(:post, add_tag_endpoint).with(:body => body).should have_been_made
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#delete" do
|
34
|
+
|
35
|
+
let(:tags) { %w[tag1 tag2] }
|
36
|
+
let(:delete_tag_endpoint) { tag_endpoint("delete") }
|
37
|
+
|
38
|
+
it "unsubscribes from further notifications for tags" do
|
39
|
+
body = build_request_body(:id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => device_uid, :tags => escape(tags.join(',')))
|
40
|
+
stub_request(:post, delete_tag_endpoint).with(:body => body)
|
41
|
+
subject.delete(tags)
|
42
|
+
a_request(:post, delete_tag_endpoint).with(:body => body).should have_been_made
|
43
|
+
end
|
44
|
+
|
45
|
+
it "unsubscribes from further notifications for tag" do
|
46
|
+
body = build_request_body(:id_type => FiveMobilePush::DEFAULT_ID_TYPE, :id_value => device_uid, :tags => "bacon")
|
47
|
+
stub_request(:post, delete_tag_endpoint).with(:body => body)
|
48
|
+
subject.delete("bacon")
|
49
|
+
a_request(:post, delete_tag_endpoint).with(:body => body).should have_been_made
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#get" do
|
55
|
+
end
|
56
|
+
|
57
|
+
def tag_endpoint(name)
|
58
|
+
"https://push.fivemobile.com/rest/device/tags/#{name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FiveMobilePush do
|
4
|
+
|
5
|
+
describe '.api_token' do
|
6
|
+
|
7
|
+
it "sets the api_token" do
|
8
|
+
subject.api_token = "random_key"
|
9
|
+
subject.api_token.should == "random_key"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.application_uid' do
|
15
|
+
|
16
|
+
it "sets the application_uid" do
|
17
|
+
subject.application_uid = 'nulayer'
|
18
|
+
subject.application_uid.should == 'nulayer'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'configure' do
|
24
|
+
|
25
|
+
FiveMobilePush::VALID_OPTION_KEYS.each do |key|
|
26
|
+
|
27
|
+
it "sets the key #{key}" do
|
28
|
+
FiveMobilePush.configure do |config|
|
29
|
+
config.send("#{key}=", key)
|
30
|
+
end
|
31
|
+
FiveMobilePush.send(key).should == key
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'platforms' do
|
39
|
+
|
40
|
+
%w(iphone blackberry android).each do |platform|
|
41
|
+
|
42
|
+
specify { FiveMobilePush::SUPPORTED_PLATFORMS.should include(platform) }
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"type":"api_token","data":"52750B30FFBC7DE3B362","active":true}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'five_mobile_push'
|
2
|
+
require 'rspec'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'yajl'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.mock_with :rspec
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_fixture(name)
|
12
|
+
File.read File.expand_path("../fixtures/#{name}", __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
def build_request_body(data)
|
16
|
+
data = data.merge(:api_token => api_token, :application_id => application_uid)
|
17
|
+
String.new.tap do |body|
|
18
|
+
data.each do |key,value|
|
19
|
+
body << "#{key}=#{value}"
|
20
|
+
body << "&" unless key == :application_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# URI escape
|
26
|
+
def escape(s)
|
27
|
+
URI.escape(s).gsub(',', '%2C')
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: five_mobile_push
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kevin Faustino
|
9
|
+
- James Herdman
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-03-30 00:00:00 -04:00
|
15
|
+
default_executable:
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: multi_json
|
19
|
+
prerelease: false
|
20
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
22
|
+
requirements:
|
23
|
+
- - ~>
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.0.5
|
26
|
+
type: :runtime
|
27
|
+
version_requirements: *id001
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: faraday
|
30
|
+
prerelease: false
|
31
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ~>
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.5.7
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id002
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rspec
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.5.0
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id003
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: yajl-ruby
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id004
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: webmock
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
type: :development
|
71
|
+
version_requirements: *id005
|
72
|
+
description: API wrapper for Five Mobile Push notification service
|
73
|
+
email:
|
74
|
+
- kevin.faustino@gmail.com
|
75
|
+
- james.herdman@me.com
|
76
|
+
executables: []
|
77
|
+
|
78
|
+
extensions: []
|
79
|
+
|
80
|
+
extra_rdoc_files: []
|
81
|
+
|
82
|
+
files:
|
83
|
+
- .gitignore
|
84
|
+
- .rspec
|
85
|
+
- Gemfile
|
86
|
+
- Rakefile
|
87
|
+
- five_mobile_push.gemspec
|
88
|
+
- lib/faraday/errors.rb
|
89
|
+
- lib/five_mobile_push.rb
|
90
|
+
- lib/five_mobile_push/client.rb
|
91
|
+
- lib/five_mobile_push/device.rb
|
92
|
+
- lib/five_mobile_push/notifier.rb
|
93
|
+
- lib/five_mobile_push/tag.rb
|
94
|
+
- lib/five_mobile_push/version.rb
|
95
|
+
- spec/five_mobile_push/client_spec.rb
|
96
|
+
- spec/five_mobile_push/device_spec.rb
|
97
|
+
- spec/five_mobile_push/notifier_spec.rb
|
98
|
+
- spec/five_mobile_push/tags_spec.rb
|
99
|
+
- spec/five_mobile_push_spec.rb
|
100
|
+
- spec/fixtures/register.json
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
has_rdoc: true
|
103
|
+
homepage: ""
|
104
|
+
licenses: []
|
105
|
+
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
123
|
+
requirements: []
|
124
|
+
|
125
|
+
rubyforge_project: five_mobile_push
|
126
|
+
rubygems_version: 1.6.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: API wrapper for Five Mobile Push notification service
|
130
|
+
test_files:
|
131
|
+
- spec/five_mobile_push/client_spec.rb
|
132
|
+
- spec/five_mobile_push/device_spec.rb
|
133
|
+
- spec/five_mobile_push/notifier_spec.rb
|
134
|
+
- spec/five_mobile_push/tags_spec.rb
|
135
|
+
- spec/five_mobile_push_spec.rb
|
136
|
+
- spec/fixtures/register.json
|
137
|
+
- spec/spec_helper.rb
|