rack-gcm 0.0.1
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 +3 -0
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/Rakefile +10 -0
- data/lib/rack/gcm/migrations/001_base_schema.rb +25 -0
- data/lib/rack/gcm/migrations/002_add_full_text_search.rb +16 -0
- data/lib/rack/gcm/models/device.rb +30 -0
- data/lib/rack/gcm/version.rb +5 -0
- data/lib/rack/gcm.rb +72 -0
- data/rack-gcm-0.0.1.gem +0 -0
- data/rack-gcm.gemspec +29 -0
- metadata +170 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Min Kim
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Sequel.migration do
|
|
2
|
+
up do
|
|
3
|
+
create_table :gcm_devices do
|
|
4
|
+
primary_key :id
|
|
5
|
+
|
|
6
|
+
column :token, :varchar, empty: false, unique: true
|
|
7
|
+
column :alias, :varchar
|
|
8
|
+
column :locale, :varchar
|
|
9
|
+
column :language, :varchar
|
|
10
|
+
column :timezone, :varchar, empty: false, default: 'UTC'
|
|
11
|
+
column :ip_address, :inet
|
|
12
|
+
column :lat, :float8
|
|
13
|
+
column :lng, :float8
|
|
14
|
+
column :tags, :'text[]'
|
|
15
|
+
|
|
16
|
+
index :token
|
|
17
|
+
index :alias
|
|
18
|
+
index [:lat, :lng]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
down do
|
|
23
|
+
drop_table :gcm_devices
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Sequel.migration do
|
|
2
|
+
up do
|
|
3
|
+
add_column :gcm_devices, :tsv, 'TSVector'
|
|
4
|
+
add_index :gcm_devices, :tsv, type: "GIN"
|
|
5
|
+
create_trigger :gcm_devices, :tsv, :tsvector_update_trigger,
|
|
6
|
+
args: [:tsv, :'pg_catalog.english', :token, :alias, :locale, :timezone],
|
|
7
|
+
events: [:insert, :update],
|
|
8
|
+
each_row: true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
down do
|
|
12
|
+
drop_column :gcm_devices, :tsv
|
|
13
|
+
drop_index :gcm_devices, :tsv
|
|
14
|
+
drop_trigger :gcm_devices, :tsv
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
class GCM::Device < Sequel::Model
|
|
3
|
+
plugin :json_serializer, naked: true, except: :id
|
|
4
|
+
plugin :validation_helpers
|
|
5
|
+
plugin :timestamps, force: true, update_on_create: true
|
|
6
|
+
plugin :schema
|
|
7
|
+
|
|
8
|
+
self.dataset = :push_notification_devices
|
|
9
|
+
self.strict_param_setting = false
|
|
10
|
+
self.raise_on_save_failure = false
|
|
11
|
+
|
|
12
|
+
def before_validation
|
|
13
|
+
# normalize_token!
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def validate
|
|
17
|
+
super
|
|
18
|
+
|
|
19
|
+
validates_presence :token
|
|
20
|
+
validates_unique :token
|
|
21
|
+
# validates_format /[[:xdigit:]]{40}/, :token
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def normalize_token!
|
|
27
|
+
self.token = self.token.strip.gsub(/[<\s>]/, '')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/rack/gcm.rb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'rack'
|
|
2
|
+
require 'rack/contrib'
|
|
3
|
+
|
|
4
|
+
require 'sinatra/base'
|
|
5
|
+
require 'sinatra/param'
|
|
6
|
+
|
|
7
|
+
require 'sequel'
|
|
8
|
+
|
|
9
|
+
module Rack
|
|
10
|
+
class GCM < Sinatra::Base
|
|
11
|
+
use Rack::PostBodyContentTypeParser
|
|
12
|
+
helpers Sinatra::Param
|
|
13
|
+
|
|
14
|
+
disable :raise_errors, :show_exceptions
|
|
15
|
+
|
|
16
|
+
autoload :Device, 'rack/gcm/models/device'
|
|
17
|
+
|
|
18
|
+
configure do
|
|
19
|
+
if ENV['DATABASE_URL']
|
|
20
|
+
Sequel.extension :pg_array, :migration
|
|
21
|
+
|
|
22
|
+
DB = Sequel.connect(ENV['DATABASE_URL'])
|
|
23
|
+
DB.extend Sequel::Postgres::PGArray::DatabaseMethods
|
|
24
|
+
Sequel::Migrator.run(DB, ::File.join(::File.dirname(__FILE__), 'gcm/migrations'), table: 'gcm_schema_info')
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
before do
|
|
29
|
+
content_type :json
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
post '/register/?' do
|
|
33
|
+
param :languages, Array
|
|
34
|
+
param :tags, Array
|
|
35
|
+
|
|
36
|
+
if params[:regId]
|
|
37
|
+
record = Device.find(token: params[:regId]) || Device.new
|
|
38
|
+
|
|
39
|
+
# let's keep Google's standard parameter name
|
|
40
|
+
params[:token] = params[:regId]
|
|
41
|
+
record.set(params)
|
|
42
|
+
|
|
43
|
+
code = record.new? ? 201 : 200
|
|
44
|
+
|
|
45
|
+
if record.save
|
|
46
|
+
status code
|
|
47
|
+
{device: record}.to_json
|
|
48
|
+
else
|
|
49
|
+
status 400
|
|
50
|
+
{errors: record.errors}.to_json
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
status 400
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
post '/unregister/?' do
|
|
58
|
+
if params[:regId]
|
|
59
|
+
record = Device.find(token: params[:regId]) or halt 404
|
|
60
|
+
|
|
61
|
+
if record.destroy
|
|
62
|
+
status 200
|
|
63
|
+
else
|
|
64
|
+
status 400
|
|
65
|
+
{errors: record.errors}.to_json
|
|
66
|
+
end
|
|
67
|
+
else
|
|
68
|
+
status 400
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
data/rack-gcm-0.0.1.gem
ADDED
|
File without changes
|
data/rack-gcm.gemspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'rack/gcm/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = "rack-gcm"
|
|
8
|
+
s.authors = ["Min Kim"]
|
|
9
|
+
s.email = ["minsikzzang@gmail.com", "minsik.kim@livestation.com"]
|
|
10
|
+
s.homepage = "https://github.com/minsikzzang/rack-gcm"
|
|
11
|
+
s.version = Rack::GCM::VERSION
|
|
12
|
+
s.platform = Gem::Platform::RUBY
|
|
13
|
+
s.summary = "REST API Rack for Google cloud message token registration"
|
|
14
|
+
s.description = "Generate a REST API for registering and querying Google cloud message device tokens."
|
|
15
|
+
|
|
16
|
+
s.add_dependency "rack", "~> 1.4"
|
|
17
|
+
s.add_dependency "rack-contrib", "~> 1.1"
|
|
18
|
+
s.add_dependency "sequel", "~> 3.37"
|
|
19
|
+
s.add_dependency "sinatra", "~> 1.3"
|
|
20
|
+
s.add_dependency "sinatra-param", "~> 0.1"
|
|
21
|
+
|
|
22
|
+
s.add_development_dependency "rspec"
|
|
23
|
+
s.add_development_dependency "rake"
|
|
24
|
+
|
|
25
|
+
s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|example|log|pkg|script|spec|test|vendor)/ }
|
|
26
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
27
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
28
|
+
s.require_paths = ["lib"]
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rack-gcm
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Min Kim
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rack
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1.4'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.4'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rack-contrib
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ~>
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '1.1'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '1.1'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: sequel
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ~>
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '3.37'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.37'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: sinatra
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ~>
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '1.3'
|
|
70
|
+
type: :runtime
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ~>
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '1.3'
|
|
78
|
+
- !ruby/object:Gem::Dependency
|
|
79
|
+
name: sinatra-param
|
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
82
|
+
requirements:
|
|
83
|
+
- - ~>
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0.1'
|
|
86
|
+
type: :runtime
|
|
87
|
+
prerelease: false
|
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
+
none: false
|
|
90
|
+
requirements:
|
|
91
|
+
- - ~>
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0.1'
|
|
94
|
+
- !ruby/object:Gem::Dependency
|
|
95
|
+
name: rspec
|
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
|
97
|
+
none: false
|
|
98
|
+
requirements:
|
|
99
|
+
- - ! '>='
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
type: :development
|
|
103
|
+
prerelease: false
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
none: false
|
|
106
|
+
requirements:
|
|
107
|
+
- - ! '>='
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rake
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
none: false
|
|
114
|
+
requirements:
|
|
115
|
+
- - ! '>='
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
none: false
|
|
122
|
+
requirements:
|
|
123
|
+
- - ! '>='
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
126
|
+
description: Generate a REST API for registering and querying Google cloud message
|
|
127
|
+
device tokens.
|
|
128
|
+
email:
|
|
129
|
+
- minsikzzang@gmail.com
|
|
130
|
+
- minsik.kim@livestation.com
|
|
131
|
+
executables: []
|
|
132
|
+
extensions: []
|
|
133
|
+
extra_rdoc_files: []
|
|
134
|
+
files:
|
|
135
|
+
- ./Gemfile
|
|
136
|
+
- ./lib/rack/gcm/migrations/001_base_schema.rb
|
|
137
|
+
- ./lib/rack/gcm/migrations/002_add_full_text_search.rb
|
|
138
|
+
- ./lib/rack/gcm/models/device.rb
|
|
139
|
+
- ./lib/rack/gcm/version.rb
|
|
140
|
+
- ./lib/rack/gcm.rb
|
|
141
|
+
- ./LICENSE
|
|
142
|
+
- ./rack-gcm-0.0.1.gem
|
|
143
|
+
- ./rack-gcm.gemspec
|
|
144
|
+
- ./Rakefile
|
|
145
|
+
- ./README.md
|
|
146
|
+
homepage: https://github.com/minsikzzang/rack-gcm
|
|
147
|
+
licenses: []
|
|
148
|
+
post_install_message:
|
|
149
|
+
rdoc_options: []
|
|
150
|
+
require_paths:
|
|
151
|
+
- lib
|
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
|
+
none: false
|
|
154
|
+
requirements:
|
|
155
|
+
- - ! '>='
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: '0'
|
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
|
+
none: false
|
|
160
|
+
requirements:
|
|
161
|
+
- - ! '>='
|
|
162
|
+
- !ruby/object:Gem::Version
|
|
163
|
+
version: '0'
|
|
164
|
+
requirements: []
|
|
165
|
+
rubyforge_project:
|
|
166
|
+
rubygems_version: 1.8.24
|
|
167
|
+
signing_key:
|
|
168
|
+
specification_version: 3
|
|
169
|
+
summary: REST API Rack for Google cloud message token registration
|
|
170
|
+
test_files: []
|