j7w1 0.0.11 → 0.0.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1caea42fda924cb30963c6eeb49ec6cd87c8d255
4
- data.tar.gz: d031a3223717a6d62899b620b503b3503b482b57
3
+ metadata.gz: 6ad5f2775ef8894cdc1c82243f9a18a44debbcf1
4
+ data.tar.gz: 042ffa10065118058d0a21192365ea10b7278a6f
5
5
  SHA512:
6
- metadata.gz: 969442af76e0375ebdd09693e5c9aed4d067f78f9fd85d8a659a1c9ea19ea9f740545c4ae4fe4a82277649f1f34ef8fbf2f66ce285eb3dfc14b41259ce14e2e7
7
- data.tar.gz: ecdfa8cd5bca3694fab365e9fe4c520f0fd42446a426455187d5cd8972a7995e16d82085c3c9e01038d041b7638394c1acb124e3f230bc74577bb8ab48add3c2
6
+ metadata.gz: dc43b5e73d7e96e9de1e75baaaed54b22075aec19281bcfc8fe0c572c15fe858325fe4292766fb93cdc840a38dbaea54910e2a10514c82d8a37421a8e7bddfea
7
+ data.tar.gz: 866d57e0b6414dd8a42056f5721b6e5f4cc805f049db38e5d66d1a114db024cbc5857294845423ab66feba6723ad4c5174ac4bed6a65a26f124cceb7d78e9483
data/j7w1.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["condor1226@gmail.com"]
11
11
  spec.description = %q{Mobile apps push client}
12
12
  spec.summary = %q{Mobile apps push client}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/condor/j7w1"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files Gemfile LICENSE.txt README.md j7w1.gemspec lib spec`.split($/)
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "activerecord", ">= 4.0"
27
+ spec.add_development_dependency 'simplecov'
26
28
  end
@@ -4,6 +4,9 @@ require 'rails/generators/migration'
4
4
  module J7W1
5
5
  class MigrationGenerator < Rails::Generators::Base
6
6
  include Rails::Generators::Migration
7
+ class_option :from_11, type: :boolean, default: :false,
8
+ desc: 'Generates migration script from v0.0.11 or earlier.'
9
+
7
10
 
8
11
  def self.orm
9
12
  Rails::Generators.options[:rails][:orm]
@@ -30,7 +33,11 @@ module J7W1
30
33
  desc "This generator provides the tables which the J7W1 uses."
31
34
  def create_migration_file
32
35
  if self.class.orm_has_migration?
33
- migration_template 'migration.rb', 'db/migrate/j7_w1_application_devices'
36
+ if options['from_11']
37
+ migration_template 'migration_from_11e.rb', 'db/migrate/add_j7_w1_application_devices_disabled'
38
+ else
39
+ migration_template 'migration.rb', 'db/migrate/create_j7_w1_application_devices'
40
+ end
34
41
  end
35
42
  end
36
43
 
@@ -1,4 +1,4 @@
1
- class J7W1ApplicationDevices < ActiveRecord::Migration
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :j7w1_application_devices do |t|
4
4
  t.string :owner_type, null: false
@@ -6,6 +6,7 @@ class J7W1ApplicationDevices < ActiveRecord::Migration
6
6
  t.string :device_identifier, null: false
7
7
  t.string :platform, null: false
8
8
  t.string :device_endpoint_arn, null: true
9
+ t.boolean :disabled, null: false, default: false
9
10
 
10
11
  t.index [:owner_type, :owner_id]
11
12
  t.index [:device_identifier, :platform], unique: true
@@ -0,0 +1,7 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ change_table :j7w1_application_devices do |t|
4
+ t.boolean :disabled, null: false, default: false
5
+ end
6
+ end
7
+ end
@@ -1,8 +1,10 @@
1
- class J7W1ApplicationDevice < ActiveRecord::Base
1
+ class J8W1ApplicationDevice < ActiveRecord::Base
2
2
  self.table_name = 'j7w1_application_devices'
3
3
 
4
4
  belongs_to :owner, polymorphic: true
5
5
 
6
+ scope :enabled, -> {where(disabled: false)}
7
+
6
8
  <%- if options['async_engine'] -%>
7
9
  after_create :create_device_endpoint_async
8
10
  after_destroy :destroy_device_endpoint_async
@@ -16,6 +18,14 @@ class J7W1ApplicationDevice < ActiveRecord::Base
16
18
 
17
19
  def push!(options = {})
18
20
  J7W1::PushClient.push device_endpoint_arn, platform, options
