moromi-apns 0.1.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: c604eaaa749cc57e9e53c0e5f422d3574dd16f14
4
+ data.tar.gz: 1394479e5bb9628eaa2dc9524230d6817681a6ef
5
+ SHA512:
6
+ metadata.gz: 9bca4c56d90fde5dbaf4594a27e6a3ec0d7b07a3a8752e32bff1e3a941db72de85a7f0f2804ed4028206ee69ac81cdc327b87af780904a3e703b61086fb5b94d
7
+ data.tar.gz: 0170273880c4204f48ba0b7b251a4d6abb710a2fbef612b60f110f13310d3ac9afe23b062af932659bb8740bd606d2e58aaa67925b351c084a7b2a31ce6d1fb5
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in moromi-apns.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 moromi
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,47 @@
1
+ # Moromi::Apns
2
+
3
+ [![Latest Version](https://img.shields.io/gem/v/moromi.svg)](http://rubygems.org/gems/moromi-apns)
4
+ [![Circle CI](https://circleci.com/gh/moromi/moromi-apns.svg?style=svg)](https://circleci.com/gh/moromi/moromi-apns)
5
+
6
+ APNS model.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'moromi-apns'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install moromi-apns
23
+
24
+ ## Usage
25
+
26
+ - initializers/moromi/apns.rb
27
+
28
+ ```ruby
29
+ Moromi::Apns.configure do |config|
30
+ config.identifiers = {
31
+ debug: 'com.example.moromi.apns.debug',
32
+ in_house: 'com.example.moromi.apns.in_house',
33
+ production: 'com.example.moromi.apns.production',
34
+ }
35
+ end
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/moromi-apns.
47
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "moromi/apns"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,4 @@
1
+ machine:
2
+ ruby:
3
+ version:
4
+ 2.3.1
@@ -0,0 +1,12 @@
1
+ require 'active_support/configurable'
2
+
3
+ module Moromi
4
+ module Apns
5
+ class Config
6
+ include ActiveSupport::Configurable
7
+
8
+ config_accessor :identifiers
9
+ config_accessor :environment_builder_class
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Moromi::Apns::Environment
2
+ class Base
3
+ def identifier
4
+ @identifier ||= Moromi::Apns.config.identifiers[key]
5
+ end
6
+
7
+ def key
8
+ raise NotImplementedError
9
+ end
10
+
11
+ def sandbox?
12
+ true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Moromi::Apns::Environment
2
+ class Builder
3
+ class << self
4
+ def all
5
+ raise NotImplementedError
6
+ end
7
+
8
+ def build(identifier)
9
+ all.each do |environment|
10
+ return environment if identifier == environment.identifier
11
+ end
12
+
13
+ raise InvalidEnvironment
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Moromi::Apns::Environment
2
+ class Debug < Base
3
+ def key
4
+ :debug
5
+ end
6
+
7
+ def sandbox?
8
+ true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Moromi::Apns::Environment
2
+ class DefaultBuilder < Builder
3
+ def self.all
4
+ [
5
+ Moromi::Apns::Environment::Production.new,
6
+ Moromi::Apns::Environment::InHouse.new,
7
+ Moromi::Apns::Environment::Debug.new
8
+ ]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Moromi::Apns::Environment
2
+ class InHouse < Base
3
+ def key
4
+ :in_house
5
+ end
6
+
7
+ def sandbox?
8
+ true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Moromi::Apns::Environment
2
+ class InvalidEnvironment < StandardError
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module Moromi::Apns::Environment
2
+ class Production < Base
3
+ def key
4
+ :production
5
+ end
6
+
7
+ def sandbox?
8
+ true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'moromi/apns/environment/base'
2
+ require 'moromi/apns/environment/builder'
3
+ require 'moromi/apns/environment/debug'
4
+ require 'moromi/apns/environment/default_builder'
5
+ require 'moromi/apns/environment/in_house'
6
+ require 'moromi/apns/environment/invalid_environment'
7
+ require 'moromi/apns/environment/production'
8
+
9
+ module Moromi::Apns
10
+ module Environment
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Moromi::Apns::Message
2
+ class Announce < Base
3
+ def self.make(message:, url: nil, badge: 1)
4
+ custom_data = {
5
+ params: {
6
+ url: url
7
+ }
8
+ }
9
+ parameter = Moromi::Apns::Parameter.new(alert: message, badge: badge, custom_data: custom_data)
10
+ new(parameter: parameter)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ require 'forwardable'
2
+
3
+ module Moromi::Apns::Message
4
+ class Base
5
+ extend Forwardable
6
+
7
+ attr_reader :parameter
8
+
9
+ def_delegators :@parameter, :alert, :badge, :sound, :content_available, :priority
10
+
11
+ # @param [Moromi::Apns::Parameter] parameter
12
+ def initialize(parameter:)
13
+ @parameter = parameter
14
+ end
15
+
16
+ def type
17
+ self.class.name
18
+ end
19
+
20
+ def custom_data
21
+ {type: type}.merge(@custom_data)
22
+ end
23
+
24
+ def serialize
25
+ {
26
+ type: type,
27
+ parameter: @parameter.serialize
28
+ }
29
+ end
30
+
31
+ # @param [Hash] params
32
+ def self.unserialize(params)
33
+ parameter = ::Moromi::Apns::Parameter.unserialize(params[:parameter])
34
+ new(parameter: parameter)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ module Moromi::Apns::Message
2
+ class Builder
3
+ # @param [Hash] hash
4
+ # @return Moromi::Apns::Message::Base
5
+ def self.build(hash)
6
+ params = hash.with_indifferent_access
7
+
8
+ type = params[:type]
9
+ return nil unless type.present?
10
+
11
+ klass = type.safe_constantize
12
+ klass.unserialize(params)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require 'moromi/apns/message/base'
2
+ require 'moromi/apns/message/announce'
3
+ require 'moromi/apns/message/builder'
4
+
5
+ module Moromi::Apns
6
+ module Message
7
+ end
8
+ end
@@ -0,0 +1,55 @@
1
+ require 'json'
2
+ require 'active_support/core_ext/hash'
3
+
4
+ module Moromi
5
+ module Apns
6
+ class Parameter
7
+ attr_reader :alert
8
+ attr_reader :badge
9
+ attr_reader :sound
10
+ attr_reader :content_available
11
+ attr_reader :priority
12
+ attr_reader :custom_data
13
+
14
+ def initialize(alert:, badge:, sound: 'default', content_available: 1, priority: 10, custom_data: {})
15
+ @alert = alert
16
+ @badge = badge
17
+ @sound = sound
18
+ @content_available = content_available
19
+ @priority = priority
20
+ @custom_data = custom_data
21
+ end
22
+
23
+ def self.make_silent_push_parameter(priority: 10, custom_data: {})
24
+ new(alert: '', badge: nil, sound: nil, content_available: 1, priority: priority, custom_data: custom_data)
25
+ end
26
+
27
+ def ==(other)
28
+ serialize == other.serialize
29
+ end
30
+
31
+ def serialize
32
+ {
33
+ alert: @alert,
34
+ badge: @badge,
35
+ sound: @sound,
36
+ content_available: @content_available,
37
+ priority: @priority,
38
+ custom_data: @custom_data
39
+ }.to_json
40
+ end
41
+
42
+ def self.unserialize(json)
43
+ hash = JSON.parse(json).with_indifferent_access
44
+ new(
45
+ alert: hash[:alert],
46
+ badge: hash[:badge],
47
+ sound: hash[:sound],
48
+ content_available: hash[:content_available],
49
+ priority: hash[:priority],
50
+ custom_data: hash[:custom_data]
51
+ )
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ module Moromi
2
+ module Apns
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ require 'moromi/apns/config'
2
+ require 'moromi/apns/environment'
3
+ require 'moromi/apns/version'
4
+ require 'moromi/apns/parameter'
5
+ require 'moromi/apns/message'
6
+
7
+ module Moromi
8
+ module Apns
9
+ def self.configure(&block)
10
+ yield @config ||= Config.new
11
+ end
12
+
13
+ def self.config
14
+ @config
15
+ end
16
+
17
+ def self.environment(bundle_identifier)
18
+ config.environment_builder_class.build(bundle_identifier)
19
+ end
20
+
21
+ configure do |config|
22
+ config.environment_builder_class = ::Moromi::Apns::Environment::DefaultBuilder
23
+ end
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ require "#{File.dirname(__FILE__)}/moromi/apns"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'moromi/apns/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "moromi-apns"
8
+ spec.version = Moromi::Apns::VERSION
9
+ spec.authors = ["Takahiro Ooishi"]
10
+ spec.email = ["taka0125@gmail.com"]
11
+
12
+ spec.summary = %q{APNS model}
13
+ spec.description = %q{APNS model}
14
+ spec.homepage = "https://github.com/moromi/moromi-apns"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 2.2'
22
+
23
+ spec.add_dependency 'activesupport', ['>= 4.2']
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moromi-apns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takahiro Ooishi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: APNS model
70
+ email:
71
+ - taka0125@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - circle.yml
85
+ - lib/moromi-apns.rb
86
+ - lib/moromi/apns.rb
87
+ - lib/moromi/apns/config.rb
88
+ - lib/moromi/apns/environment.rb
89
+ - lib/moromi/apns/environment/base.rb
90
+ - lib/moromi/apns/environment/builder.rb
91
+ - lib/moromi/apns/environment/debug.rb
92
+ - lib/moromi/apns/environment/default_builder.rb
93
+ - lib/moromi/apns/environment/in_house.rb
94
+ - lib/moromi/apns/environment/invalid_environment.rb
95
+ - lib/moromi/apns/environment/production.rb
96
+ - lib/moromi/apns/message.rb
97
+ - lib/moromi/apns/message/announce.rb
98
+ - lib/moromi/apns/message/base.rb
99
+ - lib/moromi/apns/message/builder.rb
100
+ - lib/moromi/apns/parameter.rb
101
+ - lib/moromi/apns/version.rb
102
+ - moromi-apns.gemspec
103
+ homepage: https://github.com/moromi/moromi-apns
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '2.2'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: APNS model
126
+ test_files: []