unresponsys 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/unresponsys/client.rb +52 -24
- data/lib/unresponsys/errors.rb +1 -0
- data/lib/unresponsys/event.rb +5 -6
- data/lib/unresponsys/folder.rb +4 -7
- data/lib/unresponsys/list.rb +5 -8
- data/lib/unresponsys/member.rb +5 -6
- data/lib/unresponsys/table.rb +3 -1
- data/lib/unresponsys/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 041bc50501ae1f8deb8f12dd258b0a290a062254
|
4
|
+
data.tar.gz: ce3847787e4907d4051f4af0478a0a886a35a45d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e671a298e294a4a7dc20561f118aa4e9d19b0d6a564308821ddbfc0f765b68073879cc1dc357bc237fda8da999b4715aede22abc20d0c4f15ab68b32f13fe4d7
|
7
|
+
data.tar.gz: e010fe01bc5ca6a505ee958f55e7e960416550d3419f368c2a88f17de3e8d32408d63772e4168631fbe628f5a15b834b55dc5d0f28558fbc10d87ea78529d766
|
data/lib/unresponsys/client.rb
CHANGED
@@ -2,38 +2,65 @@ require 'httparty'
|
|
2
2
|
|
3
3
|
class Unresponsys
|
4
4
|
class Client
|
5
|
-
include HTTParty
|
6
|
-
|
7
5
|
def initialize(options = {})
|
8
|
-
raise Unresponsys::ArgumentError
|
6
|
+
raise Unresponsys::ArgumentError unless options[:username] && options[:password]
|
9
7
|
@username = options[:username]
|
10
|
-
|
11
|
-
raise Unresponsys::ArgumentError, 'Password is required' unless options[:password]
|
12
8
|
@password = options[:password]
|
9
|
+
authenticate
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(path, options = {}, &block)
|
13
|
+
path = "#{@base_uri}#{path}"
|
14
|
+
options = @options.merge(options)
|
15
|
+
response = HTTParty.get(path, options, &block)
|
16
|
+
handle_error(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(path, options = {}, &block)
|
20
|
+
path = "#{@base_uri}#{path}"
|
21
|
+
options = @options.merge(options)
|
22
|
+
response = HTTParty.post(path, options, &block)
|
23
|
+
handle_error(response)
|
24
|
+
end
|
13
25
|
|
14
|
-
|
26
|
+
def delete(path, options = {}, &block)
|
27
|
+
path = "#{@base_uri}#{path}"
|
28
|
+
options = @options.merge(options)
|
29
|
+
response = HTTParty.delete(path, options, &block)
|
30
|
+
handle_error(response)
|
31
|
+
end
|
15
32
|
|
16
|
-
|
33
|
+
def folders
|
34
|
+
@folders ||= Folders.new(self)
|
17
35
|
end
|
18
36
|
|
19
|
-
def
|
20
|
-
|
21
|
-
handle_error(r)
|
37
|
+
def lists
|
38
|
+
@lists ||= Lists.new(self)
|
22
39
|
end
|
23
40
|
|
24
|
-
|
25
|
-
|
26
|
-
|
41
|
+
class Folders
|
42
|
+
def initialize(client)
|
43
|
+
@client = client
|
44
|
+
end
|
45
|
+
|
46
|
+
def find(folder_name)
|
47
|
+
Folder.new(@client, folder_name)
|
48
|
+
end
|
27
49
|
end
|
28
50
|
|
29
|
-
|
30
|
-
|
31
|
-
|
51
|
+
class Lists
|
52
|
+
def initialize(client)
|
53
|
+
@client = client
|
54
|
+
end
|
55
|
+
|
56
|
+
def find(list_name)
|
57
|
+
List.new(@client, list_name)
|
58
|
+
end
|
32
59
|
end
|
33
60
|
|
34
61
|
private
|
35
62
|
|
36
|
-
def
|
63
|
+
def handle_error(response)
|
37
64
|
if response.is_a?(Hash) && response.keys.include?('errorCode')
|
38
65
|
raise Unresponsys::TokenExpired if response['title'].include?('token expired')
|
39
66
|
raise Unresponsys::NotFoundError, response['detail'] if response['title'].include?('not found')
|
@@ -43,13 +70,14 @@ class Unresponsys
|
|
43
70
|
end
|
44
71
|
|
45
72
|
def authenticate
|
46
|
-
|
47
|
-
body
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
73
|
+
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
74
|
+
body = { user_name: @username, password: @password, auth_type: 'password' }
|
75
|
+
response = HTTParty.post('https://login2.responsys.net/rest/api/v1/auth/token', headers: headers, body: body)
|
76
|
+
|
77
|
+
raise Unresponsys::AuthenticationError unless response.success?
|
78
|
+
|
79
|
+
@options = { headers: { 'Authorization' => response['authToken'], 'Content-Type' => 'application/json' } }
|
80
|
+
@base_uri = "#{response['endPoint']}/rest/api/v1"
|
53
81
|
end
|
54
82
|
end
|
55
83
|
end
|
data/lib/unresponsys/errors.rb
CHANGED
data/lib/unresponsys/event.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
class Unresponsys
|
2
2
|
class Event
|
3
|
+
extend Forwardable
|
4
|
+
delegate [:client] => :member
|
5
|
+
attr_reader :member
|
3
6
|
|
4
7
|
def initialize(options = {})
|
5
8
|
@event_name = options[:event]
|
@@ -11,10 +14,7 @@ class Unresponsys
|
|
11
14
|
body = {
|
12
15
|
customEvent: {},
|
13
16
|
recipientData: [{
|
14
|
-
recipient: {
|
15
|
-
listName: { objectName: @member.list },
|
16
|
-
recipientId: @member.riid,
|
17
|
-
}
|
17
|
+
recipient: { listName: { objectName: @member.list.name }, recipientId: @member.riid }
|
18
18
|
}]
|
19
19
|
}
|
20
20
|
|
@@ -26,10 +26,9 @@ class Unresponsys
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
r =
|
29
|
+
r = client.post("/events/#{@event_name}", body: body.to_json)
|
30
30
|
return false if r.first['errorMessage'].present?
|
31
31
|
true
|
32
32
|
end
|
33
|
-
|
34
33
|
end
|
35
34
|
end
|
data/lib/unresponsys/folder.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
class Unresponsys
|
2
2
|
class Folder
|
3
|
-
attr_reader :name
|
3
|
+
attr_reader :client, :name
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(name)
|
10
|
-
@name = name
|
5
|
+
def initialize(client, name)
|
6
|
+
@client = client
|
7
|
+
@name = name
|
11
8
|
end
|
12
9
|
|
13
10
|
def tables
|
data/lib/unresponsys/list.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
class Unresponsys
|
2
2
|
class List
|
3
|
-
attr_reader :name
|
3
|
+
attr_reader :client, :name
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(name)
|
10
|
-
@name = name
|
5
|
+
def initialize(client, name)
|
6
|
+
@client = client
|
7
|
+
@name = name
|
11
8
|
end
|
12
9
|
|
13
10
|
def members
|
@@ -21,7 +18,7 @@ class Unresponsys
|
|
21
18
|
|
22
19
|
def find(email)
|
23
20
|
options = { query: { qa: 'e', id: email.to_responsys, fs: 'all' } }
|
24
|
-
r
|
21
|
+
r = @list.client.get("/lists/#{@list.name}/members", options)
|
25
22
|
|
26
23
|
fields = {}
|
27
24
|
r['recordData']['fieldNames'].each_with_index do |field, index|
|
data/lib/unresponsys/member.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
class Unresponsys
|
2
2
|
class Member
|
3
|
+
extend Forwardable
|
4
|
+
delegate [:client] => :list
|
5
|
+
attr_reader :list
|
3
6
|
|
4
7
|
def initialize(list, fields)
|
5
8
|
@fields = default_fields.merge(fields)
|
@@ -29,10 +32,6 @@ class Unresponsys
|
|
29
32
|
email_address
|
30
33
|
end
|
31
34
|
|
32
|
-
def list
|
33
|
-
@list.name
|
34
|
-
end
|
35
|
-
|
36
35
|
def save
|
37
36
|
record_data = { fieldNames: [], records: [[]], mapTemplateName: nil }
|
38
37
|
@fields.each_pair do |key, val|
|
@@ -47,8 +46,9 @@ class Unresponsys
|
|
47
46
|
end
|
48
47
|
|
49
48
|
options = { body: { recordData: record_data, mergeRule: merge_rule }.to_json }
|
50
|
-
r =
|
49
|
+
r = client.post("/lists/#{@list.name}/members", options)
|
51
50
|
return false if r['recordData']['records'][0][0].include?('MERGEFAILED')
|
51
|
+
|
52
52
|
@changed = ['EMAIL_ADDRESS_']
|
53
53
|
self.instance_variable_set(:@riid, r['recordData']['records'][0][0])
|
54
54
|
true
|
@@ -137,6 +137,5 @@ class Unresponsys
|
|
137
137
|
rejectRecordIfChannelEmpty: nil,
|
138
138
|
}
|
139
139
|
end
|
140
|
-
|
141
140
|
end
|
142
141
|
end
|
data/lib/unresponsys/table.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class Unresponsys
|
2
2
|
class Table
|
3
|
+
extend Forwardable
|
4
|
+
delegate [:client] => :folder
|
3
5
|
attr_reader :folder, :name
|
4
6
|
|
5
7
|
def initialize(folder, table_name)
|
@@ -18,7 +20,7 @@ class Unresponsys
|
|
18
20
|
|
19
21
|
def find(primary_key)
|
20
22
|
options = { query: { qa: 'ID_', id: primary_key.to_responsys, fs: 'all' } }
|
21
|
-
r
|
23
|
+
r = @table.client.get("/folders/#{@table.folder.name}/suppData/#{@table.name}/members", options)
|
22
24
|
|
23
25
|
fields = {}
|
24
26
|
r['recordData']['fieldNames'].each_with_index do |field, index|
|
data/lib/unresponsys/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unresponsys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Kimball
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|