21
+ rescue AWS::SNS::Errors::EndpoiintDisabled
22
+ logger.warn{"push for Application Device ##{id} is currently disabled."}
23
+ begin
24
+ update_attributes!(disabled: true)
25
+ rescue
26
+ logger.warn { "Disabling failure: application device ##{id}" }
27
+ # grasp all the exception raised.
28
+ end
19
29
  end
20
30
 
21
31
  def create_device_endpoint
data/lib/j7w1.rb CHANGED
@@ -5,6 +5,8 @@ module J7W1
5
5
  autoload :Util, 'j7w1/util'
6
6
  autoload :Version, 'j7w1/version'
7
7
  autoload :ActiveRecordExt, 'j7w1/active_record_ext'
8
+ autoload :MockPushClient, 'j7w1/mock_push_client'
9
+ autoload :SNSPushClient, 'j7w1/sns_push_client'
8
10
 
9
11
  ActiveRecord::Base.__send__(:include, ActiveRecordExt) if defined? ActiveRecord::Base
10
12
 
@@ -12,6 +14,8 @@ module J7W1
12
14
  attr_reader :current_strategy
13
15
  private :current_strategy
14
16
 
17
+ include Util
18
+
15
19
  def configure(configuration)
16
20
  raise ArgumentError,
17
21
  "J7W1 configuration values should be an instance of Hash or String, but actually it is a kind of #{configuration.class.name}" unless
@@ -19,11 +23,11 @@ module J7W1
19
23
 
20
24
  configuration = configuration_values_of(configuration)
21
25
  if configuration[:mock]
22
- autoload :PushClient, 'j7w1/mock'
26
+ replace_concrete_push_client MockPushClient
23
27
  return
24
28
  end
25
29
 
26
- autoload :PushClient, 'j7w1/push_client'
30
+ replace_concrete_push_client SNSPushClient
27
31
  @configuration = Configuration.new configuration
28
32
  end
29
33
 
@@ -51,12 +55,9 @@ module J7W1
51
55
  configuration
52
56
  end
53
57
 
54
- def symbolize_keys_recursive(hash)
55
- hash.inject({}) do |h, kv|
56
- (key, value) = kv
57
- h[key.to_sym] = regularize_for_symbolization(value)
58
- h
59
- end
58
+ def replace_concrete_push_client(newer)
59
+ remove_const :PushClient if defined? PushClient
60
+ const_set :PushClient, newer
60
61
  end
61
62
 
62
63
  if const_defined?(:ActiveSupport) && Hash.instance_methods.include?(:symbolize_keys) &&
@@ -88,6 +89,7 @@ module J7W1
88
89
  value
89
90
  end
90
91
  end
92
+
91
93
  end
92
94
  end
93
95
  end
@@ -29,7 +29,7 @@ module J7W1
29
29
  end
30
30
 
31
31
  def push!(options = {})
32
- application_devices.each do |device|
32
+ application_devices.enabled.each do |device|
33
33
  device.push! options
34
34
  end
35
35
  end
@@ -1,5 +1,7 @@
1
1
  module J7W1
2
2
  class Configuration
3
+ include J7W1::Util
4
+
3
5
  module IOSEndpoint
4
6
  def sandbox?
5
7
  @sandbox
@@ -22,12 +24,12 @@ module J7W1
22
24
 
23
25
  module Account
24
26
  [:access_key_id, :secret_access_key, :region].each do |attr|
25
- define_method(attr){self[attr]}
27
+ module_eval "def #{attr};self[:#{attr}];end"
26
28
  end
27
29
  end
28
30
 
29
31
  def initialize(configuration_values)
30
- @values = configuration_values
32
+ @values = symbolize_keys_recursive(configuration_values)
31
33
  if ios_endpoint
32
34
  ios_endpoint.extend(IOSEndpoint)
33
35
  ios_endpoint.confirm_sandbox
@@ -41,11 +43,13 @@ module J7W1
41
43
  end
42
44
 
43
45
  def ios_endpoint
46
+ return nil unless @values[:app_endpoint]
44
47
  @values[:app_endpoint][:ios]
45
48
  end
46
49
 
47
50
  def android_endpoint
48
51
  #TODO configの対応
52
+ return nil unless @values[:app_endpoint]
49
53
  @values[:app_endpoint][:android]
50
54
  end
51
55
  end
@@ -1,5 +1,5 @@
1
1
  module J7W1
2
- module PushClient
2
+ module MockPushClient
3
3
 
4
4
  class << self
5
5
  def push_histories
@@ -1,7 +1,7 @@
1
1
  module J7W1
2
- module PushClient
2
+ module SNSPushClient
3
3
  def create_sns_client(configuration = J7W1.configuration)
4
- AWS::SNS.new J7W1.configuration.account
4
+ AWS::SNS.new configuration.account
5
5
  end
6
6
 
7
7
  def create_ios_application(name, certs, private_key, options)
