urbanairship 5.8.0 → 5.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e4a3dfc0a925ebcaf22800eabbc1fec1c8c59f5fd52e26f24ca87ff7eec2d5c
4
- data.tar.gz: 593f328489aaffcfad92e1da6c9a86351aabee461ab408bf94d66a374bef8625
3
+ metadata.gz: 6dbcc6fe1884df9f5beb53e6bc29406d2d4cb51aabfab22cc45f67b714104064
4
+ data.tar.gz: d147e04cbeadbb51e13325ff9cd5b7af458aa22531b8aab2e4ef0c19544ae15c
5
5
  SHA512:
6
- metadata.gz: 5441fa97e0611f195f39d06022e30fa7a32d55a6d8a6052c0d5f366d97a687f6e789e9de9c4ceebe0f6cc192414cf706a24a0b8572bf4d5b914e147acec94c39
7
- data.tar.gz: ff5234432140b9cabac03ed2df6ef29d5398f6e8ea886d1a161fc31ee0f0c758bbc10647e736597d8524b43b9d34a1be17887af24f9a9376b1d1b75c11dd196c
6
+ metadata.gz: 7109db5053551032e3c6f933d07e39496b1f8d530349dba64a0b0b1d0b09ed5d2cbec46f89bd3adfe340cbfc0601d0ca089bcf17d302ad498959790915819096
7
+ data.tar.gz: 2e6366c2f3cbb0b35bbb68e78a1752fd32ddfeefe7316ddbcaa609b5971947d8e01c898672eee1eec617ecef222bc36928a972fefcb2b18bad0406993813536b
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ --------------------
2
+ 5.9.0
3
+ --------------------
4
+ - Adds support for bearer token auth
5
+ - Updates broken code for static lists
6
+ - Adds support for update sms channel
7
+
1
8
  --------------------
2
9
  5.8.0
3
10
  --------------------
@@ -21,6 +21,25 @@ request with an opted_in key.
21
21
  sms_channel.opted_in = '2018-02-13T11:58:59'
22
22
  sms_channel.register
23
23
 
24
+ Update SMS Channel
25
+ -------------------
26
+
27
+ To update an SMS channel you need a sender, MSISDN, and a channel ID.
28
+
29
+ .. code-block:: ruby
30
+
31
+ require 'urbanairship'
32
+ UA = Urbanairship
33
+ airship = UA::Client.new(key:'application_key', secret:'master_secret')
34
+ sms_channel = UA::Sms.new(client: airship)
35
+ sms_channel.msisdn = '15035556789'
36
+ sms_channel.sender = '12345'
37
+ sms_channel.opted_in = '2020-12-14T11:58:59'
38
+ sms_channel.timezone = 'America/Denver'
39
+ sms_channel.channel_id = 'a1b2c3d4e5f6'
40
+ sms_channel.update
41
+
42
+
24
43
  Opt-Out of SMS Messages
25
44
  -----------------------
26
45
 
@@ -28,7 +28,7 @@ string keys to arbitrary JSON values.
28
28
  airship = UA::Client.new(key:'application_key', secret:'master_secret')
29
29
  static_list = UA::StaticList.new(client: airship)
30
30
  static_list.name = 'list_name'
31
- static_list.create(description: 'description', extras: { 'key' => 'value' })
31
+ static_list.create(description: 'description', extra: {'key': 'value'})
32
32
 
33
33
 
34
34
  Upload List
@@ -71,7 +71,7 @@ Updates the metadata of a static list.
71
71
  airship = UA::Client.new(key:'application_key', secret:'master_secret')
72
72
  static_list = UA::StaticList.new(client: airship)
73
73
  static_list.name = 'list_name'
74
- static_list.update(description: 'description', { 'key' => 'value' })
74
+ static_list.update(description: 'new description', 'extra': {'new_key': 'new_value' })
75
75
 
76
76
 
77
77
  Delete List
