boxcar_publisher 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/LICENSE +22 -0
- data/README.md +25 -0
- data/boxcar_publisher.gemspec +15 -0
- data/lib/boxcar_publisher.rb +55 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: faa4a93da71f1e0fa2f7f8c6c2e0dd3d8cde0424
|
4
|
+
data.tar.gz: a1d2deff6ade74808d9ef26a1495e82b0b6acb3c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46e97b377eec7f1fe9106d65bad9042ea90165a74bfc83b3cfb2ef81168f7fc72a6055d36cc581a59d28e6c2a1772fe1875a19885685b72a3fa2052d7765bea7
|
7
|
+
data.tar.gz: 0e0b236480b4d50dfd7513402a6f6a68638adf17d8f53970f2c79c58aaeb45cba6d415d9e672189a1f381541dd4e484128d488b20cadf3d574ec4c8748fe4ec6
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Amitree
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
boxcar\_publisher
|
2
|
+
=================
|
3
|
+
|
4
|
+
Installation
|
5
|
+
-----
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install boxcar_publisher
|
9
|
+
```
|
10
|
+
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
|
14
|
+
```
|
15
|
+
BoxcarPublisher.setup do |config|
|
16
|
+
config.access_key 'THIS_IS_MY_ACCESS_KEY'
|
17
|
+
config.secret_key 'THIS_IS_MY_SECRET_KEY'
|
18
|
+
end
|
19
|
+
|
20
|
+
push = BoxcarPublisher::Push.new aps: { alert: 'Hello world' }, tags: ['@all'], id: '12345'
|
21
|
+
push.id
|
22
|
+
# => 12345
|
23
|
+
push.state
|
24
|
+
# => {:state=>"delivered", :created_at=>2015-05-27 22:28:10 -0700, :last_delivered_at=>2015-05-27 22:28:10 -0700, :sent=>1, :errors=>0, :opened=>0}
|
25
|
+
```
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'boxcar_publisher'
|
3
|
+
spec.version = '1.0.0'
|
4
|
+
spec.date = Date.today.to_s
|
5
|
+
spec.summary = "Publisher API for boxcar.io"
|
6
|
+
spec.description = "Send push notifications with Boxcar.io"
|
7
|
+
spec.authors = ["Tony Novak"]
|
8
|
+
spec.email = 'tony@amitree.com'
|
9
|
+
spec.files = Dir["{lib,spec,vendor}/**/*", "[A-Z]*"] - ["Gemfile.lock"]
|
10
|
+
spec.homepage = 'http://rubygems.org/gems/boxcar_publisher'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.add_runtime_dependency 'faraday', '>= 0.8'
|
14
|
+
spec.add_runtime_dependency 'faraday_middleware', '>= 0'
|
15
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
class BoxcarPublisher
|
6
|
+
class Config
|
7
|
+
%w(access_key secret_key).each do |var|
|
8
|
+
eval <<-BLOCK
|
9
|
+
def #{var} val
|
10
|
+
BoxcarPublisher.#{var} = val
|
11
|
+
end
|
12
|
+
BLOCK
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_accessor :access_key, :secret_key
|
18
|
+
|
19
|
+
def setup &block
|
20
|
+
Config.new.instance_eval &block
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def _conn
|
25
|
+
@conn ||= Faraday.new(url: 'https://boxcar-api.io/api') do |conn|
|
26
|
+
conn.basic_auth access_key, secret_key
|
27
|
+
conn.request :json
|
28
|
+
conn.response :json
|
29
|
+
conn.use Faraday::Response::RaiseError
|
30
|
+
conn.adapter Faraday.default_adapter
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Push
|
36
|
+
attr_accessor :id, :url
|
37
|
+
|
38
|
+
def initialize options
|
39
|
+
result = BoxcarPublisher._conn.post 'push', options
|
40
|
+
@id = result.body['ok']
|
41
|
+
@url = result.headers['Location']
|
42
|
+
end
|
43
|
+
|
44
|
+
def state
|
45
|
+
result = BoxcarPublisher._conn.get "push/#{id}"
|
46
|
+
json = result.body
|
47
|
+
{}.tap do |res|
|
48
|
+
json.each do |key, value|
|
49
|
+
value = (DateTime.parse(value).to_time rescue value) if key =~ /_at\z/
|
50
|
+
res[key.to_sym] = value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boxcar_publisher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tony Novak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Send push notifications with Boxcar.io
|
42
|
+
email: tony@amitree.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- boxcar_publisher.gemspec
|
50
|
+
- lib/boxcar_publisher.rb
|
51
|
+
homepage: http://rubygems.org/gems/boxcar_publisher
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.4.6
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Publisher API for boxcar.io
|
75
|
+
test_files: []
|
76
|
+
has_rdoc:
|