Module: Wor::Push::Notifications::Aws

Defined in:
lib/wor/push/notifications/aws.rb,
lib/wor/push/notifications/aws/version.rb,
lib/wor/push/notifications/aws/exceptions.rb,
lib/wor/push/notifications/aws/push_notifications.rb,
lib/wor/push/notifications/aws/ios_push_json_builder.rb,
lib/wor/push/notifications/aws/android_push_json_builder.rb,
lib/generators/wor/push/notifications/aws/install_generator.rb,
lib/wor/push/notifications/aws/validators/push_notifications_validator.rb

Defined Under Namespace

Modules: Exceptions, Generators Classes: AndroidPushJsonBuilder, IosPushJsonBuilder, PushNotifications, PushNotificationsValidator

Constant Summary collapse

DEVICE_TYPES =
%i[ios android].freeze
VERSION =
'0.1.2'.freeze

Class Method Summary collapse

Class Method Details

.add_token(user, device_token, device_type) ⇒ Object



88
89
90
# File 'lib/wor/push/notifications/aws.rb', line 88

def self.add_token(user, device_token, device_type)
  PushNotifications.add_token(user, device_token, device_type.to_sym)
end

.aws_android_arnObject



76
77
78
# File 'lib/wor/push/notifications/aws.rb', line 76

def self.aws_android_arn
  @config[:aws_android_arn]
end

.aws_android_arn=(aws_android_arn) ⇒ Object

Raises:

  • (ArgumentError)


50
51
52
53
# File 'lib/wor/push/notifications/aws.rb', line 50

def self.aws_android_arn=(aws_android_arn)
  raise ArgumentError, 'Argument must be a string' unless aws_android_arn.is_a?(String)
  @config[:aws_android_arn] = aws_android_arn
end

.aws_ios_arnObject



68
69
70
# File 'lib/wor/push/notifications/aws.rb', line 68

def self.aws_ios_arn
  @config[:aws_ios_arn]
end

.aws_ios_arn=(aws_ios_arn) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
# File 'lib/wor/push/notifications/aws.rb', line 40

def self.aws_ios_arn=(aws_ios_arn)
  raise ArgumentError, 'Argument must be a string' unless aws_ios_arn.is_a?(String)
  @config[:aws_ios_arn] = aws_ios_arn
end

.aws_ios_sandboxObject



72
73
74
# File 'lib/wor/push/notifications/aws.rb', line 72

def self.aws_ios_sandbox
  @config[:aws_ios_sandbox]
end

.aws_ios_sandbox=(aws_ios_sandbox) ⇒ Object

Raises:

  • (ArgumentError)


45
46
47
48
# File 'lib/wor/push/notifications/aws.rb', line 45

def self.aws_ios_sandbox=(aws_ios_sandbox)
  raise ArgumentError, 'Argument must be a boolean' unless boolean?(aws_ios_sandbox)
  @config[:aws_ios_sandbox] = aws_ios_sandbox
end

.aws_regionObject



80
81
82
# File 'lib/wor/push/notifications/aws.rb', line 80

def self.aws_region
  @config[:aws_region]
end

.aws_region=(aws_region) ⇒ Object

Raises:

  • (ArgumentError)


55
56
57
58
# File 'lib/wor/push/notifications/aws.rb', line 55

def self.aws_region=(aws_region)
  raise ArgumentError, 'Argument must be a string' unless aws_region.is_a?(String)
  @config[:aws_region] = aws_region
end

.boolean?(value) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/wor/push/notifications/aws.rb', line 104

def self.boolean?(value)
  value.is_a?(TrueClass) || value.is_a?(FalseClass)
end

.configObject



84
85
86
# File 'lib/wor/push/notifications/aws.rb', line 84

def self.config
  @config
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



15
16
17
# File 'lib/wor/push/notifications/aws.rb', line 15

def self.configure
  yield self
end

.delete_token(user, device_token) ⇒ Object



92
93
94
# File 'lib/wor/push/notifications/aws.rb', line 92

def self.delete_token(user, device_token)
  PushNotifications.delete_token(user, device_token)
end

.device_typesObject



60
61
62
# File 'lib/wor/push/notifications/aws.rb', line 60

def self.device_types
  @config[:device_types]
end

.device_types=(types) ⇒ Object

Precondition: types must be an array of symbols containing valid device types.

Every type included in this array must be a valid device type
(you can ask for valid device types with the method valid_device_types).
Default is ['ios' 'android'].

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
# File 'lib/wor/push/notifications/aws.rb', line 23

def self.device_types=(types)
  raise ArgumentError, 'Argument must be an array of symbols' unless types.is_a?(Array)
  types.each do |type|
    raise ArgumentError, "Invalid type #{type}" unless DEVICE_TYPES.include?(type)
  end
  @config[:device_types] = types
end

.send_message(user, message_content) ⇒ Object



96
97
98
# File 'lib/wor/push/notifications/aws.rb', line 96

def self.send_message(user, message_content)
  PushNotifications.send_message(user, message_content)
end

.table_nameObject



64
65
66
# File 'lib/wor/push/notifications/aws.rb', line 64

def self.table_name
  @config[:table_name]
end

.table_name=(table_name) ⇒ Object

Precondition: table_name must be a string which points out the name of the table that

will store the device_tokens.
Default is 'users'.

Raises:

  • (ArgumentError)


34
35
36
37
38
# File 'lib/wor/push/notifications/aws.rb', line 34

def self.table_name=(table_name)
  raise ArgumentError, 'Argument must be a string' unless table_name.is_a?(String)
  raise ArgumentError, 'Argument must not be an empty string' if table_name.empty?
  @config[:table_name] = table_name.pluralize.to_sym
end

.valid_device_typesObject



100
101
102
# File 'lib/wor/push/notifications/aws.rb', line 100

def self.valid_device_types
  DEVICE_TYPES
end