@@ -13,10 +13,12 @@ module Urbanairship
13
13
  #
14
14
  # @param [Object] key Application Key
15
15
  # @param [Object] secret Application Secret
16
+ # @param [String] token Application Auth Token (for custom events endpoint)
16
17
  # @return [Object] Client
17
- def initialize(key: required('key'), secret: required('secret'))
18
+ def initialize(key: required('key'), secret: required('secret'), token: nil)
18
19
  @key = key
19
20
  @secret = secret
21
+ @token = token
20
22
  end
21
23
 
22
24
  # Send a request to Airship's API
@@ -25,10 +27,11 @@ module Urbanairship
25
27
  # @param [Object] body Request Body
26
28
  # @param [Object] url Request URL
27
29
  # @param [Object] content_type Content-Type
28
- # @param [Object] version API Version
30
+ # @param [Object] encoding Encoding
31
+ # @param [Symbol] auth_type (:basic|:bearer)
29
32
  # @return [Object] Push Response
30
33
  def send_request(method: required('method'), url: required('url'), body: nil,
31
- content_type: nil, encoding: nil)
34
+ content_type: nil, encoding: nil, auth_type: :basic)
32
35
  req_type = case method
33
36
  when 'GET'
34
37
  :get
@@ -46,9 +49,14 @@ module Urbanairship
46
49
  headers['Accept'] = 'application/vnd.urbanairship+json; version=3'
47
50
  headers['Content-type'] = content_type unless content_type.nil?
48
51
  headers['Content-Encoding'] = encoding unless encoding.nil?
52
+
53
+ if auth_type == :bearer
54
+ raise ArgumentError.new('token must be provided as argument if auth_type=bearer') if @token.nil?
55
+ headers['X-UA-Appkey'] = @key
56
+ headers['Authorization'] = "Bearer #{@token}"
57
+ end
49
58
 
50
- debug = "Making #{method} request to #{url}.\n"+
51
- "\tHeaders:\n"
59
+ debug = "Making #{method} request to #{url}.\n"+ "\tHeaders:\n"
52
60
  debug += "\t\tcontent-type: #{content_type}\n" unless content_type.nil?
53
61
  debug += "\t\tcontent-encoding: gzip\n" unless encoding.nil?
54
62
  debug += "\t\taccept: application/vnd.urbanairship+json; version=3\n"
@@ -56,15 +64,20 @@ module Urbanairship
56
64
 
57
65
  logger.debug(debug)
58
66
 
59
- response = RestClient::Request.execute(
67
+ params = {
60
68
  method: method,
61
69
  url: url,
62
70
  headers: headers,
63
- user: @key,
64
- password: @secret,
65
71
  payload: body,
66
72
  timeout: Urbanairship.configuration.timeout
67
- )
73
+ }
74
+
75
+ if auth_type == :basic
76
+ params[:user] = @key
77
+ params[:password] = @secret
78
+ end
79
+
80
+ response = RestClient::Request.execute(params)
68
81
 
69
82
  logger.debug("Received #{response.code} response. Headers:\n\t#{response.headers}\nBody:\n\t#{response.body}")
70
83
  Response.check_code(response.code, response)
@@ -57,7 +57,7 @@ module Urbanairship
57
57
  content_type: 'application/json'
58
58
  )
59
59
 
60
- logger.info { "Successfully unintalled open channel with address: #{address}"}
60
+ logger.info { "Successfully uninstalled open channel with address: #{address}"}
61
61
  response
62
62
  end
63
63
  end
@@ -5,7 +5,14 @@ module Urbanairship
5
5
  class Sms
6
6
  include Urbanairship::Common
7
7
  include Urbanairship::Loggable
8
- attr_accessor :msisdn, :sender, :opted_in, :sender
8
+ attr_accessor :msisdn,
9
+ :sender,
10
+ :opted_in,
11
+ :sender,
12
+ :locale_country,
13
+ :locale_language,
14
+ :timezone,
15
+ :channel_id
9
16
 
