dirigible 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 04e5bfef8a995e173c23c747ff7a0345a3b4e28a
4
+ data.tar.gz: a2f95a51950025b8141beaf4d635dc596a63d3c7
5
+ SHA512:
6
+ metadata.gz: c3172ce4ddc17ccf705d7d41d256a8a6b4d9abaa89d1f4b5a0bfa44ee61dcc8cee011eff1532baa1b17e1e0d429ef0534b93c8e3fdb41ba016db49651f813d62
7
+ data.tar.gz: c557c64fcfffbe5a2f494047c4241739bede5a73c4448e08abb9fb4c7250b6c34df317608373339e536cb82121beda722c9a7d19b5bc73273aa1cfe7584b7762
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rbenv*
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dirigible.gemspec
4
+ gemspec
5
+
6
+ platforms :rbx do
7
+ gem 'json'
8
+ end
9
+
10
+ group :development do
11
+ gem 'bundler'
12
+ gem 'coveralls', require: false
13
+ gem 'rake'
14
+ gem 'yard'
15
+ end
16
+
17
+ group :test do
18
+ gem 'rspec'
19
+ gem 'simplecov'
20
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Anthony Smith
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Dirigible
2
+
3
+ A Ruby wrapper for the Urban Airship v3 API
4
+
5
+ ## Documentation
6
+
7
+ You can view detailed documentation of this library at http://rdoc.info/github/anthonator/dirigible/master/frames. We try to make sure that our documentation is up-to-date and thorough. However, we do recommend keeping the Urban Airship v3 API documentation handy.
8
+
9
+ If you find any discrepency in our documentation please [file an issue](https://github.com/anthonator/dirigible/issues).
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'dirigible'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install dirigible
24
+
25
+ ## Getting Started
26
+
27
+ Configure dirigible...
28
+
29
+ ```ruby
30
+ Dirigible.configure do |config|
31
+ config.app_key = YOUR_APP_KEY
32
+ config.master_secret = YOUR_MASTER_SECRET
33
+ end
34
+ ```
35
+
36
+ Make an API request...
37
+
38
+ ```ruby
39
+ begin
40
+ response = Dirigible::Push.create({
41
+ audience: { device_token: "998BAD77A8347EFE7920F5367A4811C4385D526AE42C598A629A73B94EEDBAC8" },
42
+ notification: { alert: "Hello!" },
43
+ device_types: "all"
44
+ })
45
+ puts "YAY!" if response[:ok] == true # All JSON responses are converted to hash's
46
+ rescue Dirigible::Error => e
47
+ puts "BUSTED!!!"
48
+ end
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
58
+
59
+ ## Credits
60
+ [![Sticksnleaves](http://sticksnleaves-wordpress.herokuapp.com/wp-content/themes/sticksnleaves/images/snl-logo-116x116.png)](http://www.sticksnleaves.com)
61
+
62
+ Dirigible is maintained and funded by [Sticksnleaves](http://www.sticksnleaves.com)
63
+
64
+ Thanks to all of our [contributors](https://github.com/anthonator/dirigible/graphs/contributors)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task default: :spec
data/dirigible.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dirigible/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dirigible"
8
+ spec.version = Dirigible::VERSION
9
+ spec.authors = ["Anthony Smith"]
10
+ spec.email = ["anthony@sticksnleaves.com"]
11
+ spec.description = %q{An Urban Airship v3 API wrapper written in Ruby}
12
+ spec.summary = %q{Urban Airship REST API client library for Ruby}
13
+ spec.homepage = "https://github.com/anthonator/dirigible"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ # Runtime dependencies
22
+ spec.add_dependency "faraday", "~> 0.8"
23
+ spec.add_dependency "faraday_middleware", "~> 0.9"
24
+ spec.add_dependency "hashie", "~> 2.0"
25
+ spec.add_dependency "multi_json", "~> 1.8"
26
+ end
@@ -0,0 +1,16 @@
1
+ module Dirigible
2
+ # @private
3
+ class API
4
+ attr_accessor *Configuration::VALID_OPTION_KEYS
5
+
6
+ def initialize(options = {})
7
+ options = Dirigible.options.merge(options)
8
+ Configuration::VALID_OPTION_KEYS.each do |key|
9
+ send("#{key}=", options[key])
10
+ end
11
+ end
12
+
13
+ include Connection
14
+ include Request
15
+ end
16
+ end
@@ -0,0 +1,62 @@
1
+ module Dirigible
2
+ module Configuration
3
+ VALID_OPTION_KEYS = [
4
+ :app_key,
5
+ :master_secret,
6
+ :endpoint,
7
+ :http_adapter,
8
+ :proxy,
9
+ :user_agent
10
+ ]
11
+
12
+ # By default, don't set app key.
13
+ DEFAULT_APP_KEY = nil.freeze
14
+
15
+ # By default, don't set the master secret.
16
+ DEFAULT_MASTER_SECRET = nil.freeze
17
+
18
+ # The endpoint that will be used to authorize a user if none is set.
19
+ DEFAULT_ENDPOINT = 'https://go.urbanairship.com/api'.freeze
20
+
21
+ # The Faraday HTTP adapter to be used.
22
+ DEFAULT_HTTP_ADAPTER = Faraday.default_adapter
23
+
24
+ # By default, don't set a proxy server.
25
+ DEFAULT_PROXY = nil.freeze
26
+
27
+ # The user agent that will be sent to the API endpoint if none is set.
28
+ DEFAULT_USER_AGENT = "dirigible gem v#{Dirigible::VERSION}"
29
+
30
+ # @private
31
+ attr_accessor(*VALID_OPTION_KEYS)
32
+
33
+ # When this module is extended, set all configuration options to their
34
+ # default values.
35
+ def self.extended(base)
36
+ base.reset
37
+ end
38
+
39
+ # Convenience method to allow configuration options to be set in a
40
+ # block.
41
+ def configure
42
+ yield self
43
+ end
44
+
45
+ # Create a hash of options and their values.
46
+ def options
47
+ VALID_OPTION_KEYS.inject({}) do |option, key|
48
+ option.merge!(key => send(key))
49
+ end
50
+ end
51
+
52
+ # Reset all configuration options to default.
53
+ def reset
54
+ self.app_key = DEFAULT_APP_KEY
55
+ self.master_secret = DEFAULT_MASTER_SECRET
56
+ self.endpoint = DEFAULT_ENDPOINT
57
+ self.http_adapter = DEFAULT_HTTP_ADAPTER
58
+ self.proxy = DEFAULT_PROXY
59
+ self.user_agent = DEFAULT_USER_AGENT
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,14 @@
1
+ module Dirigible
2
+ # @private
3
+ module Connection
4
+ private
5
+ def connection
6
+ options = { ssl: { verify: true }, proxy: proxy }
7
+ Faraday.new(endpoint, options) do |faraday|
8
+ faraday.request(:json)
9
+ faraday.basic_auth(app_key, master_secret)
10
+ faraday.adapter(http_adapter)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,77 @@
1
+ class Dirigible::DeviceInformation
2
+ # Get information on a particular iOS device token. For
3
+ # information on particular keys, see the device token
4
+ # registration API.
5
+ #
6
+ # @example Example request:
7
+ # Dirigible::DeviceInformation.get_device_token('FE66489F304DC75B8D6E8200DFF8A456E8DAEACEC428B427E9518741C92C6660')
8
+ #
9
+ # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#individual-device-lookup
10
+ def self.get_device_token(id)
11
+ Dirigible.get("/device_tokens/#{id}")
12
+ end
13
+
14
+ # Get information on a particular Android APID.
15
+ #
16
+ # @example Example request:
17
+ # Dirigible::DeviceInformation.get_apid('11111111-1111-1111-1111-111111111111')
18
+ #
19
+ # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#individual-device-lookup
20
+ def self.get_apid(id)
21
+ Dirigible.get("/apids/#{id}")
22
+ end
23
+
24
+ # Get information on a particular BlackBerry PIN.
25
+ #
26
+ # @example Example request:
27
+ # Dirigible::DeviceInformation.get_device_pin('12345678')
28
+ #
29
+ # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#individual-device-lookup
30
+ def self.get_device_pin(id)
31
+ Dirigible.get("/device_pins/#{id}")
32
+ end
33
+
34
+ # Fetch iOS device tokens registered to this application
35
+ # and associated metadata.
36
+ #
37
+ # @example Example request:
38
+ # Dirigible::DeviceInformation.list_device_tokens
39
+ #
40
+ # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing
41
+ def self.list_device_tokens
42
+ Dirigible.get('/device_tokens')
43
+ end
44
+
45
+ # Fetch Android APIDs registered to this application and
46
+ # associated metadata.
47
+ #
48
+ # @example Example request:
49
+ # Dirigible::DeviceInformation.list_apids
50
+ #
51
+ # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing
52
+ def self.list_apids
53
+ Dirigible.get('/apids')
54
+ end
55
+
56
+ # Fetch BlackBerry PINs registered to this application and
57
+ # associated metadata.
58
+ #
59
+ # @example Example request:
60
+ # Dirigible::DeviceInformation.list_device_pins
61
+ #
62
+ # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#device-listing
63
+ def self.list_device_pins
64
+ Dirigible.get('/device_pins')
65
+ end
66
+
67
+ # Fetch device tokens that can't recieve messages because
68
+ # the app has been uninstalled.
69
+ #
70
+ # @example Example request:
71
+ # Dirigible::DeviceInformation.device_token_feedback('2009-06-15')
72
+ #
73
+ # @see http://docs.urbanairship.com/reference/api/v3/device_information.html#feedback
74
+ def self.device_token_feedback(since)
75
+ Dirigible.get("/device_tokens/feedback", { since: since })
76
+ end
77
+ end
@@ -0,0 +1,79 @@
1
+ class Dirigible::DeviceRegistration
2
+ # Register the device token with this application. This
3
+ # will mark the device token as active in our system.
4
+ # Optionally set metadata.
5
+ #
6
+ # @example Example request:
7
+ # Dirigible::DeviceRegistration.register_device_token('FE66489F304DC75B8D6E8200DFF8A456E8DAEACEC428B427E9518741C92C6660')
8
+ #
9
+ # @example Full capability:
10
+ # Dirigible::DeviceRegistration.register_device_token('FE66489F304DC75B8D6E8200DFF8A456E8DAEACEC428B427E9518741C92C6660', {
11
+ # alias: "your_user_id",
12
+ # tags: ["tag1", "tag2"],
13
+ # badge: 2,
14
+ # quiettime: {
15
+ # start: "22:00",
16
+ # end: "8:00"
17
+ # },
18
+ # tz: "America/Los_Angeles"
19
+ # })
20
+ #
21
+ # @see http://docs.urbanairship.com/reference/api/v3/registration.html#device-token-registration
22
+ def self.register_device_token(id, options = {})
23
+ Dirigible.put("/device_tokens/#{id}", options)
24
+ end
25
+
26
+ # Deactivate the device token and clear metadata. Pushes
27
+ # will not be sent to inactive device tokens. A future
28
+ # registration will reactivate the device token.
29
+ #
30
+ # @example Example request:
31
+ # Dirigible::DeviceRegistration.delete_device_token('FE66489F304DC75B8D6E8200DFF8A456E8DAEACEC428B427E9518741C92C6660')
32
+ #
33
+ # @see http://docs.urbanairship.com/reference/api/v3/registration.html#device-token-registration
34
+ def self.delete_device_token(id)
35
+ Dirigible.delete("/device_tokens/#{id}")
36
+ end
37
+
38
+ # Register the APID and options with Urban Airship.
39
+ #
40
+ # @example Example request:
41
+ # Dirigible::DeviceRegistration.register_apid('11111111-1111-1111-1111-111111111111', {
42
+ # alias: "example_alias",
43
+ # tags: ["tag1", "tag2"]
44
+ # })
45
+ #
46
+ # @see http://docs.urbanairship.com/reference/api/v3/registration.html#apid-registration
47
+ def self.register_apid(id, params)
48
+ Dirigible.put("/apids/#{id}", params)
49
+ end
50
+
51
+ # Register this PIN with this application. This will mark
52
+ # the PIN as active in our system. Optionally set metadata.
53
+ #
54
+ # @example Example request:
55
+ # Dirigible::DeviceRegistration.register_device_pin('12345678')
56
+ #
57
+ # @example Full capability:
58
+ # Dirigible::DeviceRegistration.register_device_pin('12345678', {
59
+ # alias: "your_user_id",
60
+ # tags: ["tag1", "tag2"]
61
+ # })
62
+ #
63
+ # @see http://docs.urbanairship.com/reference/api/v3/registration.html#blackberry-pin-registration
64
+ def self.register_device_pin(id, options = {})
65
+ Dirigible.put("/device_pins/#{id}", options)
66
+ end
67
+
68
+ # Deactivate the PIN and clear metadata. Pushes will not
69
+ # be sent to inactive PINs. A future registration will
70
+ # reactivate the PIN.
71
+ #
72
+ # @example Example request:
73
+ # Dirigible::DeviceRegistration.delete_device_pin('12345678')
74
+ #
75
+ # @see http://docs.urbanairship.com/reference/api/v3/registration.html#blackberry-pin-registration
76
+ def self.delete_device_pin(id)
77
+ Dirigible.delete("/device_pins/#{id}")
78
+ end
79
+ end
@@ -0,0 +1,19 @@
1
+ module Dirigible
2
+ # Custom error class for rescuing from all known Urban Airship errors
3
+ class Error < StandardError; attr_accessor :error end
4
+
5
+ # Raised when Urban Airship returns HTTP status code 400
6
+ class BadRequest < Error; end
7
+
8
+ # Raised when Urban Airship returns HTTP status code 401
9
+ class Unauthorized < Error; end
10
+
11
+ # Raised when Urban Airship returns HTTP status code 404
12
+ class NotFound < Error; end
13
+
14
+ # Raised when Urban Airship returns HTTP status code 405
15
+ class MethodNotAllowed < Error; end
16
+
17
+ # Raised when Urban Airship returns HTTP status code 406
18
+ class NotAcceptable < Error; end
19
+ end
@@ -0,0 +1,61 @@
1
+ # @note The Feed API still uses the version 1 Push API. In the future it will be upgraded to use the V3 push API.
2
+ # @see http://docs.urbanairship.com/reference/api/v3/feeds.html
3
+ class Dirigible::Feed
4
+ # Creates a new feed.
5
+ #
6
+ # @example Example request:
7
+ # Dirigible::Feed.create({
8
+ # feed_url: "http://example.com/atom.xml",
9
+ # template: {
10
+ # aps: {
11
+ # badge: 1,
12
+ # sound: "cat.caf",
13
+ # alert: "New item from some place! {{ title }}"
14
+ # }
15
+ # }
16
+ # })
17
+ #
18
+ # @see http://docs.urbanairship.com/reference/api/v3/feeds.html#creating-a-new-feed
19
+ def self.create(params)
20
+ Dirigible.post('/feeds', params)
21
+ end
22
+
23
+ # Returns information about that particular feed.
24
+ #
25
+ # @example Example request:
26
+ # Dirigible::Feed.get('<feed_id>')
27
+ #
28
+ # @see http://docs.urbanairship.com/reference/api/v3/feeds.html#feed-details
29
+ def self.get(id)
30
+ Dirigible.get("/feeds/#{id}")
31
+ end
32
+
33
+ # Updates a feed with a new template
34
+ #
35
+ # @example Example request:
36
+ # Dirigible::Feed.update('<feed_id>', {
37
+ # template: {
38
+ # aps: {
39
+ # sound: "frog.caf",
40
+ # alert: "New update from Someplace! - {{ title }}"
41
+ # }
42
+ # },
43
+ # feed_url: "<new_feed_url>"
44
+ # })
45
+ #
46
+ # @see http://docs.urbanairship.com/reference/api/v3/feeds.html#updating-a-feed
47
+ def self.update(id, params)
48
+ Dirigible.put("/feeds/#{id}", params)
49
+ end
50
+
51
+ # Removes a feed from the monitoring service, and stops new
52
+ # pushes from being sent.
53
+ #
54
+ # @example Example request:
55
+ # Dirigible::Feed.delete('<feed_id>')
56
+ #
57
+ # @see http://docs.urbanairship.com/reference/api/v3/feeds.html#deleting-a-feed
58
+ def self.delete(id)
59
+ Dirigible.delete("/feeds/#{id}")
60
+ end
61
+ end
@@ -0,0 +1,65 @@
1
+ # @see http://docs.urbanairship.com/reference/api/v3/location.html
2
+ class Dirigible::Location
3
+ # Search for a location boundary by name.
4
+ #
5
+ # @param query [String] Text search query.
6
+ # @param boundary_type [String] Optional location type, e.g. city, province, or country.
7
+ #
8
+ # @example Example request:
9
+ # Dirigible::Location.search_by_name("Indianapolis", "city")
10
+ #
11
+ # @see http://docs.urbanairship.com/reference/api/v3/location.html#location-boundary-information
12
+ def self.search_by_name(query, boundary_type = nil)
13
+ Dirigible.get('/location', { q: query, type: boundary_type })
14
+ end
15
+
16
+ # Search for a location by latitude and longitude.
17
+ #
18
+ # @param lat [Decimal] Latitude coordinate.
19
+ # @param lng [Decimal] Longitude coordinate.
20
+ # @param boundary_type [String] Optional location type, e.g. city, province, or country.
21
+ #
22
+ # @example Example request:
23
+ # Dirigible::Location.search_by_latlng("37.7749295", "-122.4194155", "city")
24
+ #
25
+ # http://docs.urbanairship.com/reference/api/v3/location.html#location-boundary-information
26
+ def self.search_by_latlng(lat, lng, boundary_type = nil)
27
+ Dirigible.get("/location/#{lat},#{lng}", { type: boundary_type })
28
+ end
29
+
30
+ # Search for locations using a bounding box. A bounding box
31
+ # is a rectangle that covers part of the earth.
32
+ #
33
+ # @param bounding_box [Decimal Array] Multi-dimentional array of latitude and longitude pairs.
34
+ # @param boundary_type [String] Optional location type, e.g. city, province, or country.
35
+ #
36
+ # @example Example request:
37
+ # Dirigible::Location.search_by_bounding_box([["37.805172690644405", "-122.44863510131836"], ["37.77654930110633", "-122.39404678344727"]], "postalcode")
38
+ #
39
+ # @see http://docs.urbanairship.com/reference/api/v3/location.html#location-boundary-information
40
+ def self.search_by_bounding_box(bounding_box, boundary_type = nil)
41
+ Dirigible.get("/location/#{bounding_box.join(',')}", { type: boundary_type })
42
+ end
43
+
44
+ # Look up location boundary information based on
45
+ # real-world references. Multiple queries may be passed
46
+ # in one API call.
47
+ #
48
+ # @example Example request:
49
+ # Dirigible::Location.from_alias({ us_state: "IN" })
50
+ #
51
+ # @see http://docs.urbanairship.com/reference/api/v3/location.html#location-boundary-information
52
+ def self.from_alias(query)
53
+ Dirigible.get("/location/from-alias", query)
54
+ end
55
+
56
+ # Retrieve cutoff dates for each time granularity.
57
+ #
58
+ # @example Example request:
59
+ # Dirigible::Location.cutoff_dates
60
+ #
61
+ # @see http://docs.urbanairship.com/reference/api/v3/location.html#location-data-ranges
62
+ def self.cutoff_dates
63
+ Dirigible.get("/segments/dates")
64
+ end
65
+ end
@@ -0,0 +1,51 @@
1
+ # @see http://docs.urbanairship.com/reference/api/v3/push.html
2
+ class Dirigible::Push
3
+ # Send a push notification to a specified device or list
4
+ # of devices. Must be one of:
5
+ #
6
+ # * A single [Push Object](http://docs.urbanairship.com/reference/api/v3/push.html#push-object)
7
+ # * An array of one or more [Push Objects](http://docs.urbanairship.com/reference/api/v3/push.html#push-object)
8
+ #
9
+ # @example Example request:
10
+ # Dirigible::Push.create({
11
+ # audience: { device_token: "998BAD77A8347EFE7920F5367A4811C4385D526AE42C598A629A73B94EEDBAC8" },
12
+ # notification: { alert: "Hello"! },
13
+ # device_types: "all"
14
+ # })
15
+ #
16
+ # @see http://docs.urbanairship.com/reference/api/v3/push.html#push
17
+ def self.create(params)
18
+ Dirigible.post('/push', params)
19
+ end
20
+
21
+ # Accept the same range of payloads as /api/push, but parse
22
+ # and validate only, without sending any pushes.
23
+ #
24
+ # @example Missing payload:
25
+ # Dirigible::Push.validate({
26
+ # audience: "all",
27
+ # device_types: ["ios", "android"],
28
+ # notification: {
29
+ # ios: { alert: "Boo" }
30
+ # }
31
+ # })
32
+ #
33
+ # @example Device identifier/restriction mismatch:
34
+ # Dirigible::Push.validate({
35
+ # audience: {
36
+ # or: [
37
+ # device_pin: "1fd34210",
38
+ # device_token: "645A5C6C06AFB2AE095B079135168A04A5F974FBF27163F3EC6FE1F2D5AFE008"
39
+ # ]
40
+ # },
41
+ # device_types: ["blackberry"],
42
+ # notification: {
43
+ # alert: "WAT"
44
+ # }
45
+ # })
46
+ #
47
+ # @see http://docs.urbanairship.com/reference/api/v3/push.html#validate
48
+ def self.validate(params)
49
+ Dirigible.post('/push/validate')
50
+ end
51
+ end
@@ -0,0 +1,38 @@
1
+ module Dirigible
2
+ module Request
3
+ def get(path, options = {}, headers = {})
4
+ request(:get, path, options, headers)
5
+ end
6
+
7
+ def post(path, options = {}, headers = {})
8
+ request(:post, path, options, headers)
9
+ end
10
+
11
+ def put(path, options = {}, headers = {})
12
+ request(:put, path, options, headers)
13
+ end
14
+
15
+ def delete(path, options = {}, headers = {})
16
+ request(:delete, path, options, headers)
17
+ end
18
+
19
+ private
20
+ # Perform an HTTP request.
21
+ def request(method, path, options, headers)
22
+ headers.merge!({
23
+ 'User-Agent' => user_agent,
24
+ 'Accept' => 'application/vnd.urbanairship+json; version=3;',
25
+ })
26
+
27
+ response = connection.send(method) do |request|
28
+ request.url("#{endpoint}#{path}/")
29
+ request.body = options.to_json
30
+ request.headers.merge!(headers)
31
+ end
32
+
33
+ Utils.handle_api_error(response) unless (200..399).include?(response.status)
34
+
35
+ Utils.parse_json(response.body) unless response.body == ''
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,77 @@
1
+ # @see http://docs.urbanairship.com/reference/api/v3/schedule.html
2
+ class Dirigible::Schedule
3
+ # Scheduled notifications are created by POSTing to the
4
+ # schedule URI. The body of the request must be one of:
5
+ #
6
+ # * A single {http://docs.urbanairship.com/reference/api/v3/schedule.html#schedule-object schedule object}.
7
+ # * An array of one or more {http://docs.urbanairship.com/reference/api/v3/schedule.html#schedule-object schedule objects}.
8
+ #
9
+ # @example Example request:
10
+ # Dirigible::Schedule.create({
11
+ # name: "Booyah Sports",
12
+ # schedule: { scheduled_time: "2013-04-01T18:45:00" },
13
+ # push: {
14
+ # audience: { tag: "spoaaaarts" },
15
+ # notification: { alert: "Booyah!" },
16
+ # device_types: "all"
17
+ # }
18
+ # })
19
+ #
20
+ # @see http://docs.urbanairship.com/reference/api/v3/schedule.html#schedule-a-notification
21
+ def self.create(params)
22
+ Dirigible.post('/schedules', params)
23
+ end
24
+
25
+ # List all existing schedules. Returns an array of schedule
26
+ # objects in the "schedules" attribute.
27
+ #
28
+ # @example Example request:
29
+ # Dirigible::Schedule.list
30
+ #
31
+ # @see http://docs.urbanairship.com/reference/api/v3/schedule.html#list-schedules
32
+ def self.list
33
+ Dirigible.get('/schedules')
34
+ end
35
+
36
+ # Fetch the current definition of a single schedule
37
+ # resource. Returns a single schedule object.
38
+ #
39
+ # @example Example request:
40
+ # Dirigible::Schedule.get('5cde3564-ead8-9743-63af-821e12337812')
41
+ #
42
+ # @see http://docs.urbanairship.com/reference/api/v3/schedule.html#list-a-specific-schedule
43
+ def self.get(id)
44
+ Dirigible.get("/schedules/#{id}")
45
+ end
46
+
47
+ # Update the state of a single schedule resource. The body
48
+ # must contain a single schedule object.
49
+ #
50
+ # @example Example request:
51
+ # Dirigible::Schedule.update('5cde3564-ead8-9743-63af-821e12337812', {
52
+ # name: "Booyah Sports",
53
+ # schedule: { scheduled_time: "2013-04-01T18:45:30" },
54
+ # push: {
55
+ # audience: { tag: ["spoaaaarts", "Beyonce", "Nickelback"] },
56
+ # notification: { alert: "Booyah!" },
57
+ # device_types: "all"
58
+ # }
59
+ # })
60
+ #
61
+ # @see http://docs.urbanairship.com/reference/api/v3/schedule.html#update-schedule
62
+ def self.update(id, params)
63
+ Dirigible.put("/schedules/#{id}", params)
64
+ end
65
+
66
+ # Delete a schedule resource, which will result in no more
67
+ # pushes being sent. If the resource is succesfully
68
+ # deleted, the response does not include a body.
69
+ #
70
+ # @example Example request:
71
+ # Dirigible::Schedule.delete('b384ca54-0a1d-9cb3-2dfd-ae5964630e66')
72
+ #
73
+ # @see http://docs.urbanairship.com/reference/api/v3/schedule.html#delete-schedule
74
+ def self.delete(id)
75
+ Dirigible.delete("/schedules/#{id}")
76
+ end
77
+ end
@@ -0,0 +1,68 @@
1
+ # @see http://docs.urbanairship.com/reference/api/v3/segments.html
2
+ class Dirigible::Segment
3
+ # List all of the segments for the application.
4
+ #
5
+ # @example Example request:
6
+ # Dirigible::Segment.list
7
+ #
8
+ # @see http://docs.urbanairship.com/reference/api/v3/segments.html#segments-information
9
+ def self.list
10
+ Dirigible.get('/segments')
11
+ end
12
+
13
+ # Fetch information about a particular segment.
14
+ #
15
+ # @example Example request:
16
+ # Dirigible::Segment.get("0c0d899-a595-4c66-9071-bc59374bbe6b")
17
+ #
18
+ # @see http://docs.urbanairship.com/reference/api/v3/segments.html#segments-information
19
+ def self.get(id)
20
+ Dirigible.get("/segments/#{id}")
21
+ end
22
+
23
+ # Create a new segment.
24
+ #
25
+ # @example Example request:
26
+ # Dirigible::Segment.create({
27
+ # display_name: "News but not sports",
28
+ # criteria: {
29
+ # and: [
30
+ # { tag: "news" },
31
+ # { not: { tag: "sports" } }
32
+ # ]
33
+ # }
34
+ # })
35
+ #
36
+ # @see http://docs.urbanairship.com/reference/api/v3/segments.html#segment-creation
37
+ def self.create(params)
38
+ Dirigible.post('/segments', params)
39
+ end
40
+
41
+ # Change the definition of the segment.
42
+ #
43
+ # @example Example request:
44
+ # Dirigible::Segment.update("00c0d899-a595-4c66-9071-bc59374bbe6b", {
45
+ # display_name: "Entertainment but not sports",
46
+ # criteria: {
47
+ # and: [
48
+ # { tag: "news" },
49
+ # { not: { tag: "entertainment" } }
50
+ # ]
51
+ # }
52
+ # })
53
+ #
54
+ # @see http://docs.urbanairship.com/reference/api/v3/segments.html#segment-creation
55
+ def self.update(id, params)
56
+ Dirigible.put("/segments/#{id}", params)
57
+ end
58
+
59
+ # Remove the segment.
60
+ #
61
+ # @example Example request:
62
+ # Dirigible::Segment.delete("00c0d899-a595-4c66-9071-bc59374bbe6b")
63
+ #
64
+ # @see http://docs.urbanairship.com/reference/api/v3/segments.html#segment-creation
65
+ def self.delete(id)
66
+ Dirigible.delete("/segments/#{id}")
67
+ end
68
+ end
@@ -0,0 +1,112 @@
1
+ # @see http://docs.urbanairship.com/reference/api/v3/tags.html
2
+ class Dirigible::Tag
3
+ # List tags that exist for this application.
4
+ #
5
+ # @example Example request:
6
+ # Dirigible::Tag.list
7
+ #
8
+ # @see http://docs.urbanairship.com/reference/api/v3/tags.html#tag-listing
9
+ def self.list
10
+ Dirigible.get('/tags')
11
+ end
12
+
13
+ # Explicitly create a tag with no devices associated with
14
+ # it.
15
+ #
16
+ # @example Example request:
17
+ # Dirigible::Tag.create("some_new_tag")
18
+ #
19
+ # @note This call is optional; tags are created implicitly when devices are added to them. You might use this to pre-create the list for your Push Composer users, however.
20
+ # @see http://docs.urbanairship.com/reference/api/v3/tags.html#tag-creation
21
+ def self.create(tag)
22
+ Dirigible.put("/tags/#{tag}")
23
+ end
24
+
25
+ # Delete a tag and remove it from all devices.
26
+ #
27
+ # A tag can be fully removed from Urban Airship by issuing
28
+ # a delete. This will remove the master record of the tag,
29
+ # and will remove the tag from all devices.
30
+ #
31
+ # @example Example request:
32
+ # Dirigible::Tag.delete("some_new_tag")
33
+ #
34
+ # @note The removal process can take a long time if many devices use this tag.
35
+ # @see http://docs.urbanairship.com/reference/api/v3/tags.html#deleting-a-tag
36
+ def self.delete(tag)
37
+ Dirigible.delete("/tags/#{tag}")
38
+ end
39
+
40
+ # Add or remove one or more device tokens, APIDs, or PINs
41
+ # to a particular tag.
42
+ #
43
+ # @example Example request:
44
+ # Dirigible::Tag.add_or_remove("some_new_tag", {
45
+ # device_tokens: {
46
+ # add: ["device_token_1_to_add", "device_token_2_to_add"]
47
+ # },
48
+ # apids: {
49
+ # remove: ["apid_1_to_remove"]
50
+ # }
51
+ # })
52
+ #
53
+ # @example Full capability:
54
+ # Dirigible::Tag.add_or_remove("some_new_tag", {
55
+ # device_tokens: {
56
+ # add: ["device_token_1_to_add", "device_token_2_to_add"],
57
+ # remove: ["device_token_to_remove"]
58
+ # },
59
+ # device_pins: {
60
+ # add: ["device_pin_1_to_add", "device_pin_2_to_add"],
61
+ # remove: ["device_pin_to_remove"]
62
+ # },
63
+ # apids: {
64
+ # add: ["apid_1_to_add", "apid_2_to_add"],
65
+ # remove: ["apid_to_remove"]
66
+ # }
67
+ # })
68
+ #
69
+ # @see http://docs.urbanairship.com/reference/api/v3/tags.html#adding-and-removing-devices-from-a-tag
70
+ def self.add_or_remove(tag, params)
71
+ Dirigible.post("/tags/#{tag}", params)
72
+ end
73
+
74
+ # Modify the tags for a number of device tokens or apids.
75
+ #
76
+ # You must include an object containing either a
77
+ # device_token or apid section and also containing a tags
78
+ # section to apply the tags.
79
+ #
80
+ # @example Example request:
81
+ # Dirigible::Tag.batch([
82
+ # {
83
+ # device_token: "device_token_tag_tag_1",
84
+ # tags: [
85
+ # "tag_to_apply_1",
86
+ # "tag_to_apply_2",
87
+ # "tag_to_apply_3"
88
+ # ]
89
+ # },
90
+ # {
91
+ # device_token: "device_token_to_tag_2",
92
+ # tags: [
93
+ # "tag_to_apply_1",
94
+ # "tag_to_apply_4",
95
+ # "tag_to_apply_5"
96
+ # ]
97
+ # },
98
+ # {
99
+ # apid: "apid_to_tag_2",
100
+ # tags: [
101
+ # "tag_to_apply_1",
102
+ # "tag_to_apply_4",
103
+ # "tag_to_apply_5"
104
+ # ]
105
+ # }
106
+ # ])
107
+ #
108
+ # @see http://docs.urbanairship.com/reference/api/v3/tags.html#batch-modification-of-tags
109
+ def self.batch(params)
110
+ Dirigible.post("/tags/batch", params)
111
+ end
112
+ end
@@ -0,0 +1,21 @@
1
+ module Dirigible
2
+ # @private
3
+ module Utils
4
+ def self.handle_api_error(response)
5
+ error = case response.status
6
+ when 400 then BadRequest.new
7
+ when 401 then Unauthorized.new
8
+ when 404 then NotFound.new
9
+ when 405 then MethodNotAllowed.new
10
+ when 406 then NotAcceptable.new
11
+ else Error.new
12
+ end
13
+ error.error = parse_json(response.body)
14
+ raise error
15
+ end
16
+
17
+ def self.parse_json(json)
18
+ MultiJson.load(json, symbolize_keys: true)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Dirigible
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dirigible.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'hashie'
4
+ require 'multi_json'
5
+
6
+ require 'dirigible/version'
7
+ require 'dirigible/error'
8
+ require 'dirigible/utils'
9
+
10
+ require 'dirigible/configuration'
11
+ require 'dirigible/connection'
12
+ require 'dirigible/request'
13
+ require 'dirigible/api'
14
+
15
+ require 'dirigible/push'
16
+ require 'dirigible/schedule'
17
+ require 'dirigible/tag'
18
+ require 'dirigible/feed'
19
+ require 'dirigible/device_information'
20
+ require 'dirigible/device_registration'
21
+ require 'dirigible/segment'
22
+ require 'dirigible/location'
23
+
24
+ module Dirigible
25
+ extend Configuration
26
+
27
+ def self.api(options = {})
28
+ Dirigible::API.new(options)
29
+ end
30
+
31
+ def self.method_missing(method, *args, &block)
32
+ return super unless api.respond_to?(method)
33
+ api.send(method, *args, &block)
34
+ end
35
+
36
+ def self.respond_to?(method)
37
+ api.respond_to?(method) || super
38
+ end
39
+ end
data/spec/.gitkeep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dirigible
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: multi_json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ description: An Urban Airship v3 API wrapper written in Ruby
70
+ email:
71
+ - anthony@sticksnleaves.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - dirigible.gemspec
82
+ - lib/dirigible.rb
83
+ - lib/dirigible/api.rb
84
+ - lib/dirigible/configuration.rb
85
+ - lib/dirigible/connection.rb
86
+ - lib/dirigible/device_information.rb
87
+ - lib/dirigible/device_registration.rb
88
+ - lib/dirigible/error.rb
89
+ - lib/dirigible/feed.rb
90
+ - lib/dirigible/location.rb
91
+ - lib/dirigible/push.rb
92
+ - lib/dirigible/request.rb
93
+ - lib/dirigible/schedule.rb
94
+ - lib/dirigible/segment.rb
95
+ - lib/dirigible/tag.rb
96
+ - lib/dirigible/utils.rb
97
+ - lib/dirigible/version.rb
98
+ - spec/.gitkeep
99
+ homepage: https://github.com/anthonator/dirigible
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.1.0
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Urban Airship REST API client library for Ruby
123
+ test_files:
124
+ - spec/.gitkeep
125
+ has_rdoc: