push4 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0433449ec2d3a7a12231af942d69152105e5d2fb
4
+ data.tar.gz: f5130b784271486c3b4a3d88a89b5513e5ba3af4
5
+ SHA512:
6
+ metadata.gz: 9425386e2587a9afe6935c404d6a193c65889ddf126d15419b00a67daff076381d37d2ea1767c50f31988be2c4ddc428ad8be35db30e5f0f5751e8d209dc6269
7
+ data.tar.gz: e09a65b0b3582dd6631aa25acc6ccd743912ba6f1e4bdd47f3967af1d841013baf704d0f98c59fdc660f6576c2010869bab7c1187f295841527fec525ee4c1b4
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ##### v0.0.1 (2013-06-09) #####
2
+ * initial release
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,32 @@
1
+ This is a simple library for the [Push 4.0](http://www.appnotifications.com/) API.
2
+
3
+ Currently only the REST API is supported.
4
+
5
+ ---
6
+ ## Synopsis ##
7
+
8
+ ```ruby
9
+ require 'push4'
10
+
11
+ # user credentials can be set at the module level or directly in the Notification instance
12
+ Push4.user_credential = push4_key
13
+
14
+ # create a notification instance
15
+ notification = Push4::Notification.new
16
+
17
+ notification.title = 'This is the title'
18
+ notification.message = 'This is the message'
19
+ notfication.icon_url = 'https://github.com/favicon.ico'
20
+
21
+ notification.send
22
+ # => #<Net::HTTPOK 200 OK readbody=true>
23
+
24
+ # or use the block interface (this is prefered)
25
+ resp = Push4::Notification.send do |notification|
26
+ notification.title = 'This is the title'
27
+ notification.message = 'This is the message'
28
+ notfication.icon_url = 'https://github.com/favicon.ico'
29
+ end
30
+
31
+ resp
32
+ # => #<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 'push4/version'
6
+
7
+ #task :default => [:build]
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 = false
14
+ #end
15
+ #end
16
+
17
+ task :build do
18
+ system 'gem build push4.gemspec'
19
+ end
20
+
21
+ task :release => :build do
22
+ system "gem push push4-#{Push4::VERSION}.gem"
23
+ end
24
+
25
+ task :clean do
26
+ system 'rm -f *.gem'
27
+ end
@@ -0,0 +1,9 @@
1
+ module Push4
2
+ class Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+ end
7
+
8
+ VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].join('.')
9
+ end
data/lib/push4.rb ADDED
@@ -0,0 +1,86 @@
1
+ require 'net/http'
2
+
3
+ module Push4
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
+ :user_credentials,
25
+ :message,
26
+ :long_message,
27
+ :long_message_preview,
28
+ :title,
29
+ :subtitle,
30
+ :action_loc_key,
31
+ :icon_url,
32
+ ]
33
+
34
+ def initialize
35
+ @data = {}
36
+ @data['user_credentials'] = Push4.user_credentials
37
+ end
38
+
39
+ def message_level=(message_level)
40
+ self.class.assert_num_in_range(message_level, -2..2)
41
+ @message_level = message_level
42
+ @data['notification[message_level]'] = message_level
43
+ end
44
+
45
+ def silent=(silent)
46
+ @silent = silent
47
+ @data['notification[silent]'] = silent ? 1 : 0
48
+ end
49
+
50
+ def sound=(sound)
51
+ self.class.assert_num_in_range(sound, 1..40)
52
+ @sound = sound
53
+ @data['notification[sound]'] = sound
54
+ end
55
+
56
+ def send
57
+ Net::HTTP.post_form(URI(Push4::URL), @data)
58
+ end
59
+
60
+ def self.send
61
+ if block_given?
62
+ notif = self.new
63
+ yield notif
64
+ notif.send
65
+ end
66
+ end
67
+
68
+ # create setters for simple fields
69
+ simple_fields.each do |field|
70
+ define_method("#{field}=") do |input|
71
+ ivar = "@#{field}"
72
+ url_param = "notification[#{field}]"
73
+ instance_variable_set(ivar, input)
74
+ @data[url_param] = input
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def self.assert_num_in_range(num, range)
81
+ unless range.include?(num)
82
+ raise ArgumentError.new("Expected number between #{range}")
83
+ end
84
+ end
85
+ end
86
+ end
data/push4.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
2
+
3
+ require 'push4/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'push4'
7
+ s.version = Push4::VERSION
8
+ s.summary = 'A ruby library for the Push 4.0 API'
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-push4'
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
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: push4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Lucas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-09 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
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - lib/push4.rb
39
+ - lib/push4/version.rb
40
+ - push4.gemspec
41
+ homepage: https://github.com/cjlucas/ruby-push4
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.0.3
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A ruby library for the Push 4.0 API
65
+ test_files: []