@@ -24,6 +24,13 @@ module J7W1
24
24
  application_endpoint[:platform_application_arn]
25
25
  end
26
26
 
27
+ def destroy_application_endpoint(arn, options)
28
+ configuration = options[:sns_configuration] || J7W1.configuration
29
+ client = options[:sns_client] || create_sns_client(configuration)
30
+
31
+ client.client.delete_platform_application(platform_application_arn: arn)
32
+ end
33
+
27
34
  def create_device_endpoint(device_identifier, platform, options = {})
28
35
  custom_user_data = options[:custom_user_data]
29
36
  sns_configuration = options[:sns_configuration]
data/lib/j7w1/util.rb CHANGED
@@ -4,13 +4,23 @@ module J7W1
4
4
  platform = platform.to_s.downcase.to_sym unless platform.is_a? Symbol
5
5
 
6
6
  case platform
7
- when :ios, :'iphone os', :'ipad os'
8
- :ios
9
- else
10
- platform
7
+ when :ios, :'iphone os', :'ipad os'
8
+ :ios
9
+ else
10
+ # TODO Android
11
+ platform
11
12
  end
12
13
  end
13
14
 
14
- instance_methods(false).each{|m|module_function m}
15
+ def symbolize_keys_recursive(hash)
16
+ hash.inject({}) do |h, kv|
17
+ (key, value) = kv
18
+ h[key.to_sym] =
19
+ value.is_a?(Hash) ? symbolize_keys_recursive(value) : value
20
+ h
21
+ end
22
+ end
23
+
24
+ extend self
15
25
  end
16
26
  end
data/lib/j7w1/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module J7W1
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -0,0 +1,100 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../spec_helper'))
2
+
3
+ describe J7W1::Configuration do
4
+ describe :ios_endpoint do
5
+
6
+
7
+ shared_examples_for 'sandbox_confirmation' do
8
+ subject {
9
+ J7W1::Configuration.new(
10
+ app_endpoint: {
11
+ ios: {
12
+ arn: arn,
13
+ },
14
+ }
15
+ )
16
+ }
17
+
18
+ specify { expect(subject.ios_endpoint.arn).to eql(arn) }
19
+ specify { expect(!!subject.ios_endpoint.sandbox?).to eql(sandbox) }
20
+ end
21
+
22
+ describe 'sandbox arn' do
23
+ let(:sandbox){true}
24
+ let(:arn){'arn:aws:sns:ap-northeast-1:1234567:app/APNS_SANDBOX/test'}
25
+ it_should_behave_like 'sandbox_confirmation'
26
+ end
27
+
28
+ describe 'production arn' do
29
+ let(:sandbox){false}
30
+ let(:arn){'arn:aws:sns:ap-northeast-1:1234567:app/APNS/test'}
31
+ it_should_behave_like 'sandbox_confirmation'
32
+ end
33
+ end
34
+
35
+ describe :android_endpoint do
36
+ subject {
37
+ J7W1::Configuration.new(
38
+ app_endpoint: {
39
+ android: {
40
+ arn: arn,
41
+ },
42
+ }
43
+ )
44
+ }
45
+ let(:arn){'arn:aws:sns:ap-northeast-1:1234567:app/ANDROID/test'}
46
+ specify 'arn should return the specified configuration value' do
47
+ expect(subject.android_endpoint.arn).to eql(arn)
48
+ end
49
+ end
50
+
51
+ describe :account do
52
+
53
+ shared_examples_for 'configuration extraction' do
54
+ let(:region){'ap-northeast-1'}
55
+ let(:access_key_id){'access_key_id_1'}
56
+ let(:secret_access_key){'secret_access_key_1'}
57
+
58
+ describe 'should return a hash with values under :account given on initialization' do
59
+ specify{expect(subject.account).to be_kind_of Hash}
60
+ specify{expect(subject.account[:region]).to eql(region)}
61
+ specify{expect(subject.account[:access_key_id]).to eql(access_key_id)}
62
+ specify{expect(subject.account[:secret_access_key]).to eql(secret_access_key)}
63
+ end
64
+
65
+ describe 'its accessors should return the values which are correspondent to the key' do
66
+ specify{expect(subject.account.region).to eql(region)}
67
+ specify{expect(subject.account.access_key_id).to eql(access_key_id)}
68
+ specify{expect(subject.account.secret_access_key).to eql(secret_access_key)}
69
+ end
70
+ end
71
+
72
+ describe 'when keys are kind of Symbol' do
73
+ subject {
74
+ J7W1::Configuration.new(
75
+ account: {
76
+ region: region,
77
+ access_key_id: access_key_id,
78
+ secret_access_key: secret_access_key,
79
+ }
80
+ )
81
+ }
82
+ it_should_behave_like 'configuration extraction'
83
+ end
84
+
85
+ describe 'when keys are kind of String' do
86
+ subject {
87
+ J7W1::Configuration.new(
88
+ 'account' => {
89
+ 'region' => region,
90
+ 'access_key_id' => access_key_id,
91
+ 'secret_access_key'=> secret_access_key,
92
+ }
93
+ )
94
+ }
95
+ it_should_behave_like 'configuration extraction'
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../spec_helper'))
2
+
3
+ describe J7W1::Util do
4
+ subject{
5
+ Object.new.tap{|o|o.extend J7W1::Util }
6
+ }
7
+
8
+ describe :symbolize_keys_recursive do
9
+
10
+ context "should return the hash whose keys are converted to symbol recursively" do
11
+ specify do
12
+ expect(subject.symbolize_keys_recursive({'aaa' => 1, :bbb => 2, '3' => 4})).to eql({aaa: 1, bbb: 2, :'3' => 4})
13
+ end
14
+
15
+ specify do
16
+ expect(subject.symbolize_keys_recursive({'aaa' => 1, :bbb => 2, '3' => {'aaa' => 5, :'bbb' => 10}})).to eql({aaa: 1, bbb: 2, :'3' => {aaa: 5, bbb: 10}})
17
+ end
18
+ end
19
+ end
20
+
21
+ describe :normalize_platform do
22
+ context 'can normalize ios-like platform symbol to :ios' do
23
+
24
+ shared_examples_for 'into ios' do
25
+ specify{expect(subject.normalize_platform(platform_string)).to eql(:ios)}
26
+ end
27
+
28
+ context '"iPad OS" is given' do
29
+ let(:platform_string){'iPad OS'}
30
+ it_behaves_like 'into ios'
31
+ end
32
+
33
+ context '"iPhone OS" is given' do
34
+ let(:platform_string){'iPhone OS'}
35
+ it_behaves_like 'into ios'
36
+ end
37
+
38
+ context '"iOS" is given' do
39
+ let(:platform_string){'iOS'}
40
+ it_behaves_like 'into ios'
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ require 'rspec'
2
+ require 'bundler/setup'
3
+
4
+ unless ENV['SKIP_COV']
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+ end
8
+
9
+ require 'j7w1'
10
+
11
+ RSpec.configure do |config|
12
+ # see https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/configuration.rb for more infomation
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: j7w1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - condor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-15 00:00:00.000000000 Z
11
+ date: 2013-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: Mobile apps push client
70
98
  email:
