exact_target_rest 0.2.2 → 0.2.4
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 +4 -4
- data/.gitignore +2 -0
- data/lib/exact_target_rest/authorization.rb +5 -5
- data/lib/exact_target_rest/triggered_send.rb +2 -1
- data/lib/exact_target_rest/version.rb +1 -1
- data/spec/lib/exact_target_rest/authorization_spec.rb +13 -5
- data/spec/lib/exact_target_rest/triggered_send_spec.rb +14 -0
- metadata +2 -3
- data/.ruby-gemset +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1aae8d038af8c94d376bd83c559e0ea98a0a611
|
4
|
+
data.tar.gz: e160cf3bca7bde14c48272865a3daaacc3b05ee8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9943d608b41c9f1a21abb3fce489a37cd9651a4671d2a532d2dd8f0dfdaca27f51653b6579f6694ca8b6ff811e6391a42728908030c0a509b968444fe93840f8
|
7
|
+
data.tar.gz: 89e6c8baae62e3daed7a914d6465de164d91d9f43d8d9dc81da7821cb1dfa3e232fa5274ca7330e66deb591a68ccc3338db5c6205530f2b1cb0ffe323d726de1
|
data/.gitignore
CHANGED
@@ -5,6 +5,7 @@ module ExactTargetRest
|
|
5
5
|
# App Center (https://appcenter-auth.exacttargetapps.com).
|
6
6
|
class Authorization
|
7
7
|
attr_reader :access_token
|
8
|
+
attr_reader :expires_in
|
8
9
|
|
9
10
|
# New authorization (it does not trigger REST yet).
|
10
11
|
#
|
@@ -21,7 +22,6 @@ module ExactTargetRest
|
|
21
22
|
#
|
22
23
|
# @yield [access_token] Block to be executed
|
23
24
|
# @yieldparam access_token [String] Access token used to authorize a request
|
24
|
-
# @yieldparam expires_in [String] Time to token's expire
|
25
25
|
def with_authorization
|
26
26
|
authorize! unless authorized?
|
27
27
|
yield @access_token
|
@@ -35,8 +35,8 @@ module ExactTargetRest
|
|
35
35
|
end
|
36
36
|
if resp.success?
|
37
37
|
@access_token = resp.body['accessToken']
|
38
|
-
@expires_in =
|
39
|
-
|
38
|
+
@expires_in = resp.body['expiresIn']
|
39
|
+
self
|
40
40
|
else
|
41
41
|
fail NotAuthorizedError
|
42
42
|
end
|
@@ -44,13 +44,13 @@ module ExactTargetRest
|
|
44
44
|
|
45
45
|
# Already authorized and NOT expired?
|
46
46
|
def authorized?
|
47
|
-
@access_token && @expires_in > Time.now
|
47
|
+
@access_token && (Time.now + @expires_in) > Time.now
|
48
48
|
end
|
49
49
|
|
50
50
|
protected
|
51
51
|
|
52
52
|
def endpoint
|
53
|
-
|
53
|
+
Faraday.new(url: AUTH_URL) do |f|
|
54
54
|
f.request :json
|
55
55
|
f.response :json, content_type: /\bjson$/
|
56
56
|
f.adapter FARADAY_ADAPTER
|
@@ -59,6 +59,7 @@ module ExactTargetRest
|
|
59
59
|
# TriggeredSend with loaded attributes.
|
60
60
|
def deliver
|
61
61
|
tries ||= 1
|
62
|
+
|
62
63
|
@authorization.with_authorization do |access_token|
|
63
64
|
resp = endpoint.post do |p|
|
64
65
|
p.url(format(TRIGGERED_SEND_PATH, URI.encode(@external_key)))
|
@@ -92,7 +93,7 @@ module ExactTargetRest
|
|
92
93
|
protected
|
93
94
|
|
94
95
|
def endpoint
|
95
|
-
|
96
|
+
Faraday.new(url: TRIGGERED_SEND_URL) do |f|
|
96
97
|
f.request :json
|
97
98
|
f.response :json, content_type: /\bjson$/
|
98
99
|
f.adapter FARADAY_ADAPTER
|
@@ -34,8 +34,8 @@ describe Authorization do
|
|
34
34
|
it "returns a valid authorization" do
|
35
35
|
auth = subject.new(client_id, client_secret).authorize!
|
36
36
|
|
37
|
-
expect(auth
|
38
|
-
expect(auth
|
37
|
+
expect(auth.access_token).to eq access_token
|
38
|
+
expect(auth.expires_in).not_to be_nil
|
39
39
|
end
|
40
40
|
|
41
41
|
it "returns Unauthorized" do
|
@@ -45,12 +45,20 @@ describe Authorization do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
describe '#to_yaml' do
|
49
|
+
it "serializes and deserializes Authorization" do
|
50
|
+
auth = subject.new(client_id, client_secret).authorize!
|
51
|
+
|
52
|
+
expect(YAML::load(auth.to_yaml)).to be_instance_of(ExactTargetRest::Authorization)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
48
56
|
private
|
49
57
|
|
50
58
|
def stub_requests
|
51
|
-
stub_request(:post,
|
59
|
+
stub_request(:post, ExactTargetRest::AUTH_URL).
|
52
60
|
with(
|
53
|
-
:body => "{\"clientId\":\"
|
61
|
+
:body => "{\"clientId\":\"#{client_id}\",\"clientSecret\":\"#{client_secret}\"}",
|
54
62
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}
|
55
63
|
).
|
56
64
|
to_return(
|
@@ -61,7 +69,7 @@ describe Authorization do
|
|
61
69
|
|
62
70
|
stub_request(:any, ExactTargetRest::AUTH_URL).
|
63
71
|
with(
|
64
|
-
:body => "{\"clientId\":\"invalid\",\"clientSecret\":\"
|
72
|
+
:body => "{\"clientId\":\"invalid\",\"clientSecret\":\"#{client_secret}\"}",
|
65
73
|
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}
|
66
74
|
).
|
67
75
|
to_return(
|
@@ -56,6 +56,20 @@ describe TriggeredSend do
|
|
56
56
|
|
57
57
|
end
|
58
58
|
|
59
|
+
describe '#to_yaml' do
|
60
|
+
it "serializes and deserializes TriggeredSend" do
|
61
|
+
authorization = ExactTargetRest::Authorization.new("client_id", "client_secret").authorize!
|
62
|
+
|
63
|
+
ts = ExactTargetRest::TriggeredSend.new(authorization, "external_key").
|
64
|
+
with_options(
|
65
|
+
email_address: "jake@oo.com",
|
66
|
+
subscriber_attributes: { "City" => "São Paulo", "Profile ID" => "42" }
|
67
|
+
)
|
68
|
+
|
69
|
+
expect(YAML::load(ts.to_yaml)).to be_instance_of(ExactTargetRest::TriggeredSend)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
59
73
|
private
|
60
74
|
|
61
75
|
def stub_requests
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exact_target_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronie Uliana
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -131,7 +131,6 @@ extensions: []
|
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
133
|
- ".gitignore"
|
134
|
-
- ".ruby-gemset"
|
135
134
|
- Gemfile
|
136
135
|
- Guardfile
|
137
136
|
- LICENSE.txt
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
exact_target_rest
|