push_bot 0.4.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e065854bc27948088fbb46998f9d938540739268
4
+ data.tar.gz: 3c4f45347da77397b8a3f40ea04df2b2c76517a5
5
+ SHA512:
6
+ metadata.gz: 1e24692a953b753c62b614cdcfc3febb768857223c56d4242ee916eead25f3967e549561768d7a3ae8d8a589ec68e8453cd4ae5c5573a669c9efa9a3f8dc0729
7
+ data.tar.gz: 40ca316c939f63c13cddac4ff62dbab1e565522c2e3770a58e762d2ce4c2a3c17ffb801297d2c31ff5933c532e1a288b94333405bc79d01150c24f6657fc6b55
data/.gitignore ADDED
@@ -0,0 +1,30 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore all logfiles and tempfiles.
11
+ /log/*.log
12
+ /tmp
13
+
14
+ .idea
15
+ .rbx
16
+
17
+ .sass-cache
18
+ .scss-cache
19
+
20
+ _Yardoc
21
+ .DS_Store
22
+ *.rbc
23
+ *.pdf
24
+ .yardoc
25
+ *.gem
26
+
27
+ /pkg
28
+ /doc
29
+ /doc_guide
30
+ /coverage
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ push_bot
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,10 @@
1
+ Contributions to this project will be taken based on adherence to the style already used and subjective code quality.
2
+
3
+ If you need a feature chances are others need it too
4
+
5
+ The Process goes:
6
+ 1. Fork it ( https://github.com/[my-github-username]/push_bot/fork )
7
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
8
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
9
+ 4. Push to the branch (`git push origin my-new-feature`)
10
+ 5. Create a new Pull Request
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ push_bot (0.4.0)
5
+ typhoeus (~> 0.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ethon (0.7.1)
11
+ ffi (>= 1.3.0)
12
+ ffi (1.9.5)
13
+ rake (10.3.2)
14
+ typhoeus (0.6.9)
15
+ ethon (>= 0.7.1)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler (~> 1.7)
22
+ push_bot!
23
+ rake (~> 10.0)
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brian Norton
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
@@ -0,0 +1,67 @@
1
+ # PushBot
2
+
3
+ PushBot is the Ruby Gem for connecting to the PushBots push notification service
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'push_bot'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install push_bot
20
+
21
+ ## Usage
22
+
23
+ #### Configuration
24
+ ```ruby
25
+ # config/initializers/push_bot.rb
26
+
27
+ PushBot.configure do |config|
28
+ config.id = 'Your Application ID'
29
+ config.secret = 'Your Application Secret'
30
+ end
31
+ ```
32
+
33
+ #### Register a Device Token
34
+ ```ruby
35
+ # push token is the token given my the phone's OS
36
+ # platform is :ios or :android
37
+
38
+ device = PushBot::Device.new(user.push_token, user.platform)
39
+ device.add
40
+ ```
41
+
42
+ ####Push a notification to a token
43
+ ```ruby
44
+ push = PushBot::Push.new(user.push_token, user.platform)
45
+ push.notify('Hello and Welcome to the App!')
46
+ ```
47
+
48
+ #### Register a Device Token to an alias
49
+ ```ruby
50
+ # push token is the token given my the phone's OS
51
+ # platform is :ios or :android
52
+
53
+ device = PushBot::Device.new(user.push_token, user.platform)
54
+ device.add(:alias => user.email)
55
+ ```
56
+
57
+ ####Push a notification to an alias
58
+ ```ruby
59
+ push = PushBot::Push.new(nil, user.platform)
60
+ push.notify('Hello and Welcome to the App!', :alias => user.email)
61
+ ```
62
+
63
+ ####Device Info
64
+ ```ruby
65
+ device = PushBot::Device.new(user.push_token, user.platform)
66
+ device.info
67
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
data/lib/push_bot.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'push_bot/api'
2
+ require 'push_bot/config'
3
+ require 'push_bot/device'
4
+ require 'push_bot/location'
5
+ require 'push_bot/platform'
6
+ require 'push_bot/push'
7
+ require 'push_bot/request'
8
+ require 'push_bot/response'
9
+ require 'push_bot/tag'
10
+
11
+ module PushBot
12
+ def self.configure(&block)
13
+ Config.configure(&block)
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ module PushBot
2
+ class Api
3
+ attr_accessor :token, :platforms, :platform
4
+
5
+ # Create a new Api object with an associated token and platform
6
+ #
7
+ # @param token the user identifier for your platform
8
+ # @param platform one of `:ios` or `:android` to indicate which platform the user uses
9
+ def initialize(token, platform)
10
+ @token = token
11
+ @platforms = Platform.parse(platform)
12
+ @platform = platforms.first
13
+ end
14
+
15
+ # Does this request represent a tokened single user or is it a batch request
16
+ def token?
17
+ (defined?(@token) && @token) ? true : false
18
+ end
19
+
20
+ # Does this request apply to a single user
21
+ def user?
22
+ token?
23
+ end
24
+
25
+ # Does this batch apply to a segment
26
+ def batch?
27
+ !token?
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ module PushBot
2
+ class Config
3
+ attr_accessor :id, :secret
4
+
5
+ def self.config
6
+ @config ||= new
7
+ end
8
+
9
+ def self.configure
10
+ yield(config) if block_given?
11
+
12
+ config
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ module PushBot
2
+ class Device < Api
3
+ # Add a specific user or batch of users to PushBots
4
+ #
5
+ # @param registration_options Any of the options available {https://pushbots.com/developer/rest Rest Docs @ PushBots}
6
+ # @return {PushBot::Response}
7
+ def add(registration_options={})
8
+ raise(ArgumentError, 'Batch device add should only be to a single platform') if Array === token && platforms.size != 1
9
+
10
+ options, type = registration_options.merge(
11
+ :platform => platform
12
+ ), :batch
13
+
14
+ if user?
15
+ type = nil
16
+ options[:token] = token
17
+ end
18
+
19
+ Request.new(:deviceToken).put(type, options)
20
+ end
21
+
22
+ def info
23
+ Request.new(:deviceToken).get(:one, :token => token)
24
+ end
25
+
26
+ # Remove a specific user from PushBots
27
+ #
28
+ # @return {PushBot::Response}
29
+ def remove
30
+ raise(ArgumentError, 'A token and platform is required for removal') unless token && token
31
+
32
+ Request.new(:deviceToken).put(:del, :token => token, :platform => platform)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module PushBot
2
+ class Location
3
+
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ module PushBot
2
+ class Platform
3
+ VALUES = %w(ios android)
4
+
5
+ def self.parse(*platforms)
6
+ platforms = platforms.flatten.map! {|p| VALUES.index(p.to_s.downcase) }
7
+ raise(ArgumentError, 'Platform must be ios or android') if platforms.any?(&:nil?)
8
+
9
+ platforms.map!(&:to_s)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ module PushBot
2
+ class Push < Api
3
+ # Push a new message to the Segment
4
+ #
5
+ # @param message The message to alert the user with
6
+ # @param push_options Any of the options available {https://pushbots.com/developer/rest Rest Docs @ PushBots}
7
+ # @return {PushBot::Response}
8
+ def notify(message, push_options={})
9
+ options = { :sound => '' }
10
+ options, type = options.merge(push_options).merge(
11
+ :msg => message,
12
+ :platform => platforms
13
+ ), :all
14
+
15
+ unless batch?
16
+ type = :one
17
+ options[:badge] ||= '0'
18
+ options[:token] = token
19
+ options[:platform] = platform
20
+ end
21
+
22
+ Request.new(:push).post(type, options)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,46 @@
1
+ module PushBot
2
+ class Request
3
+ def initialize(base)
4
+ @base = base
5
+ end
6
+
7
+ def get(name, options)
8
+ request(:get, name, options)
9
+ end
10
+
11
+ def post(name, options)
12
+ request(:post, name, options)
13
+ end
14
+
15
+ def put(name, options)
16
+ request(:put, name, options)
17
+ end
18
+
19
+ private
20
+
21
+ def request(type, name, options)
22
+ url = "https://api.pushbots.com/#{@base}"
23
+ url << "/#{name}" if name
24
+
25
+ request_options = {
26
+ :method => type,
27
+ :body => JSON.dump(options),
28
+ :headers => {
29
+ :'X-PushBots-AppID' => Config.config.id,
30
+ :'X-PushBots-Secret' => Config.config.secret,
31
+ :'Content-Type' => 'application/json'
32
+ }
33
+ }
34
+
35
+ if type == :get
36
+ request_options[:headers][:Token] = options[:token]
37
+ end
38
+
39
+ puts "Sending request:#{type} url:#{url} options:#{request_options.inspect}"
40
+
41
+ request = Typhoeus::Request.new(url, request_options)
42
+
43
+ Response.new(request)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ module PushBot
2
+ class Response
3
+ attr_reader :raw_response, :error
4
+
5
+ def initialize(request)
6
+ @raw_response = request.run
7
+
8
+ @success = raw_response.success?
9
+ rescue => e
10
+ @error = e
11
+ end
12
+
13
+ def inspect
14
+ "#<#{self.class}:#{object_id} @success=#{success?} @json=#{json}>"
15
+ end
16
+
17
+ # Did the request complete successfully or have issues
18
+ def success?
19
+ defined?(@success) && @success
20
+ end
21
+
22
+ # Did the response complete with an error
23
+ def error?
24
+ defined?(@error) && @error
25
+ end
26
+
27
+ # The raw response body string
28
+ def body
29
+ raw_response.try(:body)
30
+ end
31
+
32
+ # The result of the request as a JSON Object
33
+ #
34
+ # @return [Hash, Array] the JSON Object
35
+ def json
36
+ @json ||= body.present? ? JSON.parse(body) : {}
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module PushBot
2
+ class Tag
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module PushBot
2
+ VERSION = '0.4.0'
3
+ end
data/push_bot.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'push_bot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'push_bot'
8
+ spec.version = PushBot::VERSION
9
+ spec.authors = ['Brian Norton']
10
+ spec.email = ['brian.nort@gmail.com']
11
+ spec.summary = ''
12
+ spec.description = ''
13
+ spec.homepage = 'http://github.com/push_bot'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_runtime_dependency 'typhoeus', '~> 0.6'
24
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: push_bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Norton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: typhoeus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
55
+ description: ''
56
+ email:
57
+ - brian.nort@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".ruby-gemset"
64
+ - ".ruby-version"
65
+ - CONTRIBUTING.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.md
69
+ - README.md
70
+ - Rakefile
71
+ - lib/push_bot.rb
72
+ - lib/push_bot/api.rb
73
+ - lib/push_bot/config.rb
74
+ - lib/push_bot/device.rb
75
+ - lib/push_bot/location.rb
76
+ - lib/push_bot/platform.rb
77
+ - lib/push_bot/push.rb
78
+ - lib/push_bot/request.rb
79
+ - lib/push_bot/response.rb
80
+ - lib/push_bot/tag.rb
81
+ - lib/push_bot/version.rb
82
+ - push_bot.gemspec
83
+ homepage: http://github.com/push_bot
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: ''
107
+ test_files: []