urbanairship 8.0.1 → 9.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1da985a2097fce219436538dbaa215aae47b9649ae658dd5ae16af3c3675bd8
4
- data.tar.gz: ecf18938527e132580ed887081a89db81aab4665286431b06d268c3a2a6b7505
3
+ metadata.gz: 5417adc316435f2d47f4962983571399b1bf4dea0015cd126ea12077260e50eb
4
+ data.tar.gz: ccbaafa7f7f6bb5820c3a9e1834c23b5a8972debc6b964a204a73cb7630dc2b8
5
5
  SHA512:
6
- metadata.gz: a3f2dad9fb10c281a0e10c1eacddb2fd26f0ec76af4c1a6a4fe0da3ddf83648f29e6762b0cbd756d81a2fadf2a0499fb8ead0c2a873d199ec2df05f16449edea
7
- data.tar.gz: 4ec1e9d2b3f145446e6a6f5bbbb1d13bc79676186335aad7e5b36779f76a34ee41fff2e48cb15eac6dbf89013a27d71ad66742534999dba654f8c656811bcc05
6
+ metadata.gz: 36063a93db8505fa64180ef1980068112d3e14b6b0330e97fa772bd7081c25ab0500aaa7db442ba086a7b12ae8e2c588bbdce7f34144998287a242e401c49c6c
7
+ data.tar.gz: d0cccf9b2713aa344d268c8a997a549525166f88e98e78d63b2a16a12e4123ce999e9be430c0c63a167cf5ff09505cc846755fc02ec822504b898146389aa799
@@ -0,0 +1,31 @@
1
+ name: Ruby Release
2
+
3
+ on:
4
+ release:
5
+ types: [released]
6
+
7
+ jobs:
8
+ test:
9
+
10
+ runs-on: ubuntu-latest
11
+
12
+ strategy:
13
+ matrix:
14
+ ruby-version: [2.7.3, 2.6.7]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby ${{ matrix.ruby-version }}
19
+ uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
20
+ with:
21
+ ruby-version: ${{ matrix.ruby-version }}
22
+ - name: Install dependencies
23
+ run: bundle install
24
+ - name: Run tests
25
+ run: bundle exec rake
26
+ - name: Publish to RubyGems
27
+ uses: cadwallion/publish-rubygems-action@master
28
+ env:
29
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
30
+ GUTHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
31
+ RELEASE_COMMAND: rake release
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 9.0.0
2
+ --------------------
3
+ - Adds Tag List API Support
4
+ - Removes location lookup endpoints
5
+ - Removes location-based audience selectors
1
6
  --------------------
2
7
  8.0.1
3
8
  --------------------
data/README.rst CHANGED
@@ -119,7 +119,7 @@ Broadcast to All Devices
119
119
  p = airship.create_push
120
120
  p.audience = UA.all
121
121
  p.notification = UA.notification(alert: 'Hello')
122
- p.device_types = UA.all
122
+ p.device_types = UA.device_types(['ios','android'])
123
123
  p.send_push
124
124
 
125
125
  Simple Tag Push
@@ -135,7 +135,7 @@ Simple Tag Push
135
135
  p = airship.create_push
136
136
  p.audience = UA.tag('some_tag')
137
137
  p.notification = UA.notification(alert: 'Hello')
138
- p.device_types = UA.all
138
+ p.device_types = UA.device_types(['ios','android'])
139
139
  p.send_push
140
140
 
141
141
  Specify the Airship server used to make your requests
data/docs/examples.rst CHANGED
@@ -18,7 +18,7 @@ Simple broadcast to all devices
18
18
  push = airship.create_push
19
19
  push.audience = UA.all
20
20
  push.notification = UA.notification(alert: "Hello, world!")
21
- push.device_types = UA.all
21
+ push.device_types = UA.device_types(['ios','android'])
22
22
  push.send_push
23
23
 
24
24
 
@@ -92,7 +92,7 @@ Rich Push with extra and without notification
92
92
 
93
93
  push = airship.create_push
94
94
  push.audience = UA.all
