faast 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +35 -0
- data/Rakefile +27 -0
- data/faast.gemspec +20 -0
- data/lib/faast.rb +98 -0
- data/lib/faast/version.rb +9 -0
- data/test/test_helper.rb +7 -0
- data/test/test_post.rb +24 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f96e92940ec6183438d43391cb63f11a747bc68e
|
4
|
+
data.tar.gz: 59a1539092c2769659be16519eac13431a8b622a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3dab61332d6dc16125a4116bc64450caf613e8389ee155651d035a60034e3ab26fe03ef53d7525741d23611833587dc3edb8230f5500305a32109aa773ce7bad
|
7
|
+
data.tar.gz: 2a439ed6e059f5cdc95c37baf4e3f30cded5ac2842458fdaaa2015db387c6903a561a1a971dbde7af55bd5dd639743e531548ad0f39f1e7ac71115b3ed4e7ede
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Chris Lucas <chris@chrisjlucas.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
[![Coverage Status](https://coveralls.io/repos/cjlucas/ruby-faast/badge.png)](https://coveralls.io/r/cjlucas/ruby-faast)
|
2
|
+
[![Build Status](https://travis-ci.org/cjlucas/ruby-faast.png?branch=master)](https://travis-ci.org/cjlucas/ruby-faast)
|
3
|
+
|
4
|
+
This is a simple library for the [Faast](http://www.faast.io/) push notification service.
|
5
|
+
|
6
|
+
Currently only the REST API is supported.
|
7
|
+
|
8
|
+
---
|
9
|
+
## Synopsis ##
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'faast'
|
13
|
+
|
14
|
+
# user credentials can be set at the module level or directly in the Notification instance
|
15
|
+
Faast.user_credentials = 'api_key'
|
16
|
+
|
17
|
+
# create a notification instance
|
18
|
+
notification = Faast::Notification.new
|
19
|
+
|
20
|
+
notification.title = 'This is the title'
|
21
|
+
notification.message = 'This is the message'
|
22
|
+
notfication.icon_url = 'https://github.com/favicon.ico'
|
23
|
+
|
24
|
+
notification.send
|
25
|
+
# => #<Net::HTTPOK 200 OK readbody=true>
|
26
|
+
|
27
|
+
# or use the block interface (this is prefered)
|
28
|
+
resp = Faast::Notification.send do |notification|
|
29
|
+
notification.title = 'This is the title'
|
30
|
+
notification.message = 'This is the message'
|
31
|
+
notfication.icon_url = 'https://github.com/favicon.ico'
|
32
|
+
end
|
33
|
+
|
34
|
+
resp
|
35
|
+
# => #<Net::HTTPOK 200 OK readbody=true>
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
require 'faast/version'
|
6
|
+
|
7
|
+
task :default => [:test]
|
8
|
+
|
9
|
+
task :test do
|
10
|
+
Rake::TestTask.new do |t|
|
11
|
+
t.libs << 'test'
|
12
|
+
t.test_files = FileList['test/test_*.rb']
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
task :build do
|
18
|
+
system 'gem build faast.gemspec'
|
19
|
+
end
|
20
|
+
|
21
|
+
task :release => :build do
|
22
|
+
system "gem push faast-#{Faast::VERSION}.gem"
|
23
|
+
end
|
24
|
+
|
25
|
+
task :clean do
|
26
|
+
system 'rm -f *.gem'
|
27
|
+
end
|
data/faast.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
2
|
+
|
3
|
+
require 'faast/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'faast'
|
7
|
+
s.version = Faast::VERSION
|
8
|
+
s.summary = 'A ruby library for the Faast push notification service'
|
9
|
+
#s.description = <<-EOF
|
10
|
+
#EOF
|
11
|
+
s.authors = ['Chris Lucas']
|
12
|
+
s.email = ['chris@chrisjlucas.com']
|
13
|
+
s.homepage = 'https://github.com/cjlucas/ruby-faast'
|
14
|
+
s.license = 'MIT'
|
15
|
+
s.files = `git ls-files | egrep '^[^\.]'`.split(/\r?\n/)
|
16
|
+
s.test_files = s.files.select { |f| f.match(/^test\/.*\.rb$/) }
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
|
19
|
+
s.add_development_dependency('rake')
|
20
|
+
end
|
data/lib/faast.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Faast
|
4
|
+
URL = 'https://www.appnotifications.com/account/notifications.json'
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :user_credentials
|
8
|
+
end
|
9
|
+
|
10
|
+
class Notification
|
11
|
+
attr_accessor :user_credentials
|
12
|
+
attr_accessor :message
|
13
|
+
attr_accessor :long_message
|
14
|
+
attr_accessor :long_message_preview
|
15
|
+
attr_accessor :title
|
16
|
+
attr_accessor :subtitle
|
17
|
+
attr_accessor :message_level
|
18
|
+
attr_accessor :silent
|
19
|
+
attr_accessor :action_loc_key
|
20
|
+
attr_accessor :icon_url
|
21
|
+
attr_accessor :sound
|
22
|
+
|
23
|
+
simple_fields = [
|
24
|
+
:message,
|
25
|
+
:long_message,
|
26
|
+
:long_message_preview,
|
27
|
+
:title,
|
28
|
+
:subtitle,
|
29
|
+
:action_loc_key,
|
30
|
+
:icon_url,
|
31
|
+
]
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@data = {}
|
35
|
+
self.user_credentials = Faast.user_credentials
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_credentials=(user_credentials)
|
39
|
+
@user_credentials = user_credentials
|
40
|
+
@data['user_credentials'] = user_credentials
|
41
|
+
end
|
42
|
+
|
43
|
+
def message_level=(message_level)
|
44
|
+
self.class.assert_num_in_range(message_level, -2..2)
|
45
|
+
@message_level = message_level
|
46
|
+
@data['notification[message_level]'] = message_level
|
47
|
+
end
|
48
|
+
|
49
|
+
def silent=(silent)
|
50
|
+
@silent = silent
|
51
|
+
@data['notification[silent]'] = silent ? 1 : 0
|
52
|
+
end
|
53
|
+
|
54
|
+
def sound=(sound)
|
55
|
+
self.class.assert_num_in_range(sound, 1..40)
|
56
|
+
@sound = sound
|
57
|
+
@data['notification[sound]'] = sound
|
58
|
+
end
|
59
|
+
|
60
|
+
def send
|
61
|
+
uri = URI(URL)
|
62
|
+
|
63
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
64
|
+
http.use_ssl = true
|
65
|
+
|
66
|
+
req = Net::HTTP::Post.new(uri.to_s)
|
67
|
+
req.set_form_data(@data)
|
68
|
+
|
69
|
+
http.request(req)
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.send
|
73
|
+
if block_given?
|
74
|
+
notif = self.new
|
75
|
+
yield notif
|
76
|
+
notif.send
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# create setters for simple fields
|
81
|
+
simple_fields.each do |field|
|
82
|
+
define_method("#{field}=") do |input|
|
83
|
+
ivar = "@#{field}"
|
84
|
+
url_param = "notification[#{field}]"
|
85
|
+
instance_variable_set(ivar, input)
|
86
|
+
@data[url_param] = input
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def self.assert_num_in_range(num, range)
|
93
|
+
unless range.include?(num)
|
94
|
+
raise ArgumentError, "Expected number between #{range}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/test_post.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'faast'
|
4
|
+
|
5
|
+
class TestPost < Test::Unit::TestCase
|
6
|
+
def test_post_no_api_key
|
7
|
+
resp = Faast::Notification.send { |notification| }
|
8
|
+
assert_block { resp.is_a?(Net::HTTPUnauthorized) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_post_with_api_key
|
12
|
+
user_credentials_file = File.expand_path('../user_creds.txt', __FILE__)
|
13
|
+
|
14
|
+
if File.exists?(user_credentials_file)
|
15
|
+
resp = Faast::Notification.send do |notification|
|
16
|
+
notification.user_credentials = File.read(user_credentials_file).strip
|
17
|
+
notification.title = '[ruby-faast] this is the title'
|
18
|
+
notification.message = '[ruby-faast] this is the message'
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_block { resp.is_a?(Net::HTTPSuccess) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Lucas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- chris@chrisjlucas.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- faast.gemspec
|
40
|
+
- lib/faast.rb
|
41
|
+
- lib/faast/version.rb
|
42
|
+
- test/test_helper.rb
|
43
|
+
- test/test_post.rb
|
44
|
+
homepage: https://github.com/cjlucas/ruby-faast
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 2.1.11
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: A ruby library for the Faast push notification service
|
68
|
+
test_files:
|
69
|
+
- test/test_helper.rb
|
70
|
+
- test/test_post.rb
|