10
17
  def initialize(client: required('client'))
11
18
  @client = client
@@ -31,9 +38,33 @@ module Urbanairship
31
38
  response
32
39
  end
33
40
 
41
+ def update
42
+ fail ArgumentError, 'sender must be set to update sms channel' if sender.nil?
43
+ fail ArgumentError, 'msisdn must be set to update sms channel' if msisdn.nil?
44
+ fail ArgumentError, 'channel_id must be set to update sms channel' if channel_id.nil?
45
+
46
+ payload = {
47
+ 'msisdn': msisdn,
48
+ 'sender': sender,
49
+ 'opted_in': opted_in,
50
+ 'locale_country': locale_country,
51
+ 'locale_language': locale_language,
52
+ 'timezone': timezone
53
+ }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
54
+
55
+ response = @client.send_request(
56
+ method: 'PUT',
57
+ body: JSON.dump(payload),
58
+ url: CHANNEL_URL + 'sms/' + channel_id,
59
+ content_type: 'application/json'
60
+ )
61
+ logger.info("Updating SMS channel with msisdn #{@channel_id}")
62
+ response
63
+ end
64
+
34
65
  def opt_out
35
- fail ArgumentError, 'sender must be set to register sms channel' if sender.nil?
36
- fail ArgumentError, 'msisdn must be set to register sms channel' if msisdn.nil?
66
+ fail ArgumentError, 'sender must be set to opt out sms channel' if sender.nil?
67
+ fail ArgumentError, 'msisdn must be set to opt out sms channel' if msisdn.nil?
37
68
 
38
69
  payload = {
39
70
  'msisdn': msisdn,
@@ -51,8 +82,8 @@ module Urbanairship
51
82
  end
52
83
 
53
84
  def uninstall
54
- fail ArgumentError, 'sender must be set to register sms channel' if sender.nil?
55
- fail ArgumentError, 'msisdn must be set to register sms channel' if msisdn.nil?
85
+ fail ArgumentError, 'sender must be set to uninstall sms channel' if sender.nil?
86
+ fail ArgumentError, 'msisdn must be set to uninstall sms channel' if msisdn.nil?
56
87
 
57
88
  payload = {
58
89
  'msisdn': msisdn,
@@ -13,11 +13,11 @@ module Urbanairship
13
13
  @client = client
14
14
  end
15
15
 
16
- def create(description: nil, extras: nil)
16
+ def create(description: nil, extra: nil)
17
17
  fail ArgumentError, 'Name must be set' if name.nil?
18
18
  payload = {'name': name}
19
19
  payload['description'] = description unless description.nil?
20
- payload['extras'] = extras unless extras.nil?
20
+ payload['extra'] = extra unless extra.nil?
21
21
 
22
22
  response = @client.send_request(
23
23
  method: 'POST',
@@ -51,13 +51,13 @@ module Urbanairship
51
51
  response
52
52
  end
53
53
 
54
- def update(description: nil, extras: nil)
54
+ def update(description: nil, extra: nil)
55
55
  fail ArgumentError, 'Name must be set' if name.nil?
56
56
  fail ArgumentError,
57
- 'Either description or extras must be set to a value' if description.nil? and extras.nil?
57
+ 'Either description or extras must be set to a value' if description.nil? and extra.nil?
58
58
  payload = {}
59
59
  payload['description'] = description unless description.nil?
60
- payload['extras'] = extras unless extras.nil?
60
+ payload['extra'] = extra unless extra.nil?
61
61
  response = @client.send_request(
62
62
  method: 'PUT',
63
63
  body: JSON.dump(payload),
@@ -1,3 +1,3 @@
1
1
  module Urbanairship
2
- VERSION = '5.8.0'
2
+ VERSION = '5.9.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: urbanairship
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.8.0
4
+ version: 5.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airship
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2020-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client