pigeon-ruby 0.3.2 → 0.5.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 +5 -5
- data/README.md +2 -2
- data/lib/pigeon-ruby.rb +16 -0
- data/lib/pigeon-ruby/client.rb +77 -5
- data/lib/pigeon-ruby/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7c54fd36687fba90d5ce57d961618842ec73507a81a571ca5c1987818db808b4
|
4
|
+
data.tar.gz: f4ea8442bd730ae786a0e86cf3eadf6b19de822252df67219461d25b46c6f5b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 010c3e1bd632abf9079e4c7895b1640bd8aa32d8893160cc494d6be2612e7286522fd1f7432266d4906f981917dc2e5614e832d136fa253ee78cd7ad231028f1
|
7
|
+
data.tar.gz: f86e175b03dfb914b03bfb17751d2be0dcdebea8632e4720354ad03b2eade7986dfcfce6877f0707f192100e33bc0d71de010ecd7c02902774fdf97a026d9312
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Pigeon SDK for Ruby
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'pigeon'
|
10
|
+
gem 'pigeon-ruby'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -16,7 +16,7 @@ And then execute:
|
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
$ gem install pigeon
|
19
|
+
$ gem install pigeon-ruby
|
20
20
|
|
21
21
|
|
22
22
|
## Usage
|
data/lib/pigeon-ruby.rb
CHANGED
@@ -14,4 +14,20 @@ module Pigeon
|
|
14
14
|
def self.deliver(message_identifier, parcels = nil)
|
15
15
|
@clients[:default].deliver(message_identifier, parcels)
|
16
16
|
end
|
17
|
+
|
18
|
+
def self.track(event, data)
|
19
|
+
@clients[:default].track(event, data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.identify(attrs = {})
|
23
|
+
@clients[:default].identify(attrs)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.add_contact(uid, attrs = {})
|
27
|
+
@clients[:default].add_contact(uid, attrs)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.generate_token(uid)
|
31
|
+
@clients[:default].generate_token(uid)
|
32
|
+
end
|
17
33
|
end
|
data/lib/pigeon-ruby/client.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
require 'base64'
|
1
2
|
require 'httparty'
|
3
|
+
require 'openssl'
|
4
|
+
require 'securerandom'
|
2
5
|
|
3
6
|
module Pigeon
|
4
7
|
class Client
|
@@ -7,15 +10,15 @@ module Pigeon
|
|
7
10
|
def initialize(config)
|
8
11
|
@config = config
|
9
12
|
|
10
|
-
self.class.base_uri(
|
13
|
+
self.class.base_uri(config.base_uri || 'https://api.pigeonapp.io/v1')
|
14
|
+
self.class.headers({
|
15
|
+
'X-Public-Key' => config.public_key,
|
16
|
+
'X-Private-Key' => config.private_key
|
17
|
+
})
|
11
18
|
end
|
12
19
|
|
13
20
|
def deliver(message_identifier, parcels = nil)
|
14
21
|
self.class.post('/deliveries', {
|
15
|
-
headers: {
|
16
|
-
'X-Public-Key' => @config.public_key,
|
17
|
-
'X-Private-Key' => @config.private_key
|
18
|
-
},
|
19
22
|
body: {
|
20
23
|
message_identifier: message_identifier,
|
21
24
|
parcels: process_parcels(parcels)
|
@@ -23,6 +26,35 @@ module Pigeon
|
|
23
26
|
})
|
24
27
|
end
|
25
28
|
|
29
|
+
def track(event, data = {})
|
30
|
+
self.class.post('/event_logs', {
|
31
|
+
body: {
|
32
|
+
event: event,
|
33
|
+
data: data
|
34
|
+
}
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
def identify(attrs = {})
|
39
|
+
self.class.post('/customers', {
|
40
|
+
body: process_identify_attributes(attrs)
|
41
|
+
})
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_contact(customer_id, attrs = {})
|
45
|
+
self.class.post('/contacts', {
|
46
|
+
body: process_contact_attributes(customer_id, attrs)
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
def generate_token(customer_id)
|
51
|
+
cipher = OpenSSL::Cipher::AES256.new :CBC
|
52
|
+
cipher.encrypt
|
53
|
+
cipher.key = OpenSSL::Digest::SHA256.digest @config.private_key
|
54
|
+
encrypted = cipher.update(customer_id.to_s) + cipher.final
|
55
|
+
Base64.urlsafe_encode64(encrypted)
|
56
|
+
end
|
57
|
+
|
26
58
|
private
|
27
59
|
|
28
60
|
def process_parcels(parcels)
|
@@ -44,5 +76,45 @@ module Pigeon
|
|
44
76
|
attachment[:name] ||= File.basename(file, '.*')
|
45
77
|
attachment.delete(:file)
|
46
78
|
end
|
79
|
+
|
80
|
+
def process_identify_attributes(attrs)
|
81
|
+
symbolize_keys! attrs
|
82
|
+
extras = attrs[:extras] || {}
|
83
|
+
|
84
|
+
raise ArgumentError, 'Extras must be a Hash' if !extras.is_a? Hash
|
85
|
+
|
86
|
+
if !attrs[:uid] && !attrs[:anonymous_uid]
|
87
|
+
attrs[:anonymous_uid] = generate_anonymous_uid
|
88
|
+
end
|
89
|
+
|
90
|
+
attrs
|
91
|
+
end
|
92
|
+
|
93
|
+
def process_contact_attributes(uid, attrs)
|
94
|
+
symbolize_keys! attrs
|
95
|
+
|
96
|
+
check_presence!(attrs[:name], 'Name')
|
97
|
+
check_presence!(attrs[:value], 'Value')
|
98
|
+
check_presence!(attrs[:kind], 'Kind')
|
99
|
+
|
100
|
+
attrs[:uid] = uid
|
101
|
+
attrs
|
102
|
+
end
|
103
|
+
|
104
|
+
def generate_anonymous_uid
|
105
|
+
SecureRandom.uuid
|
106
|
+
end
|
107
|
+
|
108
|
+
def symbolize_keys!(hash)
|
109
|
+
new_hash = hash.each_with_object({}) do |(k, v), memo|
|
110
|
+
memo[k.to_sym] = v
|
111
|
+
end
|
112
|
+
|
113
|
+
hash.replace(new_hash)
|
114
|
+
end
|
115
|
+
|
116
|
+
def check_presence!(obj, name = obj)
|
117
|
+
raise ArgumentError, "#{name} cannot be blank." if obj.nil? || (obj.is_a?(String) && obj.empty?)
|
118
|
+
end
|
47
119
|
end
|
48
120
|
end
|
data/lib/pigeon-ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pigeon-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pradeep Kumar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
|
112
|
-
rubygems_version: 2.6.12
|
111
|
+
rubygems_version: 3.0.6
|
113
112
|
signing_key:
|
114
113
|
specification_version: 4
|
115
114
|
summary: Pigeon Ruby Library
|