Class: Moromi::Aws::Sns::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/moromi/aws/sns/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, secret_access_key, region) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/moromi/aws/sns/client.rb', line 7

def initialize(access_key_id, secret_access_key, region)
  @access_key_id = access_key_id
  @secret_access_key = secret_access_key
  @region = region
end

Instance Method Details

#get_endpoint_attributes(endpoint_arn) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/moromi/aws/sns/client.rb', line 80

def get_endpoint_attributes(endpoint_arn)
  params = {
    endpoint_arn: endpoint_arn
  }
  results = client.get_endpoint_attributes(params)
  results.attributes
end

#inactive(arn) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/moromi/aws/sns/client.rb', line 50

def inactive(arn)
  params = {
    endpoint_arn: arn,
    attributes: {'Enabled' => 'false'}
  }
  client.set_endpoint_attributes(params)
end

#publish(arn, parameter) ⇒ Object

Parameters:



60
61
62
63
64
65
66
67
# File 'lib/moromi/aws/sns/client.rb', line 60

def publish(arn, parameter)
  options = {
    target_arn: arn,
    message: parameter.to_json,
    message_structure: 'json'
  }
  call_publish(options)
end

#publish_to_topic(topic_arn, parameter) ⇒ Object

Parameters:



71
72
73
74
75
76
77
78
# File 'lib/moromi/aws/sns/client.rb', line 71

def publish_to_topic(topic_arn, parameter)
  options = {
    topic_arn: topic_arn,
    message: parameter.to_json,
    message_structure: 'json'
  }
  call_publish(options)
end

#register(platform_application_arn, token, force_enable: true) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/moromi/aws/sns/client.rb', line 13

def register(platform_application_arn, token, force_enable: true)
  params = {
    platform_application_arn: platform_application_arn,
    token: token
  }

  response = client.create_platform_endpoint(params)
  arn = response.endpoint_arn

  if force_enable
    params = {
      endpoint_arn: arn,
      attributes: {'Enabled' => 'true'}
    }
    client.set_endpoint_attributes(params)
  end

  arn
end

#subscribe(topic_arn, endpoint_arn) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/moromi/aws/sns/client.rb', line 33

def subscribe(topic_arn, endpoint_arn)
  params = {
    topic_arn: topic_arn,
    protocol: 'application',
    endpoint: endpoint_arn
  }
  response = client.subscribe(params)
  response.subscription_arn
end

#unsubscribe(subscription_arn) ⇒ Object



43
44
45
46
47
48
# File 'lib/moromi/aws/sns/client.rb', line 43

def unsubscribe(subscription_arn)
  params = {
    subscription_arn: subscription_arn
  }
  client.unsubscribe(params)
end