projector 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Overview.md +5 -5
- data/Rakefile +2 -0
- data/circle.yml +1 -1
- data/lib/projector.rb +1 -0
- data/lib/projector/api_methods.rb +8 -8
- data/lib/projector/client.rb +8 -3
- data/lib/projector/end_user.rb +6 -2
- data/lib/projector/envelope.rb +5 -2
- data/lib/projector/error.rb +40 -33
- data/lib/projector/event.rb +2 -1
- data/lib/projector/transport/http.rb +20 -25
- data/lib/projector/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9985ae1b3561b3b85f5f7f7c403949c60e10736
|
4
|
+
data.tar.gz: c702dfc38afa37a3cdce2e02980b2ca9fe6eff7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75b9287b4b13a0d375ea9859c34f16c45c8be31689509a14ec3807759588cf84d3a48d05c2dafa17ae91671934c7cdaaeb4dd2e251a3678fad7782e95dc7339f
|
7
|
+
data.tar.gz: 954a2044bfdd3579d5fd3260c651f7dd65d8e9733962c76b71b46f50f53ac0817088f91e9c0c7e941ea7eacfb80011c0b48f63cabb6281069946472d3c951d81
|
data/Overview.md
CHANGED
@@ -25,14 +25,14 @@ If an error occurs, an exception will be thrown which the user can catch and ins
|
|
25
25
|
The Projector SDK can encounter two types of errors when communicating with Projector's systems - Internal Server and Client Errors. All errors subclass from {Projector::Error}.
|
26
26
|
|
27
27
|
### Client Errors
|
28
|
-
The Projector SDK has two types of Client Errors - {Projector::Unauthorized} and {Projector::BadRequest}. Making a request with safeguards for both can be done as follows:
|
28
|
+
The Projector SDK has two types of Client Errors - {Projector::Error::Unauthorized} and {Projector::Error::BadRequest}. Making a request with safeguards for both can be done as follows:
|
29
29
|
|
30
30
|
```
|
31
31
|
begin
|
32
32
|
Projector.register_end_user(end_user)
|
33
|
-
rescue Projector::Unauthorized => auth_error
|
33
|
+
rescue Projector::Error::Unauthorized => auth_error
|
34
34
|
puts auth_error.response_body
|
35
|
-
rescue Projector::BadRequest => bad_request_error
|
35
|
+
rescue Projector::Error::BadRequest => bad_request_error
|
36
36
|
puts bad_request_error.response_body
|
37
37
|
else
|
38
38
|
puts 'Unknown error'
|
@@ -45,7 +45,7 @@ These type of errors can happen for a number of reasons; our servers might be at
|
|
45
45
|
```
|
46
46
|
begin
|
47
47
|
Projector.register_end_user(end_user)
|
48
|
-
rescue Projector::InternalServerError => server_error
|
48
|
+
rescue Projector::Error::InternalServerError => server_error
|
49
49
|
if server_error.retry_after
|
50
50
|
sleep server_error.retry_after
|
51
51
|
else
|
@@ -59,7 +59,7 @@ You can retry repeatedly but if the error does not eventually clear up reach out
|
|
59
59
|
```
|
60
60
|
begin
|
61
61
|
Projector.register_end_user(end_user)
|
62
|
-
rescue Projector::InternalServerError => server_error
|
62
|
+
rescue Projector::Error::InternalServerError => server_error
|
63
63
|
# If the error does not recover, notify Projector including the Request Id
|
64
64
|
puts server_error.request_id
|
65
65
|
end
|
data/Rakefile
CHANGED
@@ -23,10 +23,12 @@ desc "Publish SDK docs to GitHub Pages"
|
|
23
23
|
task :publish_docs do
|
24
24
|
system("set -x; bundle exec yardoc") or abort
|
25
25
|
system("set -x; mv -v ./doc /tmp ") or abort
|
26
|
+
system("set -x; mv ./vendor /tmp") or abort # move the vendor directory to tmp for the moment
|
26
27
|
system("set -x; git checkout gh-pages ") or abort
|
27
28
|
system("set -x; cp -r /tmp/doc/* . ") or abort
|
28
29
|
system("set -x; git add . ") or abort
|
29
30
|
system("set -x; git commit --all -m 'Update docs' ") or abort
|
30
31
|
system("set -x; git checkout master ") or abort
|
32
|
+
system("set -x; mv /tmp/vendor .") or abort # move the vendor directory back after we're done
|
31
33
|
system("git push origin gh-pages")
|
32
34
|
end
|
data/circle.yml
CHANGED
data/lib/projector.rb
CHANGED
@@ -14,8 +14,8 @@ module Projector
|
|
14
14
|
# tags: ['likes_dogs']
|
15
15
|
# }
|
16
16
|
# Projector.register_end_user(end_user)
|
17
|
-
# @raise {Projector::Unauthorized}
|
18
|
-
# @raise {Projector::BadRequest}
|
17
|
+
# @raise {Projector::Error::Unauthorized}
|
18
|
+
# @raise {Projector::Error::BadRequest}
|
19
19
|
def register_end_user(end_user)
|
20
20
|
# If a hash is passed, use it to populate a user object
|
21
21
|
if end_user.instance_of?(Hash)
|
@@ -34,8 +34,8 @@ module Projector
|
|
34
34
|
# @param [Array] tags an array of tags to apply to the user
|
35
35
|
# @example Update a user's tags
|
36
36
|
# Projector.set_end_user_tags('51', ['likes_dogs', 'has_dog'])
|
37
|
-
# @raise {Projector::Unauthorized}
|
38
|
-
# @raise {Projector::BadRequest}
|
37
|
+
# @raise {Projector::Error::Unauthorized}
|
38
|
+
# @raise {Projector::Error::BadRequest}
|
39
39
|
# @return [Hash]
|
40
40
|
def set_end_user_tags(id, tags)
|
41
41
|
user = Projector::EndUser.new(id: id, tags: tags)
|
@@ -47,7 +47,7 @@ module Projector
|
|
47
47
|
# @param [Hash] event a hash of the event object
|
48
48
|
# @option event [String] :id (SecureRandom.uuid) the ID the event
|
49
49
|
# @option event [String] :event_key the event key for this type of event
|
50
|
-
# @option event [
|
50
|
+
# @option event [Number] :event_time ((Time.now.to_f * 1000).to_i) the event time in ms from epoch for this event
|
51
51
|
# @option event [Hash] :target the recipient or recipients of the event
|
52
52
|
# @option event [Hash] :event_context data for use in delivery rules and notification alert templates at Projector
|
53
53
|
# @option event [Hash] :payload JSON data properties to be delivered on the event (deep links, metadata, etc)
|
@@ -67,9 +67,9 @@ module Projector
|
|
67
67
|
# target: {tags: ['likes_dogs']}
|
68
68
|
# }
|
69
69
|
# Projector.deliver_event(event)
|
70
|
-
# @raise {Projector::InvalidEvent}
|
71
|
-
# @raise {Projector::Unauthorized}
|
72
|
-
# @raise {Projector::BadRequest}
|
70
|
+
# @raise {Projector::Error::InvalidEvent}
|
71
|
+
# @raise {Projector::Error::Unauthorized}
|
72
|
+
# @raise {Projector::Error::BadRequest}
|
73
73
|
# @return [Hash]
|
74
74
|
def deliver_event(event)
|
75
75
|
# Create an Event instance if the parameter is a Hash.
|
data/lib/projector/client.rb
CHANGED
@@ -15,7 +15,7 @@ module Projector
|
|
15
15
|
# If you wish to manually configure the client, create an initializer and use the {Projector::Client.configure}
|
16
16
|
# block to set properties as needed.
|
17
17
|
#
|
18
|
-
# @example Manually configuring the
|
18
|
+
# @example Manually configuring the Projector Client
|
19
19
|
# require 'projector'
|
20
20
|
# Projector::Client.configure do |client|
|
21
21
|
# client[:host] = 'https://api.projector.com'
|
@@ -25,9 +25,11 @@ module Projector
|
|
25
25
|
include Projector::ApiMethods
|
26
26
|
include Projector::Transport::HTTP
|
27
27
|
|
28
|
-
|
28
|
+
# @return [String] The API token for your application
|
29
|
+
attr_accessor :token
|
29
30
|
|
30
31
|
# The current configuration parameters for all clients
|
32
|
+
# @return [Hash]
|
31
33
|
def self.options
|
32
34
|
@options ||= {
|
33
35
|
host: ENV['PROJECTOR_API_HOST'] || 'https://api.projector.com'
|
@@ -37,6 +39,7 @@ module Projector
|
|
37
39
|
# Replaces the global Projector client options
|
38
40
|
#
|
39
41
|
# @param [Hash] val the parameters to store
|
42
|
+
# @return [Hash]
|
40
43
|
def self.options=(val)
|
41
44
|
@options = val
|
42
45
|
end
|
@@ -44,6 +47,7 @@ module Projector
|
|
44
47
|
# Configure the global Projector client options using a block
|
45
48
|
#
|
46
49
|
# @yield [Hash] a hash of configuration values for the Projector Client
|
50
|
+
# @return [Hash]
|
47
51
|
def self.configure
|
48
52
|
yield options
|
49
53
|
end
|
@@ -51,7 +55,7 @@ module Projector
|
|
51
55
|
# Initialize a new client.
|
52
56
|
#
|
53
57
|
# @param [Hash] options
|
54
|
-
# @option options [String] :
|
58
|
+
# @option options [String] :token The API access token
|
55
59
|
# @option options [String] :host The API host
|
56
60
|
def initialize(options = {})
|
57
61
|
options = self.class.options.merge(options)
|
@@ -61,6 +65,7 @@ module Projector
|
|
61
65
|
end
|
62
66
|
|
63
67
|
# The Projector API Host
|
68
|
+
# @return [String]
|
64
69
|
def host
|
65
70
|
@options[:host]
|
66
71
|
end
|
data/lib/projector/end_user.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
module Projector
|
2
2
|
# Internally represents an End User in your application.
|
3
|
+
# @api private
|
3
4
|
class EndUser
|
4
|
-
|
5
|
+
# @return [String] The user's ID in your application
|
6
|
+
attr_accessor :id
|
7
|
+
# @return [Array] an array of tags to apply to the user
|
8
|
+
attr_accessor :tags
|
5
9
|
|
6
10
|
# @param [Hash] params Properties for a user
|
7
11
|
# @option params [String] :id the id of the user in your application
|
8
12
|
# @option params [Array] :tags an array of tags to apply to the user
|
9
13
|
def initialize(params = {})
|
10
|
-
raise Projector::InvalidEndUser.new("Invalid end user, id missing") if params[:id].nil?
|
14
|
+
raise Projector::Error::InvalidEndUser.new("Invalid end user, id missing") if params[:id].nil?
|
11
15
|
if params.instance_of?(Hash)
|
12
16
|
params.each do |k, v|
|
13
17
|
self.send("#{k}=", v) if self.respond_to?("#{k}=")
|
data/lib/projector/envelope.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Projector
|
2
2
|
# Wraps all requests to the Projector API in an envelope specifying data as an explicit parameter.
|
3
|
+
# @api private
|
3
4
|
class Envelope
|
4
|
-
|
5
|
+
# @return [Hash] data to be delivered to the Projector API
|
6
|
+
attr_accessor :data
|
5
7
|
|
6
8
|
# @param [Object] data the data hash or array containing parameters for the API call
|
7
9
|
def initialize(data)
|
@@ -15,8 +17,9 @@ module Projector
|
|
15
17
|
end
|
16
18
|
|
17
19
|
# Serializes the envelope to the correct Projector-defined envelope hash format
|
20
|
+
# @return [Hash]
|
18
21
|
def to_hash(params = {})
|
19
|
-
raise Projector::InvalidEnvelope unless @data
|
22
|
+
raise Projector::Error::InvalidEnvelope unless @data
|
20
23
|
{
|
21
24
|
data: payload
|
22
25
|
}
|
data/lib/projector/error.rb
CHANGED
@@ -5,53 +5,60 @@ module Projector
|
|
5
5
|
attr_accessor :request
|
6
6
|
# The response object (if present)
|
7
7
|
attr_accessor :response
|
8
|
-
# The http response body, if present
|
8
|
+
# @return [Hash] The http JSON response body, if present
|
9
9
|
attr_accessor :response_body
|
10
|
-
# The Projector API request
|
10
|
+
# @return [String] The Projector API request ID
|
11
11
|
attr_accessor :request_id
|
12
|
-
end
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
# Raised when Projector returns a 400 HTTP status code.
|
14
|
+
class BadRequest < Error; end
|
16
15
|
|
17
|
-
|
18
|
-
|
16
|
+
# Raised when Projector returns a 401 HTTP status code.
|
17
|
+
class Unauthorized < Error; end
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
# Raised when Projector returns a 403 HTTP status code.
|
20
|
+
class Forbidden < Error; end
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
# Raised when Projector returns a 404 HTTP status code.
|
23
|
+
class NotFound < Error; end
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
# Raised when Projector returns a 406 HTTP status code.
|
26
|
+
class NotAcceptable < Error; end
|
28
27
|
|
29
|
-
|
30
|
-
|
28
|
+
# Raised when Projector returns a 422 HTTP status code.
|
29
|
+
class UnprocessableEntity < Error; end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
# Raised when Projector returns a 500 HTTP status code.
|
32
|
+
class InternalServerError < Error;
|
33
|
+
# @return [Number] The time in seconds to wait before retrying this request
|
34
|
+
attr_accessor :retry_after
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
# Raised when Projector returns a 501 HTTP status code.
|
38
|
+
class NotImplemented < Error; end
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
# Raised when Projector returns a 502 HTTP status code.
|
41
|
+
class BadGateway < Error; end
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
# Raised when Projector returns a 503 HTTP status code.
|
44
|
+
class ServiceUnavailable < Error; end
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
# Raised when a unique ID is required but not provided.
|
47
|
+
class UniqueIDRequired < Error; end
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
# Raised when an invalid End User is sumbitted to the Projector API.
|
50
|
+
class InvalidEndUser < Error; end
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
# Raised when an invalid event is submitted to the Projector API.
|
53
|
+
class InvalidEvent < Error; end
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
# Raised when an invalid envelope is submitted to the Projector API.
|
56
|
+
class InvalidEnvelope < Error; end
|
57
|
+
|
58
|
+
# Raised when the HTTP client follows too many HTTP redirects.
|
59
|
+
class TooManyRedirects < Error
|
60
|
+
# @return [Number] The redirect count that caused this error
|
61
|
+
attr_accessor :redirect_count
|
62
|
+
end
|
63
|
+
end
|
57
64
|
end
|
data/lib/projector/event.rb
CHANGED
@@ -2,11 +2,12 @@ module Projector
|
|
2
2
|
require 'securerandom'
|
3
3
|
|
4
4
|
# Internally represents an event being sent to the Projector API.
|
5
|
+
# @api private
|
5
6
|
class Event
|
6
7
|
|
7
8
|
# @param [Hash] params a hash of properties to send with the event
|
8
9
|
# @option params [String] id (SecureRandom.uuid) the unique identifier for this event in your system
|
9
|
-
# @option params [Number] event_time (Time.now) the ms since epoch for this event
|
10
|
+
# @option params [Number] event_time ((Time.now.to_f * 1000).to_i) the ms since epoch for this event
|
10
11
|
# @option params [Hash] event_context data providing context for the event. Used in delivery rules, templates, and more at Projector.
|
11
12
|
# @option params [Hash] target containing either an *end_users* or *tags* key and a corresponding hash of values.
|
12
13
|
def initialize(params)
|
@@ -9,30 +9,30 @@ module Projector
|
|
9
9
|
require 'json'
|
10
10
|
require 'projector/error'
|
11
11
|
|
12
|
-
# Maximum URI redrects to follow before failing.
|
13
|
-
MAX_REDIRECTS = 2
|
14
|
-
|
15
|
-
# Status code to exception map.
|
16
|
-
ERROR_MAP = {
|
17
|
-
400 => Projector::BadRequest,
|
18
|
-
401 => Projector::Unauthorized,
|
19
|
-
403 => Projector::Forbidden,
|
20
|
-
404 => Projector::NotFound,
|
21
|
-
406 => Projector::NotAcceptable,
|
22
|
-
422 => Projector::UnprocessableEntity,
|
23
|
-
500 => Projector::InternalServerError,
|
24
|
-
501 => Projector::InternalServerError,
|
25
|
-
502 => Projector::InternalServerError,
|
26
|
-
503 => Projector::InternalServerError
|
27
|
-
}
|
28
|
-
|
29
12
|
[:get, :post, :put, :delete, :patch].each do |method|
|
30
13
|
define_method method do |*args|
|
31
14
|
json_request(method, *args)
|
32
15
|
end
|
33
16
|
end
|
34
17
|
|
35
|
-
|
18
|
+
private
|
19
|
+
|
20
|
+
# Maximum URI redrects to follow before failing.
|
21
|
+
MAX_REDIRECTS = 2
|
22
|
+
|
23
|
+
# Status code to exception map.
|
24
|
+
ERROR_MAP = {
|
25
|
+
400 => Projector::Error::BadRequest,
|
26
|
+
401 => Projector::Error::Unauthorized,
|
27
|
+
403 => Projector::Error::Forbidden,
|
28
|
+
404 => Projector::Error::NotFound,
|
29
|
+
406 => Projector::Error::NotAcceptable,
|
30
|
+
422 => Projector::Error::UnprocessableEntity,
|
31
|
+
500 => Projector::Error::InternalServerError,
|
32
|
+
501 => Projector::Error::InternalServerError,
|
33
|
+
502 => Projector::Error::InternalServerError,
|
34
|
+
503 => Projector::Error::InternalServerError
|
35
|
+
}
|
36
36
|
|
37
37
|
# Makes an HTTP Request
|
38
38
|
#
|
@@ -76,7 +76,7 @@ module Projector
|
|
76
76
|
|
77
77
|
# Make sure we aren't in a giant redirect loop
|
78
78
|
if redirect_count >= MAX_REDIRECTS
|
79
|
-
err =
|
79
|
+
err = Projector::Error::TooManyRedirects.new
|
80
80
|
err.request = request
|
81
81
|
err.response = response
|
82
82
|
err.redirect_count = redirect_count
|
@@ -238,12 +238,7 @@ module Projector
|
|
238
238
|
end
|
239
239
|
end
|
240
240
|
end
|
241
|
-
|
242
|
-
# Raised when the HTTP client follows too many HTTP redirects
|
243
|
-
class TooManyRedirectsError < Projector::Error
|
244
|
-
# The redirect count that caused this error
|
245
|
-
attr_accessor :redirect_count
|
246
|
-
end
|
241
|
+
private_constant :Response
|
247
242
|
end
|
248
243
|
end
|
249
244
|
end
|
data/lib/projector/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: projector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Projector
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-http-persistent
|
@@ -88,3 +88,4 @@ signing_key:
|
|
88
88
|
specification_version: 4
|
89
89
|
summary: Ruby SDK for interacting with the Projector SDK
|
90
90
|
test_files: []
|
91
|
+
has_rdoc:
|