71
99
  - condor1226@gmail.com
@@ -79,6 +107,7 @@ files:
79
107
  - j7w1.gemspec
80
108
  - lib/generators/j7_w1/migration/migration_generator.rb
81
109
  - lib/generators/j7_w1/migration/templates/active_record/migration.rb
110
+ - lib/generators/j7_w1/migration/templates/active_record/migration_from_11e.rb
82
111
  - lib/generators/j7_w1/model/model_generator.rb
83
112
  - lib/generators/j7_w1/model/templates/j7_w1_application_device.rb.erb
84
113
  - lib/generators/j7_w1/model/templates/j7_w1_create_endpoint_worker.rb
@@ -86,13 +115,16 @@ files:
86
115
  - lib/j7w1.rb
87
116
  - lib/j7w1/active_record_ext.rb
88
117
  - lib/j7w1/configuration.rb
89
- - lib/j7w1/mock.rb
90
- - lib/j7w1/push_client.rb
118
+ - lib/j7w1/mock_push_client.rb
119
+ - lib/j7w1/sns_push_client.rb
91
120
  - lib/j7w1/util.rb
92
121
  - lib/j7w1/version.rb
93
122
  - spec/.gitignore
94
123
  - spec/config.example.yml
95
- homepage: ''
124
+ - spec/lib/j7w1/configuration_spec.rb
125
+ - spec/lib/j7w1/util_spec.rb
126
+ - spec/spec_helper.rb
127
+ homepage: https://github.com/condor/j7w1
96
128
  licenses:
97
129
  - MIT
98
130
  metadata: {}
@@ -112,10 +144,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
144
  version: '0'
113
145
  requirements: []
114
146
  rubyforge_project:
115
- rubygems_version: 2.0.3
147
+ rubygems_version: 2.0.14
116
148
  signing_key:
117
149
  specification_version: 4
118
150
  summary: Mobile apps push client
119
151
  test_files:
120
152
  - spec/.gitignore
121
153
  - spec/config.example.yml
154
+ - spec/lib/j7w1/configuration_spec.rb
155
+ - spec/lib/j7w1/util_spec.rb
156
+ - spec/spec_helper.rb