95
- push.device_types = UA.all
95
+ push.device_types = UA.device_types(['ios','android'])
96
96
  push.message = UA.message(
97
97
  title: "Your package is on its way!",
98
98
  body: "<h1>Would you please complete our customer survey?</h1>",
data/docs/index.rst CHANGED
@@ -27,7 +27,7 @@ Using the library
27
27
 
28
28
  The library is intended to be used with the small footprint of a single
29
29
  import. To get started, import the package, and create an
30
- :rb:class:`Airship` object representing a single UA application.
30
+ :rb:class:`Airship` object representing a single Airship project.
31
31
 
32
32
  Note that channels are preferred over ``device_token`` and ``apid``. See:
33
33
  `documentation on channels <channels>`_.
@@ -40,7 +40,7 @@ Note that channels are preferred over ``device_token`` and ``apid``. See:
40
40
  p = airship.create_push
41
41
  p.audience = UA.all
42
42
  p.notification = UA.notification(alert: 'Hello')
43
- p.device_types = UA.all
43
+ p.device_types = UA.device_types(['ios','android'])
44
44
  p.send_push
45
45
 
46
46
  The library uses `unirest`_ for communication with the UA API.
@@ -66,7 +66,7 @@ Contents:
66
66
  named_user.rst
67
67
  reports.rst
68
68
  static_lists.rst
69
- location.rst
69
+ tag_lists.rst
70
70
  exceptions.rst
71
71
  examples.rst
72
72
  create_and_send.rst
data/docs/push.rst CHANGED
@@ -22,7 +22,7 @@ and device types:
22
22
  push = airship.create_push
23
23
  push.audience = UA.all
24
24
  push.notification = UA.notification(alert: 'Hello')
25
- push.device_types = UA.all
25
+ push.device_types = UA.device_types(['ios','android'])
26
26
  push.send_push
27
27
 
28
28
 
@@ -443,12 +443,6 @@ types you wish to target with a list of strings:
443
443
 
444
444
  push.device_types = UA.device_types(['ios', 'android', 'web', 'open::example'])
445
445
 
446
- or with the ``all`` shortcut.
447
-
448
- .. code-block:: ruby
449
-
450
- push.device_types = UA.all
451
-
452
446
 
453
447
  Delivery
454
448
  --------
@@ -0,0 +1,76 @@
1
+ Tag Lists
2
+ =========
3
+
4
+ Bulk add and/or remove tags by uploading a CSV file of Airship users. For more
5
+ information about the use of this endpoint, incluiding CSV file formatting requirements
6
+ please see `the Airship Tag Lists API documentation
7
+ <https://docs.airship.com/api/ua/#tag-tag-lists>`__
8
+
9
+
10
+ Create List
11
+ -----------
12
+
13
+ Add tags to your contacts by creating a list and uploading CSV file with user identifiers.
14
+ The body of the request contains the name, description, and optional metadata for the
15
+ list. After you define a list, you populate it with a call to the Upload Tag List method.
16
+
17
+ .. code-block:: ruby
18
+
19
+ require 'urbanairship'
20
+ UA = Urbanairship
21
+ airship = UA::Client.new(key: 'app_key', secret: 'master_secret')
22
+ tags = {'tag_group_name': ['tag1', 'tag2']}
23
+
24
+ tag_list = UA::TagList.new(client: airship)
25
+ tag_list.name = 'ua_tags_list_name'
26
+ tag_list.create(description: 'description', extra: {'key': 'value'}, add: tags)
27
+
28
+
29
+ Upload List
30
+ -----------
31
+
32
+ Upload a CSV that will set tag values on the specified channels or named users. See `the
33
+ Airship API documentation <https://docs.airship.com/api/ua/#operation-api-tag-lists-list_name-csv-put>`__ for CSV formatting requirements. Set
34
+ the optional `gzip` parameter to `true` if your file is gzip compressed.
35
+
36
+ .. code-block:: ruby
37
+
38
+ require 'urbanairship'
39
+ UA = Urbanairship
40
+ airship = UA::Client.new(key: 'app_key', secret: 'master_secret')
41
+
42
+ tag_list = UA::TagList.new(client: airship)
43
+ tag_list.name = 'ua_tags_list_name'
44
+ tag_list.upload(csv_file: 'file_content', gzip: true)
45
+
46
+
47
+ Dowload List Errors
48
+ -------------------
49
+
50
+ During processing, after a list is uploaded, errors can occur. Depending on the type
51
+ of list processing, an error file may be created, showing a user exactly what went wrong.
52
+
53
+ .. code-block:: ruby
54
+
55
+ require 'urbanairship'
56
+ UA = Urbanairship
57
+ airship = UA::Client.new(key: 'app_key', secret: 'master_secret')
58
+
59
+ tag_list = UA::TagList.new(client: airship)
60
+ error_csv = tag_list.errors
61
+
62
+
63
+ Retrieve All Tag Lists
64
+ ----------------------
65
+
66
+ Retrieve information about all tag lists. This call returns a list of metadata that
67
+ will not contain the actual lists of users.
68
+
69
+ .. code-block:: ruby
70
+
71
+ require 'urbanairship'
72
+ UA = Urbanairship
73
+ airship = UA::Client.new(key: 'app_key', secret: 'master_secret')
74
+
75
+ tag_list = UA::TagList.new(client: airship)
76
+ list_response = tag_list.list
data/example/pusher.rb CHANGED
@@ -3,19 +3,15 @@ class Pusher
3
3
  require 'urbanairship'
4
4
  UA = Urbanairship
5
5
 
6
- def send_message
6
+ def send_broadcast_message
7
7
  airship = UA::Client.new(key:'app_key', secret:'master_secret')
8
8
  p = airship.create_push
9
9
  p.audience = UA.all
10
10
  p.notification = UA.notification(alert: 'Hello')
11
- p.device_types = UA.all
12
- p.in_app = UA.in_app(
13
- alert: 'This is a test message!',
14
- display_type: 'banner'
15
- )
11
+ p.device_types = UA.device_types(['ios','android'])
16
12
  p.send_push
17
13
  end
18
14
 
19
15
  end
20
16
 
21
- Pusher.new.send_message
17
+ Pusher.new.send_broadcast_message
@@ -34,10 +34,6 @@ module Urbanairship
34
34
  "/lists/#{path}"
35
35
  end
36
36
 
37
- def location_path(path='')
38
- "/location/#{path}"
39
- end
40
-
41
37
  def named_users_path(path='')
42
38
  "/named_users/#{path}"
43
39
  end
@@ -66,6 +62,10 @@ module Urbanairship
66
62
  "/segments/#{path}"
67
63
  end
68
64
 
65
+ def tag_lists_path(path='')
66
+ "/tag-lists/#{path}"
67
+ end
68
+
69
69
  # Helper method for required keyword args in Ruby 2.0 that is compatible with 2.1+
70
70
  # @example
71
71
  # def say(greeting: required('greeting'))
@@ -0,0 +1,82 @@
1
+ require 'urbanairship'
2
+ require 'tempfile'
3
+
4
+ module Urbanairship
5
+ module Devices
6
+ class TagList
7
+ include Urbanairship::Common
8
+ include Urbanairship::Loggable
9
+ attr_accessor :name
10
+
11
+ def initialize(client: required('client'))
12
+ fail ArgumentError, 'Client cannot be set to nil' if client.nil?
13
+ @client = client
14
+ end
15
+
16
+ def create(description: nil, extra: nil, add:nil, remove: nil, set: nil)
17
+ fail ArgumentError, 'Name must be set' if name.nil?
18
+ payload = {'name': name}
19
+ payload['description'] = description unless description.nil?
20
+ payload['extra'] = extra unless extra.nil?
21
+ payload['add'] = add unless add.nil?
22
+ payload['remove'] = remove unless remove.nil?
23
+ payload['set'] = set unless set.nil?
24
+
25
+ response = @client.send_request(
26
+ method: 'POST',
27
+ body: JSON.dump(payload),
28
+ path: tag_lists_path,
29
+ content_type: 'application/json'
30
+ )
31
+ logger.info("Created Tag List for #{@name}")
32
+ response
33
+ end
34
+
35
+ def upload(csv_file: required('csv_file'), gzip: false)
36
+ fail ArgumentError, 'Name must be set' if name.nil?
37
+
38
+ if gzip
39
+ response = @client.send_request(
40
+ method: 'PUT',
41
+ body: csv_file,
42
+ path: tag_lists_path(@name + '/csv/'),
43
+ content_type: 'text/csv',
44
+ encoding: gzip
45
+ )
46
+ else
47
+ response = @client.send_request(
48
+ method: 'PUT',
49
+ body: csv_file,
50
+ path: tag_lists_path(@name + '/csv/'),
51
+ content_type: 'text/csv'
52
+ )
53
+ end
54
+
55
+ logger.info("Uploaded a tag list for #{@name}")
56
+ response
57
+ end
58
+
59
+ def errors
60
+ fail ArgumentError, 'Name must be set' if name.nil?
61
+
62
+ response = @client.send_request(
63
+ method: 'GET',
64
+ path: tag_lists_path(@name + '/errors/')
65
+ )
66
+ logger.info("Got error CSV for tag list #{@name}")
67
+ response
68
+ end
69
+
70
+ def list
71
+ fail ArgumentError, 'Name must be set' if name.nil?
72
+
73
+ response = @client.send_request(
74
+ method: 'GET',
75
+ path: tag_lists_path
76
+ )
77
+ logger.info("Got tag lists listing")
78
+ response
79
+ end
80
+ end
81
+ end
82
+ end
@@ -78,67 +78,6 @@ module Urbanairship
78
78
  { not: child }
79
79
  end
80
80
 
81
- # Select a recent date range for a location selector.
82
- # Valid selectors are:
83
- # :minutes :hours :days :weeks :months :years
84
- #
85
- # @example
86
- # recent_date(months: 6) # => { recent: { months: 6 }}
87
- # recent_date(weeks: 3) # => { recent: { weeks: 3 }}
88
- def recent_date(**params)
89
- fail ArgumentError, 'Only one range allowed' if params.size != 1
90
- k, v = params.first
91
- unless DATE_TERMS.include?(k)
92
- fail ArgumentError, "#{k} not in #{DATE_TERMS}"
93
- end
94
- { recent: { k => v } }
95
- end
96
-
97
- # Select an absolute date range for a location selector.
98
- #
99
- # @param resolution [Symbol] Time resolution specifier, one of
100
- # :minutes :hours :days :weeks :months :years
101
- # @param start [String] UTC start time in ISO 8601 format.
102
- # @param the_end [String] UTC end time in ISO 8601 format.
103
- #
104
- # @example
105
- # absolute_date(resolution: :months, start: '2013-01', the_end: '2013-06')
106
- # #=> {months: {end: '2013-06', start: '2013-01'}}
107
- #
108
- # absolute_date(resolution: :minutes, start: '2012-01-01 12:00',
109
- # the_end: '2012-01-01 12:45')
110
- # #=> {minutes: {end: '2012-01-01 12:45', start: '2012-01-01 12:00'}}
111
- def absolute_date(resolution: required('resolution'), start: required('start'), the_end: required('the_end'))
112
- unless DATE_TERMS.include?(resolution)
113
- fail ArgumentError, "#{resolution} not in #{DATE_TERMS}"
114
- end
115
- { resolution => { start: start, end: the_end } }
116
- end
117
-
118
- # Select a location expression.
119
- #
120
- # Location selectors are made up of either an id or an alias and a date
121
- # period specifier. Use a date specification function to generate the time
122
- # period specifier.
123
- #
124
- # @example ID location
125
- # location(id: '4oFkxX7RcUdirjtaenEQIV', date: recent_date(days: 4))
126
- # #=> {location: {date: {recent: {days: 4}},
127
- # id: '4oFkxX7RcUdirjtaenEQIV'}}
128
- #
129
- # @example Alias location
130
- # location(us_zip: '94103', date: absolute_date(
131
- # resolution: 'days', start: '2012-01-01', end: '2012-01-15'))
132
- # #=> {location: {date: {days: {end: '2012-01-15',
133
- # start: '2012-01-01'}}, us_zip: '94103'}}
134
- def location(date: required('date'), **params)
135
- unless params.size == 1
136
- fail ArgumentError, 'One location specifier required'
137
- end
138
- params[:date] = date
139
- { location: params }
140
- end
141
-
142
81
  private
143
82
 
144
83
  # Clean up a UUID for use in the library
@@ -1,3 +1,3 @@
1
1
  module Urbanairship
2
- VERSION = '8.0.1'
2
+ VERSION = '9.0.0'
3
3
  end
data/lib/urbanairship.rb CHANGED
@@ -26,7 +26,7 @@ require 'urbanairship/devices/named_user'
26
26
  require 'urbanairship/devices/open_channel'
27
27
  require 'urbanairship/reports/response_statistics'
28
28
  require 'urbanairship/devices/static_lists'
29
- require 'urbanairship/push/location'
29
+ require 'urbanairship/devices/tag_lists'
30
30
  require 'urbanairship/automations/pipeline'
31
31
  require 'urbanairship/automations/automation'
32
32
  require 'urbanairship/ab_tests/variant'
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: 8.0.1
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airship
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-28 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -141,6 +141,7 @@ files:
141
141
  - ".github/PULL_REQUEST_TEMPLATE.md"
142
142
  - ".github/SUPPORT.md"
143
143
  - ".github/workflows/ci.yaml"
144
+ - ".github/workflows/release.yaml"
144
145
  - ".gitignore"
145
146
  - ".rspec"
146
147
  - CHANGELOG
@@ -163,7 +164,6 @@ files:
163
164
  - docs/examples.rst
164
165
  - docs/exceptions.rst
165
166
  - docs/index.rst
166
- - docs/location.rst
167
167
  - docs/named_user.rst
168
168
  - docs/open_channels.rst
169
169
  - docs/push.rst
@@ -171,6 +171,7 @@ files:
171
171
  - docs/segment.rst
172
172
  - docs/sms.rst
173
173
  - docs/static_lists.rst
174
+ - docs/tag_lists.rst
174
175
  - docs/tags.rst
175
176
  - example/pusher.rb
176
177
  - lib/urbanairship.rb
@@ -199,9 +200,9 @@ files:
199
200
  - lib/urbanairship/devices/sms.rb
200
201
  - lib/urbanairship/devices/sms_notification.rb
201
202
  - lib/urbanairship/devices/static_lists.rb
203
+ - lib/urbanairship/devices/tag_lists.rb
202
204
  - lib/urbanairship/loggable.rb
203
205
  - lib/urbanairship/push/audience.rb
204
- - lib/urbanairship/push/location.rb
205
206
  - lib/urbanairship/push/payload.rb
206
207
  - lib/urbanairship/push/push.rb
207
208
  - lib/urbanairship/push/schedule.rb
@@ -229,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
230
  - !ruby/object:Gem::Version
230
231
  version: '0'
231
232
  requirements: []
232
- rubygems_version: 3.0.3
233
+ rubygems_version: 3.0.3.1
233
234
  signing_key:
234
235
  specification_version: 4
235
236
  summary: Ruby Gem for using the Airship API
data/docs/location.rst DELETED
@@ -1,127 +0,0 @@
1
- Locations
2
- =========
3
-
4
- This class allows you to search for location information in
5
- various ways.
6
-
7
-
8
- Name Lookup
9
- -----------
10
-
11
- Search for a location boundary by name. The search primarily
12
- uses the location names, but you can also filter the results
13
- by boundary type. See `the API documentation on location
14
- <http://docs.airship.com/api/ua.html#location>`_
15
- for more information.
16
-
17
- .. code-block:: ruby
18
-
19
- require 'urbanairship'
20
- UA = Urbanairship
21
- airship = UA::Client.new(key:'application_key', secret:'master_secret')
22
- location = UA::Location.new(client: airship)
23
- location.name_lookup(name: 'name', type: 'type')
24
-
25
- .. note::
26
-
27
- ``name`` is a required parameter, but ``type`` is optional
28
-
29
-
30
- Coordinates Lookup
31
- ------------------
32
-
33
- Search for a location by latitude and longitude coordinates. Type is
34
- an optional parameter. See `the API documentation on coordinates lookup
35
- <http://docs.airship.com/api/ua.html#lat-long-lookup>`_
36
- for more information.
37
-
38
- .. code-block:: ruby
39
-
40
- require 'urbanairship'
41
- UA = Urbanairship
42
- airship = UA::Client.new(key:'application_key', secret:'master_secret')
43
- location = UA::Location.new(client: airship)
44
- location.coordinates_lookup(latitude: 123.45, longitude: 123.45, type: 'type')
45
-
46
- .. note::
47
-
48
- ``longitude`` and ``latitude`` are required parameters that must be numbers.
49
- ``Type`` is an optional parameter.
50
-
51
-
52
- Bounding Box Lookup
53
- -------------------
54
-
55
- Search for location using a bounding box. See `the documentation on
56
- bounding box lookup
57
- <http://docs.airship.com/api/ua.html#bounding-box-lookup>`_
58
- for more information.
59
-
60
- .. code-block:: ruby
61
-
62
- require 'urbanairship'
63
- UA = Urbanairship
64
- airship = UA::Client.new(key:'application_key', secret:'master_secret')
65
- location = UA::Location.new(client: airship)
66
- location.bounding_box_lookup(lat1: 123.45, long1: 123.45,
67
- lat2: 321.45, long2: 321.45, type: 'type')
68
-
69
- .. note::
70
-
71
- ``lat1``, ``long1``, ``lat2``, and ``long2`` and are required parameters that must be numbers.
72
- ``Type`` is an optional parameter.
73
-
74
-
75
- Alias Lookup
76
- ------------
77
-
78
- Search for location by alias. See `the documentation on alias lookup
79
- <http://docs.airship.com/api/ua.html#alias-lookup>`_
80
-
81
- .. code-block:: ruby
82
-
83
- require 'urbanairship'
84
- UA = Urbanairship
85
- airship = UA::Client.new(key:'application_key', secret:'master_secret')
86
- location = UA::Location.new(client: airship)
87
- location.alias_lookup(from_alias: 'us_state=CA')
88
-
89
- .. note::
90
-
91
- ``from_alias`` can either be a single alias or an array of aliases.
92
-
93
-
94
- Polygon Lookup
95
- --------------
96
-
97
- Search for location by polygon id. See `the documentation on polygon
98
- lookup <http://docs.airship.com/api/ua.html#polygon-lookup>`_
99
- for more information.
100
-
101
- .. code-block:: ruby
102
-
103
- require 'urbanairship'
104
- UA = Urbanairship
105
- airship = UA::Client.new(key:'application_key', secret:'master_secret')
106
- location = UA::Location.new(client: airship)
107
- location.polygon_lookup(polygon_id: 'id', zoom: 1)
108
-
109
- .. note::
110
-
111
- ``polygon_id`` needs to be a string. ``Zoom`` is a number ranging from 1-20.
112
-
113
-
114
- Location Date Ranges
115
- --------------------
116
-
117
- Get the possible date ranges that can be used with location endpoints. See `the documentation
118
- on location date ranges <http://docs.airship.com/api/ua.html#location-date-ranges>`__
119
- for more information.
120
-
121
- .. code-block:: ruby
122
-
123
- require 'urbanairship'
124
- UA = Urbanairship
125
- airship = UA::Client.new(key:'application_key', secret:'master_secret')
126
- l = UA::Location.new(client: airship)
127
- l.date_ranges
@@ -1,103 +0,0 @@
1
- require 'urbanairship'
2
-
3
-
4
- module Urbanairship
5
- module Push
6
- class Location
7
- include Urbanairship::Common
8
- include Urbanairship::Loggable
9
-
10
- def initialize(client: required('client'))
11
- @client = client
12
- end
13
-
14
- def name_lookup(name: required('name'), type: nil)
15
- fail ArgumentError, 'name needs to be a string' unless name.is_a? String
16
- fail ArgumentError, 'type needs to be a string' unless type.nil? or type.is_a? String
17
- path = location_path('?q=' + name)
18
- path += '&type=' + type unless type.nil?
19
- resp = @client.send_request(
20
- method: 'GET',
21
- path: path
22
- )
23
- logger.info("Retrieved location information for #{name}")
24
- resp
25
- end
26
-
27
- def coordinates_lookup(latitude: required('latitude'), longitude: required('longitude'), type: nil)
28
- fail ArgumentError,
29
- 'latitude and longitude need to be numbers' unless latitude.is_a? Numeric and longitude.is_a? Numeric
30
- fail ArgumentError, 'type needs to be a string' unless type.nil? or type.is_a? String
31
- path = location_path(latitude.to_s + ',' + longitude.to_s)
32
- path += '?type=' + type unless type.nil?
33
- resp = @client.send_request(
34
- method: 'GET',
35
- path: path
36
- )
37
- logger.info("Retrieved location information for latitude #{latitude} and longitude #{longitude}")
38
- resp
39
- end
40
-
41
- def bounding_box_lookup(lat1: required('lat1'), long1: required('long1'),
42
- lat2: required('lat2'), long2: required('long2'), type: nil)
43
-
44
- fail ArgumentError,
45
- 'lat1, long1, lat2, and long2 need to be numbers' unless lat1.is_a? Numeric and long2.is_a? Numeric\
46
- and lat2.is_a? Numeric and long2.is_a? Numeric
47
- fail ArgumentError, 'type needs to be a string' unless type.nil? or type.is_a? String
48
- path = location_path(lat1.to_s + ',' + long1.to_s + ',' + lat2.to_s + ',' + long2.to_s)
49
- path += '?type=' + type unless type.nil?
50
- resp = @client.send_request(
51
- method: 'GET',
52
- path: path
53
- )
54
- logger.info("Retrieved location information for bounding box with lat1 #{lat1}, long1 #{long1}," +
55
- " lat2 #{lat2}, and long2 #{long2}")
56
- resp
57
- end
58
-
59
- def alias_lookup(from_alias: required('from_alias'))
60
- fail ArgumentError, 'from_alias needs to be a string or an array of strings' unless from_alias.is_a? String or from_alias.is_a? Array
61
- path = location_path('from-alias?')
62
- if from_alias.is_a? Array
63
- from_alias.each do |a|
64
- fail ArgumentError, 'from_alias needs to be a string or an array of strings' unless a.is_a? String
65
- path += a + '&'
66
- end
67
- path = path.chop
68
- else
69
- path += from_alias
70
- end
71
-
72
- resp = @client.send_request(
73
- method: 'GET',
74
- path: path
75
- )
76
- logger.info("Retrieved location info from alias #{from_alias}")
77
- resp
78
- end
79
-
80
- def polygon_lookup(polygon_id: required('polygon_id'), zoom: required('zoom'))
81
- fail ArgumentError, 'polygon_id needs to be a string' unless polygon_id.is_a? String
82
- fail ArgumentError, 'zoom needs to be an integer' unless zoom.is_a? Integer
83
-
84
- path = location_path(polygon_id + '?zoom=' + zoom.to_s)
85
- resp = @client.send_request(
86
- method: 'GET',
87
- path: path
88
- )
89
- logger.info("Retrieved location info for polygon #{polygon_id} and zoom level #{zoom}")
90
- resp
91
- end
92
-
93
- def date_ranges
94
- resp = @client.send_request(
95
- method: 'GET',
96
- path: segments_path('dates/')
97
- )
98
- logger.info('Retrieved location date ranges')
99
- resp
100
- end
101
- end
102
- end
103
- end